Graal Forums

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

kingcj 02-03-2011 03:39 AM

Npc to Npc
 
I've been trying to get an NPC to communicate with another. (such as touching one affects the other) Trigger doesn't seem to work, and I am unable to get callnpc to work either. I don't know if it is the way I am doing it or how it's called...

ffcmike 02-03-2011 03:47 AM

PHP Code:

//Set a reference for the NPC
function onCreated(){
  
this.level.somename this;
}

function 
onPlayerTouchsMe(){
  
//this.level.someothername being the reference for the opposite NPC
  
this.level.someothername.wasTouched();
}

public function 
wasTouched(){
  
//stuff


Just have to make 2 npcs with this script and make sure to set the necessary variable names.

CallNPC is really a relic from pre npcserver/pre GS2 days, may still work Clientside but it's somewhat deprecated.

fowlplay4 02-03-2011 03:52 AM

You can use getareanpcs(float, float, float, float) and loop through and find the NPC by a unique id or joined class even.

Baddies find other baddies, I.e:

PHP Code:

// Loop through NPCs in a 64x64 square around the npc.
for (temp.ngetareanpcs(this.32this.326464)) {
  
// Check if NPC is part of the Baddy class
  
if (temp.n.joinedclasses.index("baddy") >= 0) {
    
// Add NPC to Baddies Array for Further Processing
    
temp.baddies.add(temp.n);
  }
}
for (
temp.baddytemp.baddies) {
  echo(
"Baddy Found: " temp.baddy.nick);


When you have the NPC object, you can simply send triggers or call public functions. I.e:

PHP Code:

// Loop through NPCs in a 64x64 square around the npc.
for (temp.ngetareanpcs(this.32this.326464)) {
  
temp.n.trigger("Found""");


then in the other NPCs:

PHP Code:

function onFound() {
  echo(
"Found: " this.nick);



kingcj 02-03-2011 04:09 AM

I believe ffcmike's explaination is sufficient, however I'm unsure of the this.level.var. Do i insert the level name here or npc? I'm confused as to how to implement in the level... I tried in the script and it comes back as it can't find this.level.someothername.wasTouched (I tried different names in my script, just guess and test with no luck)

ffcmike 02-03-2011 04:14 AM

"this.level" you leave the same, the "somename" part is up to you, you just need to make sure that whatever name is being referred to in one NPC is the specified reference name for the opposite NPC.

kingcj 02-03-2011 04:45 AM

Yes I understand that, but the reference name is confusing? I place the this.level.var which is what the player would touch, then in the other NPC this.level.var is triggered to hide the image? I'm still very confused, please enlighten me.

ffcmike 02-03-2011 04:46 AM

I believe "var" is a protected variable name, try something else.

kingcj 02-03-2011 04:48 AM

thats just in my example on forums

ffcmike 02-03-2011 04:55 AM

Maybe show your current script of the 2 NPCs?

Should be as simple as this:

NPC 1
PHP Code:

function onCreated(){
  
this.level.obj1 this;
}

function 
onPlayerTouchsMe(){
  
this.level.obj2.wasTouched();
}

public function 
wasTouched(){
  
this.hide();


NPC 2
PHP Code:

function onCreated(){
  
this.level.obj2 this;
}

function 
onPlayerTouchsMe(){
  
this.level.obj1.wasTouched();
}

public function 
wasTouched(){
  
this.hide();



kingcj 02-03-2011 05:10 AM

Yea thats how I was doing it, but I get this error and it's the same with mine and yours... : Script: Function obj2.wasTouched not found at line 6 of explodeswitch in script of npcs[0] (in level zie_scripttest.nw at pos (39, 32))

ffcmike 02-03-2011 05:37 AM

Strangest thing actually, I tried it myself and it seemed to be doing nothing at all despite all of my echo's suggesting it was working, I then reconnect to find that the NPC was indeed being hidden just for some reason this was not being sent to the player so it remained visible on my client, this is something Stefan should probably look into.

You can always just to this Clientside if this is a single player thing.

kingcj 02-03-2011 05:44 AM

lol.. I didn't think I was crazy.. so just clientside the whole script?

ffcmike 02-03-2011 05:47 AM

This definitely works clientside.

kingcj 02-03-2011 05:56 AM

Thanks mike, sucked it took like 2hrs to do something so simple lol

kingcj 02-03-2011 09:28 AM

Kinda on the same note I am now trying to lay an npc down and have it affect another npc while it is there. again should i trigger an action? I am unsure of this process, but I am trying to affect the npc clientside. I may have to do it serverside?


All times are GMT +2. The time now is 02:59 AM.

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