Quote:
Originally Posted by i8bit
Think you could give me an example/scenario?
|
The simple solution is just take Starfire's code and modify it to send a trigger...
PHP Code:
//#CLIENTSIDE
function onCreated() {
setImg("block.png");
onTimeout(); // probably better than setting a timer here as you might not want to wait a second before checking
}
function onTimeout() {
// assuming that your block's dimensions are 2x2
if (player.x in |this.x, this.x + 2| && player.y in |this.y, this.y + 2|) {
triggerServer("npc", "HealthSystem", "hitByBlock");
return setTimer(1); // to avoid sending 20 triggers per second
}
setTimer(.05); // or higher if it doesn't need to be so accurate
}
and then in a DB NPC HealthSystem...
PHP Code:
function onActionServerSide(temp.cmd) {
if (temp.cmd == "hitByBlock") {
echo(player.niceName() @ " was hit by a block.");
player.hit(1); // or whatever
}
}
You could also send a point trigger (but those can be unreliable) or do this a bunch of other ways. There are some neat tricks you can use to do this more efficiently but I'd need to know more about what you're trying to do to know if they'd work here.
Note that the above makes it possible for cheating players to not be hit by the block, so if you care about that, you should do everything serverside.