Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 


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 05:58 AM.


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