PDA

View Full Version : Level NPC Server -> Client Communication?


Astram
10-27-2013, 07:11 PM
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[#]

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

//#CLIENTSIDE
function onCreated()
this.setshape(1, 32, 32);

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

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

Astram
10-27-2013, 07:28 PM
Thank you however this doesn't appear to be working:

triggeraction(this.x + .5, this.y + .5, "Test", this.owner);

when I try and catch in it clientside doing

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

I even set the shape of the object doing:

setshape( 0, 16 * 5, 16 * 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
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
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
function onCreated() {
this.owner = null;
this.ani = "grab";
setshape( 1, 16 * 5, 16 * 5);
}

function onInitialize(playername) {
this.owner = playername;
triggeraction(this.x + .5, this.y + .5, "Test", null);
onTimeOut();
}

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

function onActionRightMouse() {
destroy();
}

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

//#CLIENTSIDE
function onCreated() {
setshape( 1, 16 * 5, 16 * 5);
}

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

function showPoly() {
with(findimg(200)) {
polygon = {
this.x - 5, this.y - 5,
this.x + 5, this.y - 5,
this.x + 5, this.y + 5,
this.x - 5, this.y + 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
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
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
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.

Astram
10-29-2013, 02:49 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.

I don't think scheduleevent can have less than 3 params.

fowlplay4
10-29-2013, 04:59 PM
I don't think scheduleevent can have less than 3 params.

That was a V5 issue, trigger no longer requires a second parameter either.

I still do both by habit.

Jakov_the_Jakovasaur
10-29-2013, 07:15 PM
i just tested the following script in a local npc (putnpc2) and it worked fine -


function onCreated() {
this.ani = "grab";
setshape( 1, 80, 80);
}

function onInitialize(temp.pobj) {
this.owner = temp.pobj.account;
triggeraction(this.x + .5, this.y + .5, "Test", null);
}

function onPlayerChats() {
if (player.chat == "test") {
this.onInitialize(player);
}
}

//#CLIENTSIDE
function onCreated() {
this.setshape(1, 80, 80);
}

function onActionTest() {
this.scheduleEvent(.05, "ShowPoly");
this.chat = ":D";
}

function onShowPoly() {
with(findimg(200)) {
polygon = {
this.x - 5, this.y - 5,
this.x + 5, this.y - 5,
this.x + 5, this.y + 5,
this.x - 5, this.y + 5
};
red = green = blue = 0;
alpha = .6;
layer = 3;
}
}


http://img202.imageshack.us/img202/140/yjih.png

so im fairly confident its breaking either because of the timeout or because of whats happening in the timeout

unrelated but also note how 'scheduleEvent' invokes 'onShowPoly' from the parameter 'ShowPoly'

if all else fails then why not try setting a gani attr on serverside, then moving the poly script into the gani attr script?

npc -


function onCreated() {
this.owner = null;
this.ani = "grab";
setshape( 1, 16 * 5, 16 * 5);
this.attr[5] = "polytest.gani";
}


polytest.gani -

SCRIPT

function onPlayerEnters(){
with(findimg(200)) {
polygon = {
this.x - 5, this.y - 5,
this.x + 5, this.y - 5,
this.x + 5, this.y + 5,
this.x - 5, this.y + 5
};
red = green = blue = 0;
alpha = .6;
layer = 3;
attachtoowner = true;
}
}

SCRIPTEND


using 'attachtoowner = true;' will make the poly automatically follow the npc object as it moves

Astram
10-29-2013, 08:06 PM
Thank you Jakov. I'm not too familiar with the uses of ganiscripts but this will for sure help! :)