View Single Post
  #13  
Old 04-25-2009, 11:28 AM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
Quote:
Originally Posted by Inverness View Post
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(npcidevtnameparams...) {
  
triggerclient("gui"this.name"ntc"npcidevtnameparams...);
}
public function 
npctriggerclientother(accnpcidevtnameparams...) {
  
with (findplayer(acc)) {
    
triggerclient("gui"this.name"ntc"npcidevtnameparams...);
  }
}
function 
onActionServerside() {
  
temp.0;

  if (
params[0] == "nts") {
    for (
ifindlevel(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(npclvlnpcidevtnameparams...) {
  
triggerserver("gui"this.name"nts"npclvlnpcidevtnameparams...);

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.
First post.
I actually like this solution.
I just don't see why Stefan can't make triggerserver/client work in every NPC just as easy as it works in the Weapons.
Why is the Serverside name not the Clientside Name?
Kinda confusing, isn't it?
Reply With Quote