This is demonstrating how you would have an npc call a weapon function to trigger an event on its serverside or clientside.
This is the weapon script.
PHP Code:
public function npctriggerclient(npcid, evtname, params...) {
triggerclient("gui", this.name, "ntc", npcid, evtname, params...);
}
public function npctriggerclientother(acc, npcid, evtname, params...) {
with (findplayer(acc)) {
triggerclient("gui", this.name, "ntc", npcid, evtname, params...);
}
}
function onActionServerside() {
temp.i = 0;
if (params[0] == "nts") {
for (i: findlevel(params[1]).npcs) {
if (i.id == params[2]) {
i.trigger(params[3], params[...]);
break;
}
}
}
}
//#CLIENTSIDE
function onActionClientside() {
if (params[0] == "ntc") {
findnpcbyid(params[1]).trigger(params[2], params[...]);
}
}
public function npctriggerserver(npclvl, npcid, evtname, params...) {
triggerserver("gui", this.name, "nts", npclvl, npcid, evtname, params...);
}
Considering how npc ids are local to the level, I don't think the server to client part would work the same. In that case you would need to manually assign a unique name for the npc, since findlevel() does not appear to exist on clientside.
In the npc in it's created you would do something like:
PHP Code:
(@ "localnpc" @ extractfilebase(this.level.name) @ this.id) = this;
A class could be used for that. And would probably be better to be using a global TStaticVar to put those vars on:
PHP Code:
// In the system weapon on created:
if (player.objectmap.type() != 2)
player.objectmap = new TStaticVar("ObjectMap");
Then we do:
PHP Code:
// In a local npc on created:
ObjectMap.(@ "localnpc" @ extractfilebase(this.level.name) @ this.id) = this;
Though in the end it would be easier to have an Interop weapon or so and have npcs register with it when they're created and it will have functions for triggering the npc's other side and stuff.
Quote:
Instead of doing the above you'd rather just use triggeraction...
|
First post.