Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Instance? (https://forums.graalonline.com/forums/showthread.php?t=74203)

theHAWKER 05-26-2007 12:43 AM

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;
}



JkWhoSaysNi 05-26-2007 12:47 AM

use findnpc?

PHP Code:

findnpc("npc-name").+= 5


Inverness 05-26-2007 12:48 AM

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().

zokemon 05-26-2007 01:00 AM

"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.

JkWhoSaysNi 05-26-2007 01:01 AM

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;

theHAWKER 05-26-2007 01:03 AM

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"

Inverness 05-26-2007 01:05 AM

Quote:

Originally Posted by theHAWKER (Post 1311929)
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.

theHAWKER 05-26-2007 01:12 AM

Quote:

Originally Posted by Inverness (Post 1311930)
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?

JkWhoSaysNi 05-26-2007 01:12 AM

Creating a variable like that gives it global scope???

theHAWKER 05-26-2007 02:13 AM

Quote:

Originally Posted by JkWhoSaysNi (Post 1311933)
Creating a variable like that gives it global scope???

like if i wanted him to talk, for instance

Deadly_Killer 05-26-2007 03:02 AM

PHP Code:

function onPlayerTouchsMe()
{
  for (
temp.var : npcs)
  {
    if (
temp.var.nick == "Rupert")
    {
      
temp.var.chat "I'm Rupert!";
      
      break;
    }
  }



Kristi 05-26-2007 04:06 PM

Quote:

Originally Posted by theHAWKER (Post 1311932)
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");

theHAWKER 05-26-2007 05:02 PM

cool, thank you guys :D

Admins 05-26-2007 05:50 PM

Quote:

Originally Posted by Inverness (Post 1311930)
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(); 


zokemon 05-26-2007 06:37 PM

Quote:

Originally Posted by Stefan (Post 1312128)
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!


All times are GMT +2. The time now is 11:19 PM.

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