Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   How-To: triggerAction() (clientside <--> serverside communication in level NPCs) (https://forums.graalonline.com/forums/showthread.php?t=87732)

Gambet 09-02-2009 06:02 AM

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



Soala 09-02-2009 02:57 PM

*Vote for this How-To to be on the wiki*

Liberated 09-02-2009 03:19 PM

i vote for a yes.

Toxen 09-02-2009 05:02 PM

Gambet I always love to read your "How-To" threads there always so helpful and to the point.

Deas_Voice 09-02-2009 06:10 PM

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.

Crow 09-02-2009 06:13 PM

Quote:

Originally Posted by Deas_Voice (Post 1520679)
should be a howto or tutorial subforum or a index sticked.

Wiki.

Deas_Voice 09-02-2009 06:29 PM

Quote:

Originally Posted by Crow (Post 1520680)
Wiki.

or wiki, but since it's already here, why not get a sticked index of howto-s? :)

Loriel 09-02-2009 06:37 PM

Quote:

Originally Posted by Deas_Voice (Post 1520686)
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

Deas_Voice 09-02-2009 06:42 PM

jeeze, can't i have my own opinion?..

xXziroXx 09-02-2009 06:49 PM

Quote:

Originally Posted by Deas_Voice (Post 1520688)
jeeze, can't i have my own opinion?..

No, since you obviously get offended when people counter your opinion with their own.

Gambet 09-02-2009 06:51 PM

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.

Deas_Voice 09-02-2009 07:02 PM

Quote:

Originally Posted by xXziroXx (Post 1520690)
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.

Loriel 09-05-2009 08:25 PM

Quote:

Originally Posted by Gambet (Post 1520602)
. 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.

napo_p2p 09-05-2009 08:32 PM

Quote:

Originally Posted by Gambet (Post 1520691)
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.

Loriel 09-05-2009 09:10 PM

Quote:

Originally Posted by napo_p2p (Post 1521323)
Will have to wait until Monday when the wiki is supposed to be back.

Add it to the other wiki?

Pelikano 09-05-2009 10:52 PM

Quote:

Originally Posted by Loriel (Post 1521332)
Add it to the other wiki?

"other wiki"? oO

Crow 09-06-2009 12:56 AM

Quote:

Originally Posted by Pelikano (Post 1521358)
"other wiki"? oO

[dot]us

Gambet 09-06-2009 02:43 AM

Quote:

Originally Posted by Loriel (Post 1521320)
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.


I read somewhere on the wiki originally that you could, but after testing it out when you use triggerAction on the serverside it just triggers to itself. I'll have my original post edited, I suppose people can use save[] and attr[]'s to send information to the clientside.

salesman 09-06-2009 05:30 AM

Quote:

Originally Posted by Gambet (Post 1521387)
I read somewhere on the wiki originally that you could, but after testing it out when you use triggerAction on the serverside it just triggers to itself. I'll have my original post edited, I suppose people can use save[] and attr[]'s to send information to the clientside.

I think I recall Stefan even saying that triggeraction on the serverside will trigger the client, no?

DustyPorViva 09-06-2009 05:36 AM

triggeractions are a bit iffy, because if there's another NPC also there, it will 'capture' the triggeraction instead of the intended NPC, as triggeractions will only call on the NPC that's on top.

fowlplay4 09-06-2009 06:21 AM

Personally I'd never use triggeraction server <----> client in a level npc, from experience it can "miss" or not work at all so why take that chance.

Now triggerserver/triggerclient + weapon npcs, that's where it's at :>

Crow 09-06-2009 09:38 AM

Quote:

Originally Posted by DustyPorViva (Post 1521401)
triggeractions are a bit iffy, because if there's another NPC also there, it will 'capture' the triggeraction instead of the intended NPC, as triggeractions will only call on the NPC that's on top.

Ye, that's just plain stupid. I hope it's "fixed" in the next version, should it ever be released..


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

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