Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-26-2007, 12:43 AM
theHAWKER theHAWKER is offline
**FLIP OUT**
theHAWKER's Avatar
Join Date: Mar 2006
Location: canada, vancouver
Posts: 768
theHAWKER is an unknown quantity at this point
Question Instance?

Someone once tolled me that gScript was like ActionScript,
so is it possible to set instances?

incase u dont know, instances make the "npc" noticealbe by other scripts like:
the character is called "chr_npc"
PHP Code:
function onCreated(){
if (
player.chat == "move it!"){
chr_npc.+= 5;
}

__________________
**FLIP OUT**
Reply With Quote
  #2  
Old 05-26-2007, 12:47 AM
JkWhoSaysNi JkWhoSaysNi is offline
Ruler of the graalaxy
Join Date: Feb 2005
Location: Great Britain
Posts: 488
JkWhoSaysNi is on a distinguished road
Send a message via ICQ to JkWhoSaysNi
use findnpc?

PHP Code:
findnpc("npc-name").+= 5
__________________

Coming soon (Hopefully:P)
Reply With Quote
  #3  
Old 05-26-2007, 12:48 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
I don't know exactly what you mean by instance, but GS2 is object-based and you can access other objects from the current 'this'. Some objects have a global identifier this.name and you can use ObjectName.variable or ObjectName.function if the function is public.

Edit: Find-NPC isn't necessary since the NPC would need a name for you to use findnpc().
__________________
Reply With Quote
  #4  
Old 05-26-2007, 01:00 AM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
"Instance" is just macromedia's way of trying to be unique. The term you are looking for is 'object'. As stated above, you can find the name of any npc by echoing this.name.
(Try echo(this.name)

This will only work on database npcs though but there are other ways to access level npcs such as finding the npc in the "npcs" array-variable.
__________________
Do it with a DON!
Reply With Quote
  #5  
Old 05-26-2007, 01:01 AM
JkWhoSaysNi JkWhoSaysNi is offline
Ruler of the graalaxy
Join Date: Feb 2005
Location: Great Britain
Posts: 488
JkWhoSaysNi is on a distinguished road
Send a message via ICQ to JkWhoSaysNi
You're right.

There is a findareanpcs() function to find npcs in a specific area.

Or, you could make a list in a DB npc

(in the NPC you want to access somewhere else)
dbNPC.foo = this;

then in any other NPC you could use dbNPC.foo.x += 5;
__________________

Coming soon (Hopefully:P)
Reply With Quote
  #6  
Old 05-26-2007, 01:03 AM
theHAWKER theHAWKER is offline
**FLIP OUT**
theHAWKER's Avatar
Join Date: Mar 2006
Location: canada, vancouver
Posts: 768
theHAWKER is an unknown quantity at this point
i dont understand how to use that stuff, could you use it in a script?
say ur trying to make an npc move called "rupert"
__________________
**FLIP OUT**
Reply With Quote
  #7  
Old 05-26-2007, 01:05 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by theHAWKER View Post
i dont understand how to use that stuff, could you use it in a script?
say ur trying to make an npc move called "rupert"
You can't name level-npcs like that, you need some way of finding it.
Edit: Oh my, nevermind, you can set up a global reference to the object.
PHP Code:
//The script of "rupert"
function onCreated() {
  
NPCRupert this;

Then you could reference that object using NPCRupter.variable. Of course there are other things to consider, global vars are cleared on a restart of the environment, for clientside that would be if you restarted Graal or changed server. And for serverside, that would be when the server restarts.

Something I did on Aeon was to add a new global var Control pointing to Control-NPC.

There is an array npcs representing all npcs in the current level.
__________________
Reply With Quote
  #8  
Old 05-26-2007, 01:12 AM
theHAWKER theHAWKER is offline
**FLIP OUT**
theHAWKER's Avatar
Join Date: Mar 2006
Location: canada, vancouver
Posts: 768
theHAWKER is an unknown quantity at this point
Quote:
Originally Posted by Inverness View Post
You can't name level-npcs like that, you need some way of finding it.
Edit: Oh my, nevermind, you can set up a global reference to the object.
PHP Code:
//The script of "rupert"
function onCreated() {
  
NPCRupert this;

Then you could reference that object using NPCRupter.variable. Of course there are other things to consider, global vars are cleared on a restart of the environment, for clientside that would be if you restarted Graal or changed server. And for serverside, that would be when the server restarts.

Something I did on Aeon was to add a new global var Control pointing to Control-NPC.
right, but how would i refer to NPCRupert?
__________________
**FLIP OUT**
Reply With Quote
  #9  
Old 05-26-2007, 04:06 PM
Kristi Kristi is offline
Bowie's Deciple
Kristi's Avatar
Join Date: Dec 2003
Location: Boston, MA
Posts: 748
Kristi has a spectacular aura aboutKristi has a spectacular aura about
Send a message via AIM to Kristi Send a message via MSN to Kristi
Quote:
Originally Posted by theHAWKER View Post
right, but how would i refer to NPCRupert?
Expanding on what inverness said, all you have to do from any other npc is
NPCRupert.chat = "whatever";

or if it was never a showchar

NPCRupert.message("whatever");
__________________
Reply With Quote
  #10  
Old 05-26-2007, 05:50 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
Quote:
Originally Posted by Inverness View Post
Something I did on Aeon was to add a new global var Control pointing to Control-NPC.
NPCs or weapon-NPCs with odd names can be accessed like this:
PHP Code:
("Control-NPC").dosomething(); 
Reply With Quote
  #11  
Old 05-26-2007, 06:37 PM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
Quote:
Originally Posted by Stefan View Post
NPCs or weapon-NPCs with odd names can be accessed like this:
PHP Code:
("Control-NPC").dosomething(); 
You don't need the ()'s either (You can just do "Control-NPC".dosomething(); ) but it is fairly unfashionable to some people to do that.

What Stefan meant by "odd names" would be any object with a math or script character in it (Examples are: +-*/^%!@()[]{}<>'")

Hope that makes sense!
__________________
Do it with a DON!
Reply With Quote
  #12  
Old 05-26-2007, 01:12 AM
JkWhoSaysNi JkWhoSaysNi is offline
Ruler of the graalaxy
Join Date: Feb 2005
Location: Great Britain
Posts: 488
JkWhoSaysNi is on a distinguished road
Send a message via ICQ to JkWhoSaysNi
Creating a variable like that gives it global scope???
__________________

Coming soon (Hopefully:P)
Reply With Quote
  #13  
Old 05-26-2007, 02:13 AM
theHAWKER theHAWKER is offline
**FLIP OUT**
theHAWKER's Avatar
Join Date: Mar 2006
Location: canada, vancouver
Posts: 768
theHAWKER is an unknown quantity at this point
Quote:
Originally Posted by JkWhoSaysNi View Post
Creating a variable like that gives it global scope???
like if i wanted him to talk, for instance
__________________
**FLIP OUT**
Reply With Quote
  #14  
Old 05-26-2007, 03:02 AM
Deadly_Killer Deadly_Killer is offline
Registered User
Join Date: Feb 2002
Posts: 227
Deadly_Killer is on a distinguished road
PHP Code:
function onPlayerTouchsMe()
{
  for (
temp.var : npcs)
  {
    if (
temp.var.nick == "Rupert")
    {
      
temp.var.chat "I'm Rupert!";
      
      break;
    }
  }

__________________
- Zidane / Zidaya
Reply With Quote
  #15  
Old 05-26-2007, 05:02 PM
theHAWKER theHAWKER is offline
**FLIP OUT**
theHAWKER's Avatar
Join Date: Mar 2006
Location: canada, vancouver
Posts: 768
theHAWKER is an unknown quantity at this point
cool, thank you guys
__________________
**FLIP OUT**
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 02:39 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.