I know some members may dislike me, but for those who don't continue reading

Anyway I am scripting a Baddy and am wondering how I could make it swing its sword at players when it's movement is done via a timeout.
Maybe increase an index variable and if it starts with lets say 2 for instance or an even number it would swing it's sword.
Here is what I have so far.
PHP Code:
function onCreated() {
this.attackzone = 10; //Tiles before it attacks
this.speed = 0.5; //Speed in tiles
this.lastplayer = null;
CreateCharacter(); //Creates the character
this.orx = this.x;
this.ory = this.y;
this.sayings = {
"It's time to die ",
"The time has come ",
"It's you're turn ",
"I will get you ",
"I won't miss this time ",
"You will die ",
"My sword never misses "
};
onTimeout();
}
function onTimeout() {
for (temp.pl: players) {
if (pl.x in | this.x + 1 - this.attackzone, this.x + 1 + this.attackzone | && pl.y in | this.y + 1 - this.attackzone, this.y + 1 + this.attackzone | ) {
if (this.lastplayer == null) {
this.lastplayer = pl;
this.saying = randomstring(this.sayings)@pl.nick.substring(0, pl.nick.pos("(").trim());
}
if (this.x < pl.x) {
this.x += this.speed;
this.ani = "walk";
}
if (this.x > pl.x) {
this.x -= this.speed;
this.ani = "walk";
}
if (this.y < pl.y) {
this.y += this.speed;
this.ani = "walk";
}
if (this.y > pl.y) {
this.y -= this.speed;
this.ani = "walk";
}
this.chat = this.saying;
this.dir = getdir(pl.x - this.x, pl.y - this.y);
} else {
if (pl == this.lastplayer) {
this.lastplayer = null;
}
}
}
if (this.lastplayer == null) {
this.ani = "idle";
if (this.x > this.orx) {
this.x -= this.speed;
this.ani = "walk";
}
if (this.x < this.orx) {
this.x += this.speed;
this.ani = "walk";
}
if (this.y > this.ory) {
this.y -= this.speed;
this.ani = "walk";
}
if (this.y < this.ory) {
this.y += this.speed;
this.ani = "walk";
}
this.chat = "";
this.dir = getdir(this.orx - this.x, this.ory - this.y);
}
settimer(0.05);
}
function CreateCharacter() {
showcharacter();
this.head = "head25.png";
this.nick = "Baddy";
this.ap = 25;
this.colors[0] = "orange"; //hands
this.colors[1] = "red"; //body
this.colors[2] = "blue"; //sleeves
this.colors[3] = "white"; //shoes
this.colors[4] = "blue"; //belt
}