View Single Post
  #1  
Old 04-25-2009, 10:09 AM
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
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.
Quote:
Originally Posted by [email protected] View Post
Instead of doing the above you'd rather just use triggeraction...
First post.
__________________

Last edited by Inverness; 04-25-2009 at 10:29 AM..
Reply With Quote