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(obj, action, time) {
return waitfor(obj, "Notify" @ action, time);
}
public function notifyClient(obj, ename, time) {
triggerClient("gui", name, "notify", obj, ename, time);
}
public function notifyServer(obj, ename, time) {
scheduleEvent(0, "ActionServerSide", obj, ename, time);
}
public function clientFunction(fobj, fname, fparams) {
temp.out = 0;
client.temp.(@ "clientfunction_" @ fname) = null;
triggerClient("gui", name, "clientfunction", fname, fparams, fobj);
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.r = 0;
temp.fn = params[1];
r = 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.r = 0;
temp.fn = params[1];
r = 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(obj, action, time) {
return waitfor(obj, "Notify" @ action, time);
}
public function notifyServer(obj, ename, time) {
triggerServer("gui", name, "notify", obj, ename, time);
}
public function notifyClient(obj, ename, time) {
scheduleEvent(0, "ActionClientSide", "notify", obj, ename, time);
}
public function serverFunction(fobj, fname, fparams) {
temp.out = 0;
client.temp.(@ "serverfunction_" @ fname) = null;
triggerServer("gui", name, "serverfunction", fname, fparams, fobj);
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.