View Single Post
  #1  
Old 04-19-2007, 10:58 PM
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
Client <-> Serverside Function Caller

This is a set of functions I made after waitfor() was implemented.
The notification functions, which I made for my information system so the gui would open after the information was gotten and not before. Its used for the client and server function triggers to make the script wait until you've got the return of the function.
PHP Code:
// This was placed in a weapon named System.
public function waitForNotify(objactiontime) {
  return 
waitfor(obj"Notify" actiontime);
}
public function 
notifyClient(objenametime) {
  
triggerClient("gui"name"notify"objenametime);
}
public function 
notifyServer(objenametime) {
  
scheduleEvent(0"ActionServerSide"objenametime);
}
public function 
clientFunction(fobjfnamefparams) {
  
temp.out 0;

  
client.temp.(@ "clientfunction_" fname) = null;
  
triggerClient("gui"name"clientfunction"fnamefparamsfobj);
  
waitForNotify(name"ClientFunctionEnd"5);
  
out client.temp.(@ "clientfunction_" fname);
  
client.temp.(@ "clientfunction_" fname) = null;
  return 
out;
}
function 
onActionServerSide() {
  switch (
params[0]) {
    case 
"notify":
      
makevar(params[1]).scheduleEvent(params[3], "Notify" params[2], null);
      break;
    case 
"serverfunction":
      
temp.0;
      
temp.fn params[1];
      
      
makevar(params[3] @ "." params[1])(params[2][0], params[2][1], params[2][2], params[2][3], params[2][4], params[2][5]);
      
client.temp.(@ "serverfunction_" fn) = r;
      
notifyClient(name"ServerFunctionEnd"0);
      break;
  }
}
//#CLIENTSIDE
function onActionClientSide() {
  switch (
params[0]) {
    case 
"notify":
      
makevar(params[1]).scheduleEvent(params[3], "Notify" params[2], null);
      break;
    case 
"clientfunction":
      
temp.0;
      
temp.fn params[1];
      
      
makevar(params[3] @ "." params[1])(params[2][0], params[2][1], params[2][2], params[2][3], params[2][4], params[2][5]);
      
client.temp.(@ "clientfunction_" fn) = r;
      
notifyServer(name"ClientFunctionEnd"0);
      break;
  }
}
public function 
waitForNotify(objactiontime) {
  return 
waitfor(obj"Notify" actiontime);
}
public function 
notifyServer(objenametime) {
  
triggerServer("gui"name"notify"objenametime);
}
public function 
notifyClient(objenametime) {
  
scheduleEvent(0"ActionClientSide""notify"objenametime);
}
public function 
serverFunction(fobjfnamefparams) {
  
temp.out 0;
  
  
client.temp.(@ "serverfunction_" fname) = null;
  
triggerServer("gui"name"serverfunction"fnamefparamsfobj);
  
waitForNotify(name"ServerFunctionEnd"5);
  
out client.temp.(@ "serverfunction_" fname);
  
client.temp.(@ "serverfunction_" fname) = null;
  return 
out;

Obviously, to use this correctly the object containing the function you're calling must have an identifier, the name variable.

And here is the script I used to test it:
PHP Code:
function onCreated() {
  
with (findPlayer("Inverness")) {
    echo(
System.clientFunction("InverTest","clientFunction"null));
  }
}
//#CLIENTSIDE
public function clientFunction() {
  return 
"OOGLEBOOGLESMORF";

Which worked obviously.

I don't know how this would affect script performance or anything, I just did it because using triggerServer() and triggerClient() and previously triggerAction() has always irritated me.
__________________
Reply With Quote