PDA

View Full Version : Editing a local NPC


Kirko
11-25-2015, 10:57 PM
How would I go the way of editing local npcs from a level. I had tried changing the layer of one in clientside but only changed for me and no one else.
I tried doing in serverside but the layer wouldn't change. I had the npcs chat change to the layer it was in and it was chatting correctly but the layer wouldn't actually change.

Elk
11-26-2015, 03:32 AM
open the level in texteditor and change it manually

Jakov_the_Jakovasaur
11-26-2015, 08:15 AM
hello!

this is probably a case of the 'layer' variable not synchronising from serverside to clientside, you could try either setting it via drawunderplayer()/drawoverplayer() or by triggering its change using npc.trigger('Event', params...);

Kirko
11-26-2015, 01:19 PM
So I got it to work some what. In class that the npc is joined to I have

function onLayerChange(){
this.trigger("Update");
//this.chat = "test1";//this worked
//this.layer = params[2];//can only be changed in clientside
this.triggeraction(this.x+.5,this.y+.5,"LayerChange2","");//doesnt work
}

//#CLIENTSIDE
function onPlayerEnters()
this.layer=this.attr[2]

//doesnt work
function onLayerChange2(){
this.trigger("Update");
this.chat = "test2";
onPlayerEnters();
}

the layer only changes when I update level or reenter level. I tried triggering "Update" for the npc in my weapon script and some other thnigs but no luck

cbk1994
11-26-2015, 03:38 PM
Unfortunately you can't trigger clientside like that (it would need to copy the trigger to every player in the level). The best way I remember solving these kind of issues is using a timeout to check an attr, sadly.

You could also hack it by triggering a weapon clientside on each player in the level, but that feels kind of bad too. You can't do point-triggers to clientside, though.

edit: nevermind, this entire post is wrong, see below

Tim_Rocks
11-26-2015, 04:08 PM
Chris' method of using attr w/ a timeout makes the most sense.

ffcmike
11-26-2015, 04:09 PM
You can't do point-triggers to clientside, though.

You can since V6, I have a lot of scripts which work as follows:



function onUpdate(temp.val) {
this.attr[4] = int(timevar2);
this.attr[5] = temp.val;
triggeraction(this.x + 1, this.y + 1, "Update", "");
}

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

function onPlayerEnters()
if (this.updatetTime != this.attr[4])
this.onActionUpdate();

function onActionUpdate() {
this.updatetTime = this.attr[4];
echo("New value is " @ this.attr[5]);
}



Looking at -



function onLayerChange(){
this.trigger("Update");
//this.chat = "test1";//this worked
//this.layer = params[2];//can only be changed in clientside
this.triggeraction(this.x+.5,this.y+.5,"LayerChange2","");//doesnt work
}



this.triggeraction() won't work as it is not an NPC function, but a level function. Change it to one of just triggeraction(), level.triggeraction() or this.level.triggeraction(). The NPC needs a Clientside setshape() in order to receive the triggeraction as well.

xXziroXx
11-26-2015, 04:12 PM
You can since V6

Confirmed. Stefan added it after popular demand.

cbk1994
11-26-2015, 06:16 PM
You can since V6

whoops, thanks for correcting me! clearly I'm a bit behind the times :p.

Kirko
11-26-2015, 07:29 PM
Got it to work!! thanks so much!!