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 02-03-2011, 03:39 AM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
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...
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #2  
Old 02-03-2011, 03:47 AM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
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.
Reply With Quote
  #3  
Old 02-03-2011, 03:52 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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);

__________________
Quote:
Reply With Quote
  #4  
Old 02-03-2011, 04:09 AM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
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)
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #5  
Old 02-03-2011, 04:14 AM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
"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.
Reply With Quote
  #6  
Old 02-03-2011, 04:45 AM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
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.
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #7  
Old 02-03-2011, 04:46 AM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
I believe "var" is a protected variable name, try something else.
Reply With Quote
  #8  
Old 02-03-2011, 04:48 AM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
thats just in my example on forums
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #9  
Old 02-03-2011, 04:55 AM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
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();

Reply With Quote
  #10  
Old 02-03-2011, 05:10 AM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
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))
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #11  
Old 02-03-2011, 05:37 AM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
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.
Reply With Quote
  #12  
Old 02-03-2011, 05:44 AM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
lol.. I didn't think I was crazy.. so just clientside the whole script?
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #13  
Old 02-03-2011, 05:47 AM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
This definitely works clientside.
Reply With Quote
  #14  
Old 02-03-2011, 05:56 AM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
Thanks mike, sucked it took like 2hrs to do something so simple lol
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #15  
Old 02-03-2011, 09:28 AM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
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?
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming

Last edited by kingcj; 02-03-2011 at 09:29 AM.. Reason: um prolly use fp4's advice now that I'm looking back over it
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 01:48 PM.


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