I'm making an NPC baddy again. This time, I am using the classic system, so it's a bit different. Anyway, I'm having trouble damaging it. So far, the only sure fire way to do it is to shoot him. I originally didn't put the wa****, wasshot, etc in the timeout, but I decided to try it to make it easier to hit him.
No luck.
Any ideas/suggestions? (other than taking the sleep() command out of when the baddy is hit, that wouldn't change this, and I do plan to take it out and replace it with a timeout once I have everything working right. I also plan to add some better AI).
PHP Code:
// NPC Enemy made by Excalibur
//Ceverous, first fight
//#CLIENTSIDE
function onCreated()
{
// Character attributes
showcharacter();
headimg = "darkdemon13-head4.mng";
colors[0] = "orange";
colors[1] = "gray";
colors[2] = "gray";
colors[3] = "black";
colors[0] = "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 = .6;
//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);
if(abs(player.x-x)>abs(player.y-y))
{
//direction should be 1 or 3
if(player.x>x)
{
dir = 3;
//move
if(!onwall(x+this.speed,y+.5) && !onwall(x+this.speed,y+2.5))
{
x+=this.speed;
}
}
else
{
dir = 1;
//move
if(!onwall(x-this.speed,y+.5) && !onwall(x-this.speed,y+2.5))
{
x-=this.speed;
}
}
}
else
{
//direction is 0 or 2
if(player.y>y)
{
dir = 2;
//move
if(!onwall(x,y+this.speed) && !onwall(x+2,y+this.speed))
{
y+=this.speed;
}
}
else
{
dir = 0;
//move
if(!onwall(x,y-this.speed) && !onwall(x+2,y-this.speed))
{
y-=this.speed;
}
}
}
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);
}