well im not good at explaining but here:
NPC Code:
function onCreated(){
this.cur_target=-1; // reset current target
this.walkgani="hex-metalspider-walk"; // set the walk
this.idlegani="hex-metalspider-idle"; //idle
this.hitgani="hex-metalspider-attack"; //and hit gani
showcharacter(); //well lol
setCharAni(this.idlegani,""); // set the current gani to the idlegani
setTimer(0.05); // start the timeout
}
function onTimeout(){
//chat=playerscount;
if(playerscount>0){ //when there still are players in the room
if(this.cur_target==-1){ //if no target is set
this.pindexes=getnearestplayers(x,y); // get the indexes of the players
thiso.newdistance=10; // set the newdistance to 10 so everything under a distance of 10 gets targeted
thiso.newtarget=-1; // set the new target to -1
thiso.baddy_x=x; // store baddy
thiso.baddy_y=y; // & y
for(i: this.pindexes){ // loop through the indexes
with(players[i]){ //get the player
this.ddb_dx=player.x-thiso.baddy_x; //calculate dx
this.ddb_dy=player.y-thiso.baddy_y; // & dy
this.dist=(this.ddb_dx*this.ddb_dx+this.ddb_dy*thi s.ddb_dy)^.5; //calculate distance
if(this.dist<thiso.newdistance){ //when the distance is smaller than the newdistance
thiso.newtarget=player.account; //set new target to the players account
thiso.newdistance=this.dist; //set newdistance to the current distance(to target the players, whos nearest at the baddie)
player.chat="targeted"; //debug help
}
}
}
chat=thiso.newtarget; // tel the newtarget
if(thiso.newtarget!=-1)this.cur_target=thiso.newtarget; //when newtarget is not -1 then set current target to the newtarget
chat=this.cur_target; // tell the current target
}else{
this.tmp_plr=findplayer(this.target); //get targeted player
if(this.tmp_plr.level==level){ // if player is in baddie level
//to be done later
}else{ // if not
this.cur_target=-1; //reset target
this.tmp_plr=null; // delete the temp player object
}
}
setTimer(0.05); // start timeout again
}
}
function onPlayerEnters(){
setTimer(0.05); (restart the timeout if an player enters)
}
function onPlayerChats(){
if(player.chat="/dbb")
destroy(); //to destroy them (only temp until its finished)
}
//#CLIENTSIDE
function onCreated(){
// chat="test";
}