I'm trying to script some sort of an event, and I'm having a little trouble. Basically, the point is not to get hit by the blocks randomly warping around the room. I've got that sorted. Now, I can't seem to get the NPC to detect if it's hit a player! Can somebody tell me what I'm doing wrong?
PHP Code:
function onCreated() {
setTimer(0.05);
setshape(1,32,32);
}
function onTimeout() {
if (this.on == 1) {
this.timer -= 1; // Start the count down
this.x = random(3.5,57.5);
this.y = random(18,46);
if (player.x in | this.x, this.x + this.width | && player.y in | this.y, this.y + this.height|) {
player.chat = "I've been hit!";
}
}
if (this.timer == 0) {
this.on = 0; // Stop warping
}
setTimer(0.05);
}
Edit
I think I've found my issue. It can't detect the players x and y co-ords server side? It worked when I created a new NPC and made it clientside. If I do this to my NPC, players won't be able to see the same X and Y of the block that other players see, and that's what I'm trying to do. Anybody got any ideas?
Just wondering if I could use a triggeraction to get around this. Would it be possible to send a triggeraction from the serverside to the clientside?
Edit
I've managed to put the movement and whatever clientside, and trigger the movement via the serverside using triggeraction. Now, I need help again trying to make the NPC detect if a player is in it's x and y.
PHP Code:
/*
Timer is the amount of time it takes
to warp around the room. The higher the
timer, the longer the warp session is.
*/
function onPlayerChats() {
if (player.guild != "Events Team") {
return;
}
if (player.chat == ":warp") {
triggeraction(31,33,"start",NULL);
}
}
function onActionhit() {
player.chat = "HAS BEEN HIT!";
}
//#CLIENTSIDE
const TIMER = 25;
function onCreated() {
setTimer(0.05);
setshape(1,32,32);
this.height = this.width = 32;
}
function onTimeout() {
this.chat = "Status:" SPC this.on;
if (this.on == 1) {
this.timer -= 1;
this.x = random(3.5,57.5);
this.y = random(18,46);
if (player.x in | this.x, this.x + this.width | && player.y in | this.y, this.y + this.height|) {
triggeraction(player.x, player.y, "hit", NULL);
}
}
if (this.timer == 0) {
this.on = 0;
this.x = 31;
this.y = 33;
}
setTimer(0.05);
}
function onActionstart() {
this.on = 1;
this.timer = TIMER;
}