View Single Post
  #20  
Old 11-09-2006, 11:47 PM
kinetaro kinetaro is offline
Hiding under your bed.
kinetaro's Avatar
Join Date: Jun 2006
Posts: 30
kinetaro is on a distinguished road
Send a message via AIM to kinetaro Send a message via MSN to kinetaro
here is a very basic script for clientside NPC movement.
NPC Code:

//#CLIENTSIDE
function onCreated()
{
showcharacter();
headimg = "head.png";
bodyimg = "body.png";
swordimg = "sword1.png";
shieldimg = "shield1.png";
this.speed = 0.5;
setTimer(0.1);
}
function onTimeout()
{
setcharani("walk", NULL);
for(pl: players) {
this.dir = getdir(pl.x - this.x, pl.y - this.y);
this.angle = getangle(pl.x - this.x, pl.y - this.y);
this.x = this.x + (cos(this.angle) * this.speed);
this.y = this.y - (sin(this.angle) * this.speed);
}
setTimer(0.05);
}


and to make it serverside its basically the same exact thing.
NPC Code:

function onCreated()
{
showcharacter();
headimg = "head.png";
bodyimg = "body.png";
swordimg = "sword1.png";
shieldimg = "shield1.png";
this.speed = 0.5;
setTimer(0.1);
}
function onTimeout()
{
setcharani("walk", NULL);
for(pl: players) {
this.dir = getdir(pl.x - this.x, pl.y - this.y);
this.angle = getangle(pl.x - this.x, pl.y - this.y);
x = this.x + (cos(this.angle) * this.speed);
y = this.y - (sin(this.angle) * this.speed);
}
setTimer(0.05);
}

Reply With Quote