Quote:
Originally Posted by i8bit
Can you give me an example of using the move() function?
|
using scripthelp:
TServerNPC.move(float, float, float, int) - moves the npc smoothly, parameters are delta x, delta y, time and options: cache type (0, 1-cache, 2-append) + blockcheck(4) + eventwhendone(8) + applydir(16)
example:
PHP Code:
function onCreated() {
this.image = "block.png";
this.x = this.y = 30;
echo("Starting to move...");
//Move NPC by 2 tiles in the x, 2 tiles in the y within 0.5 secs
//While the last parameter is 8 (check description above script example)
//The event 'onMovementFinished()' will be called
move(2, 2, 0.5, 8);
}
function onMovementFinished() {
echo("Done moving!");
}
With some maths you can tweak around the delta x/y and have it move around the player easy.
Ps: This move example replaced something like this which does lag more on the server
PHP Code:
function onCreated() {
this.image = "block.png";
this.x = this.y = 30;
echo("Starting to move...");
temp.time = (0.05/0.5); //steps divided by the time it should take
for (temp.i=0;temp.i<2;temp.i+=temp.time) {
this.x += temp.time;
this.y += temp.time;
}
echo("Done moving!");
}