I have a custom baddy script which I've written (It's still in progress so it just uses chat commands to test it's functionality so far) and I'm having some trouble with a certain command.
PHP Code:
function onCreated() {
this.isBaddy = true;
this.maxHealth = 100;
this.atkdmg = 1;
setImg("Block.png");
this.chat = "Rawr I'm a baddy!";
onTimeout();
}
function onPlayerChats() {
temp.movex = player.x + .5 + vecx(player.dir) * 2;
temp.movey = player.y + .5 + vecy(player.dir) * 2;
if ( player.chat == "destroybaddy" ) destroy();
elseif ( player.chat == "remove target" ) this.target = NULL;
elseif ( player.chat.tokenize()[0] == "target" ) {
this.target = player.chat.tokenize()[1];
this.chat = "Targeting: "@ this.target;
}
}
function onTimeout() {
this.attack = ( this.attack + 1 ) # 40;
if ( this.target != NULL ) {
temp.a = findPlayer(this.target);
temp.movex = temp.a.x + .5 + vecx(temp.a.dir) * 2;
temp.movey = temp.a.y + .5 + vecy(temp.a.dir) * 2;
if ( !(this.x in |temp.movex-.5,temp.movex+.5|) || !(this.y in |temp.movey-.5,temp.movey+.5|) ) {
this.last = temp.test;
this.newmove = !this.newmove;
MoveTo( temp.movex,temp.movey );
}
else if ( this.attack == 10 ) Attack();
}
if ( playerscount < 1 ) setTimer(0);
else setTimer(.05);
}
//Move one space closer to newx,newy
function MoveTo( newx,newy ) {
temp.angle = getangle((newx - this.x),(newy - this.y));
this.xvel = cos(temp.angle);
this.yvel = sin(temp.angle);
this.x += this.xvel;
this.y -= this.yvel;
this.dir = getDir( this.x , this.y );
this.chat = "My dir is " @ this.dir;
}
//Testing removal of HP
function Attack() findPlayer( this.target ).clientr.myhealthstat -= this.atkdmg;
Everything runs just fine except for this:
PHP Code:
this.dir = getDir( newx - this.x , newy - this.y );
this.chat = "My dir is " @ this.dir;
This is always returning zero. I need to find the direction which the baddy is facing depending on where it moves so I can apply the proper direction for the setcharani animations for the baddy.
Anyone know what I may be doing wrong?
Also, this is my first custom baddy script. Any other CONSTRUCTIVE criticism or suggesstions for any other part of this script is obviously welcome.