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 09-02-2009, 06:02 AM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
How-To: triggerAction() (clientside <--> serverside communication in level NPCs)

Since there has been recent confusion on how to communicate from clientside to serverside and vice versa with regards to level NPCs, I have decided to write my second installment of the "How-To" series on the triggerAction() function. triggerAction() can be used to perform other actions as well but that is not a part of this explanation.

Important Notes

. triggerAction() is used to trigger an action from clientside to serverside or on the clientside and serverside themselves in level NPCs that are located in the x and y coordinates specified in the parameters of the function.
. To send information from the serverside to the clientside, use save[] or attr[]'s.
. triggerAction() MUST take at least 4 parameters, if you don't want to send any extra information, then use empty quotations (i.e "") as the fourth parameter
. Classes work as global level NPCs so you treat triggerAction() in classes the same way.
. You must define a shape for the npc on the serverside if you want to communicate to the serverside, on the clientside if you want to communicate to the clientside, or both if you wish to do both (use setShape() or setShape2()).
. You read the function triggered by the triggerAction() via onActionActionname(), where Actionname is the name you specify in the parameters of the function.
. When reading the x/y coordinates of the npc, use this.x and this.y to avoid problems on gmaps.
. If you stack NPCs on top of each other and trigger to the same coordinates as the stack of NPCs, then the onActionActionname() will be called in each NPC in the specified coordinates.
. The specified action name in the parameters must be written in quotations (which applies to just about all unique text in GS2).

Syntax

PHP Code:
triggerAction(x coordy coord"Actionname"extraparametershere,...); 
Examples

Without sending any extra parameters:

PHP Code:
function onCreated() setShape(13232);

function 
onActionServersideTrigger() {
  echo(
"Success!");
}

//#CLIENTSIDE
function onCreated() {
  
setShape(13232);
  
triggerAction(this.x+1this.y+1"ServersideTrigger""");


Sending extra parameters:

PHP Code:
function onCreated() setShape(13232);

function 
onActionServersideTrigger(bar) {
   echo(
bar "!");
}

//#CLIENTSIDE
function onCreated() {
  
setShape(13232);
  
temp.foo 1
  
triggerAction(this.x+1this.y+1"ServersideTrigger"foo);


Last edited by Darlene159; 09-06-2009 at 02:53 AM..
Reply With Quote
  #2  
Old 09-02-2009, 02:57 PM
Soala Soala is offline
Ideas on Fire
Soala's Avatar
Join Date: Jun 2007
Location: In my head
Posts: 3,208
Soala is a jewel in the roughSoala is a jewel in the rough
*Vote for this How-To to be on the wiki*
Reply With Quote
  #3  
Old 09-02-2009, 03:19 PM
Liberated Liberated is offline
not doing alot
Liberated's Avatar
Join Date: Feb 2008
Posts: 1,366
Liberated has a spectacular aura about
i vote for a yes.
__________________
Quote:
Originally Posted by Tigairius View Post
I promise when I get rich I'll send you an iPhone. I'll send everyone an iPhone.
Reply With Quote
  #4  
Old 09-02-2009, 05:02 PM
Toxen Toxen is offline
A Toxic Fellow
Join Date: Jan 2008
Location: Georgia
Posts: 36
Toxen is on a distinguished road
Gambet I always love to read your "How-To" threads there always so helpful and to the point.
__________________
UN NAT.
Reply With Quote
  #5  
Old 09-02-2009, 06:10 PM
Deas_Voice Deas_Voice is offline
Deas
Deas_Voice's Avatar
Join Date: Jun 2007
Location: Sweden
Posts: 2,264
Deas_Voice is a jewel in the roughDeas_Voice is a jewel in the rough
Send a message via AIM to Deas_Voice Send a message via MSN to Deas_Voice Send a message via Yahoo to Deas_Voice
should be a howto or tutorial subforum or a index sticked.

i maybe wont use it because i rarely use levelnpcs with server/clientside triggers, but nice work anyway!

oh and, i also vote yes on Soalas votecast.
__________________
.
WTF is real life, and where do I Download it?
There is no Real Life, just AFK!
since 2003~
I Support~
ღAeonღ | ღTestbedღ | ღDelteriaღ

if you are going to rep me, don't be an idiot, leave your name!
I got nothing but love for you
Reply With Quote
  #6  
Old 09-02-2009, 06:13 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by Deas_Voice View Post
should be a howto or tutorial subforum or a index sticked.
Wiki.
__________________
Reply With Quote
  #7  
Old 09-02-2009, 06:29 PM
Deas_Voice Deas_Voice is offline
Deas
Deas_Voice's Avatar
Join Date: Jun 2007
Location: Sweden
Posts: 2,264
Deas_Voice is a jewel in the roughDeas_Voice is a jewel in the rough
Send a message via AIM to Deas_Voice Send a message via MSN to Deas_Voice Send a message via Yahoo to Deas_Voice
Quote:
Originally Posted by Crow View Post
Wiki.
or wiki, but since it's already here, why not get a sticked index of howto-s?
__________________
.
WTF is real life, and where do I Download it?
There is no Real Life, just AFK!
since 2003~
I Support~
ღAeonღ | ღTestbedღ | ღDelteriaღ

if you are going to rep me, don't be an idiot, leave your name!
I got nothing but love for you
Reply With Quote
  #8  
Old 09-02-2009, 06:37 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Quote:
Originally Posted by Deas_Voice View Post
or wiki, but since it's already here, why not get a sticked index of howto-s?
Because this is a discussion forum and the "howtos" should be rewritten into reference documentation and put on the wiki
Reply With Quote
  #9  
Old 09-02-2009, 06:42 PM
Deas_Voice Deas_Voice is offline
Deas
Deas_Voice's Avatar
Join Date: Jun 2007
Location: Sweden
Posts: 2,264
Deas_Voice is a jewel in the roughDeas_Voice is a jewel in the rough
Send a message via AIM to Deas_Voice Send a message via MSN to Deas_Voice Send a message via Yahoo to Deas_Voice
jeeze, can't i have my own opinion?..
__________________
.
WTF is real life, and where do I Download it?
There is no Real Life, just AFK!
since 2003~
I Support~
ღAeonღ | ღTestbedღ | ღDelteriaღ

if you are going to rep me, don't be an idiot, leave your name!
I got nothing but love for you
Reply With Quote
  #10  
Old 09-02-2009, 06:49 PM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
Quote:
Originally Posted by Deas_Voice View Post
jeeze, can't i have my own opinion?..
No, since you obviously get offended when people counter your opinion with their own.
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #11  
Old 09-02-2009, 06:51 PM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Feel free to add this to the wiki but I'm not going to go above and beyond with this thing, this is enough for me.
Reply With Quote
  #12  
Old 09-02-2009, 07:02 PM
Deas_Voice Deas_Voice is offline
Deas
Deas_Voice's Avatar
Join Date: Jun 2007
Location: Sweden
Posts: 2,264
Deas_Voice is a jewel in the roughDeas_Voice is a jewel in the rough
Send a message via AIM to Deas_Voice Send a message via MSN to Deas_Voice Send a message via Yahoo to Deas_Voice
Quote:
Originally Posted by xXziroXx View Post
No, since you obviously get offended when people counter your opinion with their own.
wouldn't you?

Edit, let's drop this, no idea to argue.
__________________
.
WTF is real life, and where do I Download it?
There is no Real Life, just AFK!
since 2003~
I Support~
ღAeonღ | ღTestbedღ | ღDelteriaღ

if you are going to rep me, don't be an idiot, leave your name!
I got nothing but love for you
Reply With Quote
  #13  
Old 09-05-2009, 08:25 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Quote:
Originally Posted by Gambet View Post
. triggerAction() is used to trigger an action on the serverside if used on the clientside, and on the clientside if used on the serverside in level NPCs that are located in the x and y coordinates specified in the parameters of the function.
As blinders pointed out on IRC, this is not actually correct.

triggerAction from the serverside cannot trigger the clientside, however the clientside can also trigger itself.
Reply With Quote
  #14  
Old 09-05-2009, 08:32 PM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
Quote:
Originally Posted by Gambet View Post
Feel free to add this to the wiki but I'm not going to go above and beyond with this thing, this is enough for me.
Will have to wait until Monday when the wiki is supposed to be back.
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.
Reply With Quote
  #15  
Old 09-05-2009, 09:10 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Quote:
Originally Posted by napo_p2p View Post
Will have to wait until Monday when the wiki is supposed to be back.
Add it to the other wiki?
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:53 PM.


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