task root(x,y,v,dir,graphic,delay){
let obj = Obj_Create(OBJ_SHOT);
Obj_SetPosition(obj,x,y);
Obj_SetSpeed(obj,v);
Obj_SetAngle(obj,dir);
ObjShot_SetGraphic(obj,graphic);
ObjShot_SetDelay(obj,delay);
ObjShot_SetBombResist(obj,false);
//"while the bullet is not deleted, do the following"
while(!Obj_BeDeleted(obj)){
if(((Obj_GetX(obj)-GetEnemyX)^2+(Obj_GetY(obj)-GetEnemyY)^2)^0.5>rand_int(60,120)){
ObjShot_FadeDelete(obj);
}
//this is going to make the bullet's almost completely random, which you probably don't want to do.
Obj_SetAngle(obj,Obj_GetAngle(obj)+rand_int(-35,35));
//this is going to create bullets every frame, I dont think you want to do that either.
CreateShotA(1,Obj_GetX(obj),Obj_GetY(obj),20);
SetShotDataA(1,0,0.08,rand_int(0,359),0,0,0.04,GREEN05);
SetShotKillTime(1,240);
FireShot(1);
//If you want the angle changing and bullet spawning to happen every thirteen frames (Wait(12) + yield, like you had before), you could say "if(frame%13==0){ SpawnBulletChangeAngle; }" inside this while loop, and say frame++; at the beginning of the loop. This way, everything you've put inside there will occur every thirteen frames. Obviously, declare the variable "frame".
//Since while statements will repeat during the one frame, we'll need to yield to postpone the check till the next frame.
yield;
}
//So this is outside of the while loop, meaning after the bullet is deleted, since the loop will only occur if the bullet isn't alive. Insert whatever you want to happen upon death here.
dostuff;
}