Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Trigger Client NPC (https://forums.graalonline.com/forums/showthread.php?t=86364)

Pelikano 06-15-2009 12:03 PM

Trigger Client NPC
 
Is there any way to trigger a clientside-function in an NPC?

Skyld 06-15-2009 03:49 PM

There have been many threads about this already, please use the forum search function. You'll also have to be more specific as to what type of NPC (level NPC?) or a little bit more about what it does.

Pelikano 06-15-2009 04:56 PM

Quote:

Originally Posted by Skyld (Post 1499670)
There have been many threads about this already, please use the forum search function. You'll also have to be more specific as to what type of NPC (level NPC?) or a little bit more about what it does.

Sorry, didn't use the search function :p:

PHP Code:

function onCreated() {
  if (
blablabla) {
    
// trigger the client
  
}
}
//#CLIENTSIDE
function onClientSideFunction() {
  
// Stuff


Something like this

cbk1994 06-15-2009 06:10 PM

No, you normally can't trigger client like that. Think about it: It'd have to trigger client for every player in the level, right? Unless of course you did something like player.triggerclient.

However, I don't think it works for DB NPCs (putnpc2, for example).

I could be wrong, though.

salesman 06-15-2009 07:36 PM

Quote:

Originally Posted by Pelikano (Post 1499685)
Sorry, didn't use the search function :p:

PHP Code:

function onCreated() {
  if (
blablabla) {
    
// trigger the client
  
}
}
//#CLIENTSIDE
function onClientSideFunction() {
  
// Stuff


Something like this

In that example you could just have the onCreated() function on the clientside, no trigger needed (I'm assuming it's a DBNPC via putnpc?).

If the conditional statement 'if (blablabla)' can only be read serverside, I suggest storing the data in some other way where it could be read on the client.

Edit: what I'm trying to say is that there's most likely a way to do it without needing a server->client trigger and you should be more specific with your problem.

Pelikano 06-15-2009 07:57 PM

Quote:

Originally Posted by salesman (Post 1499739)
In that example you could just have the onCreated() function on the clientside, no trigger needed (I'm assuming it's a DBNPC via putnpc?).

If the conditional statement 'if (blablabla)' can only be read serverside, I suggest storing the data in some other way where it could be read on the client.

Edit: what I'm trying to say is that there's most likely a way to do it without needing a server->client trigger and you should be more specific with your problem.


I don't have a problem, it would just be handy if you could trigger a function on the Client in a level NPC ;D

Robin 06-15-2009 08:04 PM

could you not just do

NPC Code:

triggeraction(this.x, this.y, "clientside", "params");
//#CLIENTSIDE
function onActionClientside() {

}



etc?

DustyPorViva 06-15-2009 08:06 PM

Quote:

Originally Posted by Robin (Post 1499752)
could you not just do

NPC Code:

triggeraction(this.x, this.y, "clientside", "params");
//#CLIENTSIDE
function onActionClientside() {

}



etc?

Doesn't work with NPCs that don't have a shape(aka non-blocking), and if there are other NPC's at the same space, they will get the triggeraction instead.

Robin 06-15-2009 08:11 PM

Quote:

Originally Posted by DustyPorViva (Post 1499753)
Doesn't work with NPCs that don't have a shape(aka non-blocking), and if there are other NPC's at the same space, they will get the triggeraction instead.

So what do you suggest? I was looking for something like this the other day actually.

DustyPorViva 06-15-2009 08:19 PM

It's fairly easy to send data from serverside > clientside via attr[]'s. You can do checks like that if you'd like.

What I also did was set-up a DBNPC that would intercept the triggerserver's/triggerclient's from the local NPC, and then do the communication in the DBNPC itself and then resend the function. However, I only did this for clientside > serverside, so I'm not particularly sure of how that'd work the other way around

DBNPC:
PHP Code:

function onActionServerside(cmd,lvl,checkid) {
  if (
cmd == "checkhit") {
    for (
temp.ifindlevel(lvl).npcs) {
      if (
i.id == checkid) {
        
i.test();
        break;
      }
    }
  }


And in the level itself(from the clientside):
PHP Code:

triggerserver("npc","mydbnpc","checkhit",this.level.name,this.id); 


Robin 06-15-2009 08:31 PM

http://forums.graalonline.com/forums...=triggerclient

could have sworn triggerclient() worked?

Angel_Light 06-16-2009 01:31 AM

It does, but not in the way I think you want it too.

NPC Code:
triggerClient( "gui", name, params...);



PHP Code:

function onCreated()
{

  for ( 
temp.plallplayers)
  {

    
pl.triggerClient"gui"name"Hello World");

  }
}

//#CLIENTSIDE

function onActionClientside()
{

  
player.chat params0];



I know you can replace "gui" with "weapon" but it still does the same. Can someone enlighten us if there is any difference.

For level NPC's you just have to define the shape, such as
NPC Code:
setshape( 0, 16 * 2, 16 * 3);

0 being non-blocking.

Then you can do the triggerAction();

example

PHP Code:

function onCreated()
{

  
triggerActionthis.xthis.y"Clientside""Hello World");

}

//#CLIENTSIDE

function onCreated()
{

  
setShape016 216 3);

}

function 
onActionClientside()
{

  
player.chat params0];



Also, you dont have to use "Clientside" since it's a triggerAction(); So replace that with something like "Data" then the function would be onActionData()

Robin 06-16-2009 03:16 AM

It really does need a way of directly calling a function on the clientside of the current DBNPC / Level NPC.

Angel_Light 06-16-2009 04:49 AM

My first method works for dbNPCs and second for levelNPCs. Both methods have worked for me.

Pelikano 06-16-2009 09:09 AM

Thanks Angel,

but your second method doesn't work.
You cannot use triggeraction() from server to client as it seems..

Robin 06-16-2009 02:59 PM

Quote:

Originally Posted by Pelikano (Post 1499846)
Thanks Angel,

but your second method doesn't work.
You cannot use triggeraction() from server to client as it seems..

Yes you can.. ?

Angel_Light 06-21-2009 05:16 PM

you might want to put this.x + 0.5 and this.y + 0.5 in the triggeraction since it is calling it on the border. I found doing that usually fixes it.

xXziroXx 06-22-2009 12:33 PM

Quote:

Originally Posted by Angel_Light (Post 1500741)
you might want to put this.x + 0.5 and this.y + 0.5 in the triggeraction since it is calling it on the border. I found doing that usually fixes it.

Sounds like you never setshape on the serversided part of the NPC tbh.

Angel_Light 06-23-2009 02:17 AM

Quote:

Originally Posted by xXziroXx (Post 1500949)
Sounds like you never setshape on the serversided part of the NPC tbh.

Both work, but probably setting setshape may sound more efficient.

DustyPorViva 06-23-2009 02:19 AM

Triggeraction probably won't work if the shape of the NPC isn't set on the serverside. This is because without a serverside setshape, the NPC server won't be able to 'find' the NPC when you do the triggeraction(since triggeraction uses blocking space only to trigger, and non-blocking will not register).

Angel_Light 06-23-2009 10:50 PM

setshape isnt always blocking per sei, if you just do setshape( 0, 32, 32); zero will make it non-blocking


All times are GMT +2. The time now is 03:53 AM.

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