Will this work with multiple players? (My cleanest script yet yay)

I’m wondering what else I need so this works with multiple players in the level, and why?

[CODE]if(playerenters){
dontblock;
setimgpart baddy_bird01.png,96,0,48,32;
this.originx = 33;
this.originy = 24;
this.speed = .5;
timereverywhere;
timeout = .05;
}

if(timeout){
if(this.dead=0){
//direction to look at
if(this.goingback==0){
this.dx = playerx-x;
this.dy = playery-y;
this.dir = getdir(this.dx,this.dy);
}
if(this.goingback==1){
this.dx = this.originx-x;
this.dy = this.originy-y;
this.dir = getdir(this.dx,this.dy);
}

//movement
checkifplayernearby();
if(this.attacking == 0&&this.goingback == 0){
  lookatplayer();
}
if(this.attacking == 1){
  fly();
  attackplayer();
}
if(this.attacking == 0 && this.goingback==1){
  fly();
  goback();
}
hurtplayer();

}
else{
this.c++;
if(this.c==20)destroy;
}
timeout = .05;
}

if(hitbyboomerang){
this.dead = 1;
setcharani baddy_dead_01,;
}

function lookatplayer(){
if(this.dir==0) setimgpart baddy_bird01.png,0,0,48,32;
if(this.dir==1) setimgpart baddy_bird01.png,48,0,48,32;
if(this.dir==2) setimgpart baddy_bird01.png,96,0,48,32;
if(this.dir==3) setimgpart baddy_bird01.png,144,0,48,32;
}

function checkifplayernearby(){
if(playerx in |this.originx-5,this.originx+5|
&&playery in |this.originy-4,this.originy+12|){this.attacking = 1; this.goingback=0;}
else if(this.attacking==1) {this.attacking = 0; this.goingback=1;}
}

function fly(){
this.i++;
if(this.dir==0){
if(this.i%6==0) setimgpart baddy_bird01.png,0,32,48,32;
if(this.i%6==2) setimgpart baddy_bird01.png,0,64,48,32;
if(this.i%6==4) setimgpart baddy_bird01.png,0,96,48,32;
}
if(this.dir==1){
if(this.i%6==0) setimgpart baddy_bird01.png,48,32,48,32;
if(this.i%6==2) setimgpart baddy_bird01.png,48,64,48,32;
if(this.i%6==4) setimgpart baddy_bird01.png,48,96,48,32;
}
if(this.dir==2){
if(this.i%6==0) setimgpart baddy_bird01.png,96,32,48,32;
if(this.i%6==2) setimgpart baddy_bird01.png,96,64,48,32;
if(this.i%6==4) setimgpart baddy_bird01.png,96,96,48,32;
}
if(this.dir==3){
if(this.i%6==0) setimgpart baddy_bird01.png,144,32,48,32;
if(this.i%6==2) setimgpart baddy_bird01.png,144,64,48,32;
if(this.i%6==4) setimgpart baddy_bird01.png,144,96,48,32;
}
}

function attackplayer(){
if(this.takeback==0){
this.dist=(this.dx^2+this.dy^2)^.5;
if(this.dist>1){
x += (this.dx/this.dist)*this.speed;
y += (this.dy/this.dist)*this.speed;
}
else this.takeback = 1;
}
//so the bird backs up before attacking again
if(this.takeback==1&&this.b%7<=5){
this.dx = this.originx-x;
this.dy = this.originy-y;
goback();
this.b++;
}
else{this.takeback=0; this.b=0}
}

function hurtplayer(){
for (this.x=1;this.x<=2;this.x+=.5){
for (this.y=1;this.y<=2;this.y+=.5){
hitplayer testplayer(x+this.x,y+this.y),1,x,y;
}
}
}

function goback(){
this.dist=(this.dx^2+this.dy^2)^.5;
if(this.dist>1){
x += (this.dx/this.dist)*this.speed;
y += (this.dy/this.dist)*this.speed;
}
else this.goingback = 0;
}[/CODE]

Players are given certain IDs and the level leader has the lowest level ID. When you use playerx and playery, that means it’s going to go for the leader of the level.

players[ index ].x a player's horizontal position players[ index ].y a player's vertical position

I believe properly using this would fix your issue, though I don’t have much experience with it myself.

Yer this is only going to attack the player who’s running the script by the looks of it.

You can use this function to find the closest player if you like.

function findPlayer(){
  this.targetPlayer = {0,99};//players ID, distance to player
  for (this.pl = 0; this.pl < playerscount; this.pl++){
    this.newDist = ((x-players[this.pl].x)^2+(y-players[this.pl].y)^2)^0.5;
    if (this.newDist < this.targetPlayer[1])
      this.targetPlayer = {this.pl,this.newDist};
  }
}

Do I need to use ganis so everyone sees the anim?

You don’t need to use them but they’re ideal since they run clientside so there would be close to no lag. If you use the current method you have,it’ll work but I wouldn’t recommend it and it’d lag alot.