Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-13-2009, 03:53 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Trigger Control 2

This is an improved and simplified version of a small utility class I made before. It is #2 because it is not compatible with the previous version because the function names are different (and more descriptive).

Basically this class wraps the triggerserver/triggerclient functionality in a weapon, meaning you should only join the class to a weapon. It provides a more direct way to call functions on the server from the client and vice-versa. The important thing is that it can wait for a value to be returned if the wait time is greater than zero.

The functions work like:

call<side>(wait_time, function_name, params...);

Note that up to 8 parameters are accepted.

Other functions provided are callnpc(level_name, npc_id, function_name, params...) on both sides. I can't remember why I originally added that but it can be used to call a specific npc using the previously mentioned functions.

Note that the function name for better or worse can include dots as it uses makevar to resolve the name. So it is possible to use "ObjectName.FunctionName" in the function_name parameter.

This class is named util_triggercontrol2:

PHP Code:
/* Made by Inverness
   This class simplifies serverside to clientside
   communication and vice-versa.
   
   This class can only be joined to weapons.
 */
function callclient(wtimefnamep0p1p2p3p4p5p6p7) {
  if (
temp.wtime 0) {
    
triggerclient("gui"this.name"c",
      
temp.fname,
      
temp.p0temp.p1temp.p2temp.p3,
      
temp.p4temp.p5temp.p6temp.p7);
    
waitfor(this"__cce"temp.wtime);
    
temp.out this.__ccr;
    
this.__ccr null;
    return 
temp.out;
  }
  else {
    
triggerclient("gui"this.name"n",
      
temp.fname,
      
temp.p0temp.p1temp.p2temp.p3,
      
temp.p4temp.p5temp.p6temp.p7);
  }
}
function 
callnpc2(levelnamenpcidfuncnamep3p4p5p6p7p8p9p10) {
  for (
temp.ifindlevel(temp.levelname).npcs) {
    if (
temp.i.id == temp.npcid) {
      return 
temp.i.(@ temp.funcname)(
        
temp.p3temp.p4temp.p5temp.p6,
        
temp.p7temp.p8temp.p9temp.p10);
    }
  }
}
function 
onActionServerSide() {
  if (
params[0] == "e") {
    
this.__ccr params[1];
    
this.scheduleevent(0"__cce"null);
  }
  else if (
params[0] == "c") {    
    
triggerclient("gui"this.name"e",
      
makevar(params[1])(
        
params[2], params[3], params[4], params[5],
        
params[6], params[7], params[8], params[9]
      )
    );
  }
  else if (
params[0] == "n") {
    
makevar(params[1])(
      
params[2], params[3], params[4], params[5],
      
params[6], params[7], params[8], params[9]
    );
  }
}
//#CLIENTSIDE
function onActionClientSide() {
  if (
params[0] == "e") {
    
this.__scr params[1];
    
this.scheduleevent(0"__sce"null);
  }
  else if (
params[0] == "c") {    
    
triggerserver("gui"this.name"e",
      
makevar(params[1])(
        
params[2], params[3], params[4], params[5],
        
params[6], params[7], params[8], params[9]
      )
    );
  }
  else if (
params[0] == "n") {
    
makevar(params[1])(
      
params[2], params[3], params[4], params[5],
      
params[6], params[7], params[8], params[9]
    );
  }
}
function 
callnpc2(levelnamenpcidfuncnamep3p4p5p6p7p8p9p10) {
  for (
temp.ifindlevel(temp.levelname).npcs) {
    if (
temp.i.id == temp.npcid) {
      return 
temp.i.(@ temp.funcname)(
        
temp.p3temp.p4temp.p5temp.p6,
        
temp.p7temp.p8temp.p9temp.p10);
    }
  }
}
function 
callserver(wtimefnamep0p1p2p3p4p5p6p7) {
  if (
temp.wtime 0) {
    
triggerserver("gui"this.name"c",
      
temp.fname,
      
temp.p0temp.p1temp.p2temp.p3,
      
temp.p4temp.p5temp.p6temp.p7);
    
waitfor(this"__sce"temp.wtime);
    
temp.out this.__scr;
    
this.__scr null;
    return 
temp.out;
  }
  else {
    
triggerserver("gui"this.name"n",
      
temp.fname,
      
temp.p0temp.p1temp.p2temp.p3,
      
temp.p4temp.p5temp.p6temp.p7);
  }

__________________
Reply With Quote
  #2  
Old 12-13-2009, 03:57 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
It would be cool if GScript supported n-parameter function calls.
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 11:38 AM.


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