Quote:
Originally Posted by Loriel
I think what Tyhm is looking for here is triggering the "other" side of the script without involving coordinates or the chance that other scripts might be hit by it.
|
If you have an NPC's ID and level name, you can send it to a triggerserver/client and simply use functions to locate the NPC object.
These are two functions extracted from my triggercontrol class that is used to wrap the triggerserver() and triggerclient() in weapons:
PHP Code:
public function npcfunction(lvlname, npcid, funcname, p3, p4, p5, p6, p7, p8, p9) {
for (temp.i: findlevel(temp.lvlname).npcs) {
if (temp.i.id == temp.npcid) {
return temp.i.(@ temp.funcname)(temp.p3, temp.p4, temp.p5, temp.p6, temp.p7, temp.p8, temp.p9);
}
}
}
//#CLIENTSIDE
public function npcfunction(npcid, funcname, p2, p3, p4, p5, p6, p7, p8, p9) {
return findnpcbyid(temp.npcid).(@ temp.funcname)(temp.p2, temp.p3, temp.p4, temp.p5, temp.p6, temp.p7, temp.p8, temp.p9);
}
Call clientside part of an NPC from serverside, assuming I have a calling player, I can:
WeaponName.ClientFunction(null, "npcfunction", this.id, "saystuff", "lol I like pancakes");
Or from the client:
WeaponName.ServerFunction(null, "npcfunction", this.level.name, this.id, "saystuff", "Inverness was here");
Note that ClientFunction() and ServerFunction() are part of my class, they call a function on the other side and wait for return value. Naturally, I would prefer a hard-coded function, as it would be more efficient.