Thanks, that helped a lot.
Moves a lot smoother now, although I still can't find a way to hit him x_X
full script below.
PHP Code:
// NPC Enemy made by Excalibur
//Ceverous, first fight
//#CLIENTSIDE
function onPlayerenters()
{
// Character attributes
showcharacter();
headimg = "darkdemon13-head4.mng";
colors[0] = "orange";
colors[1] = "gray";
colors[2] = "gray";
colors[3] = "black";
colors[4] = "black";
nick = "?????";
shieldimg = "darkman-shield.gif";
bodyimg = "bodysage2.mng";
swordimg = "dronan-sword.gif";
shieldpower = 1;
swordpower = 2;
hearts = 5;
dir = 2;
setcharani("idle",NULL);
//position
x+=.5;
//sight radius
this.sightradius = 10;
//speed
this.speed = .5;
//cut scene
setani("idle",NULL);
freezeplayer(3);
player.chat = "It's been YOU!";
sleep(.1);
chat = "Ha ha ha! Welcome to the party!";
//timeout
setTimer(.05);
}
function onTimeout()
{
function onWa****()
{
this.mode = 2;
this.damage = player.swordpower/2;
}
function onWasShot()
{
this.mode = 2;
this.damage = clientr.bowpower/2;
}
function onExploded()
{
this.mode = 2;
this.damage = clientr.bombpower/2;
}
function onWaspelt()
{
setcharani("sword",NULL);
this.mode = 2;
this.damage=0;
}
if(this.mode = 0)
{
setcharani("idle",NULL);
setTimer(.05);
}
/*Modes
*0)Idle
*1)Chasing/attacking
*2)Hurt
*3)Dead
**********/
if(hearts<=0)
{
hearts = 0;
this.mode = 3;
}
if((abs(player.x-x)^2+abs(player.y-y)^2)^.5<=this.sightradius)
{
this.mode = 1;
}
if(this.mode==1)
{
setcharani("walk",NULL);
//set movement w/ trig
if(player.x>x && abs(player.x-x)>1)
{
this.modx = 1;
}
else if(player.x<x && abs(player.x-x)>1)
{
this.modx = -1;
}
else
{
this.modx = 0;
}
if(player.y>y && abs(player.y-y)>1)
{
this.mody = 1;
}
else if(player.y<y && abs(player.y-y)>1)
{
this.mody = -1;
}
else
{
this.mody = 0;
}
//My wall check
if(onwall(x,y) || onwall(x,y+3) || onwall(x+1,y) || onwall(x+1,y+3) || onwall(x+2,y) || onwall(x+2,y+3) || onwall(x,y) || onwall(x,y+1.5) || onwall(x+1,y) || onwall(x+1,y+1.5) || onwall(x+2,y) || onwall(x+2,y+1.5))
{
if(this.scount==0)
{
shootball();
}
else
{
if(this.scount<=5)
{
this.scount = 0;
}
}
this.scount++;
move(this.speed*this.modx*.3,this.speed*this.mody*.3,1,4+8+16);
}
else
{
move(this.speed*this.modx,this.speed*this.mody,1,4+8+16);
}
if((abs(player.x-x)^2+abs(player.y-y)^2)^.5<=3)
{
if(this.hit==1)
{
setcharani("sword",NULL);
this.hit = 0;
setTimer(.45);
}
else
{
this.hit = 1;
setTimer(random(.05,.3));
}
}
else
{
setTimer(.05);
}
}
if(this.mode==2)
{
hearts-=this.damage;
if(this.damage>0)
{
setcharani("hurt",NULL);
}
else
{
this.damage = 0;
}
if(player.x>x)
{
for(this.i = 0; this.i<3; this.i++)
{
if(!onwall(x-1,y+.5) && !onwall(x-1,y+2.5))
{
x-=1;
}
else
{
chat = "Ugh";
}
sleep(.05);
}
}
else if(player.x<x)
{
for(this.i = 0; this.i<3; this.i++)
{
if(!onwall(x+1,y+.5) && !onwall(x+1,y+2.5))
{
x+=1;
}
else
{
chat = "Ugh";
}
sleep(.05);
}
}
else if(player.y>y)
{
for(this.i = 0; this.i<3; this.i++)
{
if(!onwall(x,y+1) && !onwall(x+2,y+1))
{
y+=1;
}
else
{
chat = "Ugh";
}
sleep(.05);
}
}
else if(player.y>y)
{
for(this.i = 0; this.i<3; this.i++)
{
if(!onwall(x,y-1) && !onwall(x+2,y-1))
{
y-=1;
}
else
{
chat = "Ugh";
}
sleep(.05);
}
}
setTimer(.5);
this.mode = 1;
}
if(this.mode==3)
{
setcharani("dead",NULL);
chat = "This isn't over, " @ player.nick @ ", your gift's in the throne room!";
client.unlock = 1;
hearts = 5;
this.mode = 0;
setTimer(10);
}
}
function onWa****()
{
this.mode = 2;
this.damage = player.swordpower/2;
setTimer(.05);
}
function onWasShot()
{
this.mode = 2;
this.damage = clientr.bowpower/2;
setTimer(.05);
}
function onExploded()
{
this.mode = 2;
this.damage = clientr.bombpower/2;
setTimer(.05);
}
function onWaspelt()
{
setcharani("sword",NULL);
this.mode = 2;
this.damage=0;
setTimer(.05);
}
edit: made movement cleaner near walls