Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   triggerserver/client (https://forums.graalonline.com/forums/showthread.php?t=85272)

fragman85 04-23-2009 07:04 AM

triggerserver/client
 
Why don't these two functions work in NPCs too?
I find it kinda dumb that you have to do: triggeraction(this.x, this.y...)
:o

cbk1994 04-23-2009 09:58 PM

They do work.

PHP Code:

findPlayer("cbk1994").triggerclient("gui""-System""blueDeath"); 

You can never trigger serverside from serverside; use this instead.
PHP Code:

(@ "-System").trigger("onActionServerSide""meow"); 


Crow 04-23-2009 10:05 PM

Quote:

Originally Posted by cbk1994 (Post 1486278)
They do work.

PHP Code:

findPlayer("cbk1994").triggerclient("gui""-System""blueDeath"); 

You can never trigger serverside from serverside; use this instead.
PHP Code:

(@ "-System").trigger("onActionServerSide""meow"); 


Well, he wants to use them to trigger the serverside/clientside in an NPC using another or the same NPC. Which does not work.

cbk1994 04-23-2009 10:14 PM

Quote:

Originally Posted by Crow (Post 1486279)
Well, he wants to use them to trigger the serverside/clientside in an NPC using another or the same NPC. Which does not work.

From a level NPC or a DB NPC?

EDIT: I think I get it ... yeah, I agree, it would be cool if there was a way to do this easily.

Inverness 04-23-2009 10:50 PM

Quote:

Originally Posted by Crow (Post 1486279)
Well, he wants to use them to trigger the serverside/clientside in an NPC using another or the same NPC. Which does not work.

Well it's possible if you have a weapon between the two npcs. From client to server you'd need to send the npc's level name and ID, and from server to client only the npc's ID; this is so the npc object can be located.

Admins 04-23-2009 10:54 PM

You can trigger npcs, you just need to know the (serverside) name of the npc: triggerserver("npc", npcname, eventname, params..)

cbk1994 04-23-2009 11:29 PM

Quote:

Originally Posted by Stefan (Post 1486291)
You can trigger npcs, you just need to know the (serverside) name of the npc: triggerserver("npc", npcname, eventname, params..)

I don't think this works with local level NPCs.

Crow 04-24-2009 02:18 PM

Quote:

Originally Posted by cbk1994 (Post 1486300)
I don't think this works with local level NPCs.

Pretty sure it does not. Level NPCs all have "unknown" as their name I think.

fowlplay4 04-25-2009 05:42 AM

Well if the this.name isn't that same on the clientside you could store their .name in an attr and do..

PHP Code:

function onCreated() {
  
attr[3] = this.name;
}
//#CLIENTSIDE
function onDamageNPC(baddy) {
  
triggerserver("npc"baddy.attr[3], "damage"9999);


Of course you'll need some sort of targetting system to use the damage npc function.

[email protected] 04-25-2009 09:39 AM

Instead of doing the above you'd rather just use triggeraction...

Inverness 04-25-2009 10:09 AM

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] (Post 1486669)
Instead of doing the above you'd rather just use triggeraction...

First post.

[email protected] 04-25-2009 10:21 AM

Oh- I see what you're trying to do.
Makes sense- interesting solution @ Inverness

Pelikano 04-25-2009 11:28 AM

Quote:

Originally Posted by Inverness (Post 1486672)
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?

Inverness 04-25-2009 09:59 PM

Quote:

Originally Posted by Pelikano (Post 1486677)
Why is the Serverside name not the Clientside Name?
Kinda confusing, isn't it?

What do you mean? Local npcs do not have names, they're identified by their ID in relation to the level they're in.


All times are GMT +2. The time now is 12:59 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.