Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Level NPC Server -> Client Communication? (https://forums.graalonline.com/forums/showthread.php?t=134268870)

Astram 10-27-2013 07:11 PM

Level NPC Server -> Client Communication?
 
As the title suggests, I'm looking to have the serverside interact with the clientside in a level npc. I'm aware of the backwards direction which I would use triggeraction for, however, I'm not sure how to go about server to the client. Thank you for taking your time to read this and possibly answer this short question!

EDIT:
Also, what I'm trying to accomplish is showing a polygon around an NPC detecting a range of 5 tiles around the NPC. This polygon should be visible to everyone.

Jakov_the_Jakovasaur 10-27-2013 07:21 PM

in the new V6 client a serverside triggeraction() in a level npc is received on the clients of all players in the level, and if you want to store data that can be retrieved on the client of a player who enters the level you can also use this.attr[#]
PHP Code:

function updatePoly(temp.polyarray){
  
this.attr[1] = int(timevar2);
  
this.attr[2] = temp.polyarray;
  
triggeraction(this.1this.1"UpdatePoly""");
}

//#CLIENTSIDE
function onCreated()
  
this.setshape(13232);

function 
onPlayerEnters()
  if(
this.attr[1] != this.save_time)
    
this.onActionUpdatePoly();

function 
onActionUpdatePoly(){
  
this.save_time this.attr[1];
  
this.showpoly(200this.attr[2].tokenize(","));



Astram 10-27-2013 07:28 PM

Thank you however this doesn't appear to be working:
PHP Code:

triggeraction(this..5this..5"Test"this.owner); 

when I try and catch in it clientside doing
PHP Code:

function onActionTest(this.zowner) {
  
scheduleevent(.05"showPoly");
  
this.chat this.zowner;


I even set the shape of the object doing:
PHP Code:

setshape016 516 5); 

But it still isn't working.

Jakov_the_Jakovasaur 10-27-2013 07:31 PM

im not sure that you can specify parameters as 'this.' variables like that as opposed to using 'temp.', have you tried doing 'this.chat = "test";' to ensure the trigger is at least being received?

also having the first parameter in the setshape() as 0 instead of 1 might be a problem, and is the setshape() on both clientside and serverside?

Astram 10-27-2013 07:51 PM

Quote:

Originally Posted by Jakov_the_Jakovasaur (Post 1723607)
im not sure that you can specify parameters as 'this.' variables like that as opposed to using 'temp.', have you tried doing 'this.chat = "test";' to ensure the trigger is at least being received?

also having the first parameter in the setshape() as 0 instead of 1 might be a problem, and is the setshape() on both clientside and serverside?

I'm pretty sure 0 works as a setshape because that just allows no movement through the NPC. I did setshape serverside and I have debugged the triggeraction and it isn't receiving it.

Just tested using 1 as setshape and nothing changes anyways.

Jakov_the_Jakovasaur 10-27-2013 08:04 PM

have you used setshape(); on clientside as well?
when its used serverside that doesnt get synchronised to clientside in the way that some other variables do, and because the trigger is being received on the client it needs a shape to be set clientside

Astram 10-27-2013 10:11 PM

Quote:

Originally Posted by Jakov_the_Jakovasaur (Post 1723609)
have you used setshape(); on clientside as well?
when its used serverside that doesnt get synchronised to clientside in the way that some other variables do, and because the trigger is being received on the client it needs a shape to be set clientside

Oh thank you, I'll try it!

EDIT: Nope, this isn't working either. Really weird.

Jakov_the_Jakovasaur 10-27-2013 10:58 PM

could you post the entire script?
it sounds like youre doing everything right based on what youve provided so it would be interesting to see it all pieced together

one guess would be that the serverside function which contains 'triggeraction();' isnt being executed, have you debugged that as well?

Astram 10-27-2013 11:00 PM

PHP Code:

function onCreated() {
  
this.owner null;
  
this.ani "grab";
  
setshape116 516 5);
}

function 
onInitialize(playername) {
  
this.owner playername;
  
triggeraction(this..5this..5"Test"null);
  
onTimeOut();
}

function 
onPlayerChats() {
  if (
player.chat == "bye") {
    
destroy();
  }
}

function 
onActionRightMouse() {
  
destroy();
}

function 
onTimeOut() {
  if (
max(this.owner.xthis.x) - min(this.owner.xthis.x) > 5this.+= 1;
  if (
max(this.owner.ythis.y) - min(this.owner.ythis.y) > 5this.+= 1;
  
setTimer(.05);
}

//#CLIENTSIDE
function onCreated() {
  
setshape116 516 5);
}

function 
onActionTest() {
  
scheduleevent(.05"showPoly");
  
player.chat ":D";
}

function 
showPoly() {
  
with(findimg(200)) {
    
polygon = {
      
this.5this.5,
      
this.5this.5,
      
this.5this.5,
      
this.5this.5
    
};
    
red green blue 0;
    
alpha .6;
    
layer 3;
  }


I know that onCreated is there twice but it seems to those parts seem to work fine.

Jakov_the_Jakovasaur 10-27-2013 11:03 PM

there is no default event called 'onInitialize' in level npcs, only database npcs and putnpc2s

its also worth mentioning that there is no player parameter in that onInitialize event

using the same event on clientside and serverside is perfectly fine, you can even use onCreated() within multiple classes that are joined to the same object

Astram 10-27-2013 11:58 PM

Quote:

Originally Posted by Jakov_the_Jakovasaur (Post 1723616)
there is no default event called 'onInitialize' in level npcs, only database npcs and putnpc2s

its also worth mentioning that there is no player parameter in that onInitialize event

using the same event on clientside and serverside is perfectly fine, you can even use onCreated() within multiple classes that are joined to the same object

Sorry I forgot to mention that this was a class and I used putnpc2 then I did:
temp.npc.trigger("Initialize", params...);

Jakov_the_Jakovasaur 10-28-2013 12:10 AM

oh well in that case although it should still work its not a good idea to use that event name because it will be invoked every time the npc server is restarted

only other explanations i can think of is that you cant do 0.05 second timeouts serverside and trying it could be preventing the entire script, plus the npcs x and y are being altered after the triggeraction (which does get synchronised to clientside) and that could somehow be breaking it

i would suggest commenting out the timeout out and seeing if the triggeraction works

xXziroXx 10-28-2013 11:41 PM

Quote:

Originally Posted by Jakov_the_Jakovasaur (Post 1723620)
oh well in that case although it should still work its not a good idea to use that event name because it will be invoked every time the npc server is restarted

You're confusing his onInitialize() with the default event onInitialized(). He should be fine.

I'm pretty sure this has something to do with the shape(s), that's always been the problem for me. Unfortunately I'm in a bit of a hurry and wasn't able to really look over your script at all, maybe I'll be able to get back too it later.

Astram 10-29-2013 12:44 AM

Quote:

Originally Posted by xXziroXx (Post 1723637)
You're confusing his onInitialize() with the default event onInitialized(). He should be fine.

I'm pretty sure this has something to do with the shape(s), that's always been the problem for me. Unfortunately I'm in a bit of a hurry and wasn't able to really look over your script at all, maybe I'll be able to get back too it later.

Thank you. But I don't think the shape is the problem.

Starfire2001 10-29-2013 02:00 AM

Maybe I'm not getting the right idea here, but why don't you just put the scheduleevent(.05, "showPoly"); (which might work but should have a third param, so scheduleevent(.05, "showPoly", null);) in the clientside onCreated(), as you seem to be sending the trigger right after the NPC is placed anyways.


All times are GMT +2. The time now is 05:27 PM.

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