Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Trigger Control 2 (https://forums.graalonline.com/forums/showthread.php?t=134257280)

Inverness 12-13-2009 03:53 AM

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



WhiteDragon 12-13-2009 03:57 AM

It would be cool if GScript supported n-parameter function calls.


All times are GMT +2. The time now is 12:49 PM.

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