The respawn thing is pretty easy although I've drawn a blank and can't find the code I used at the moment. but it uses func PlayerRespawn
Random flies are simple enough.
I had this in the AI file
func AIRandomFly( idx,pixx,pixy )
{
if(idx==-1) return;
if(ObjGet(idx,O_DISABLE)) return;
if(!IsUpdate(ObjGet(idx,O_DELAY))) return;
if(ObjGet(idx,O_STATUS)!=1) return;
id2 = ObjGet(idx,O_TARGET);
if(id2==0) return;
idx2 = ObjFind(id2);
if(idx2==-1) return;
speed = ObjGet(idx2,O_WAYPOINTSPEED);
targx = ObjGet(idx2,O_ X) ;
targy = ObjGet(idx2,O_Y);
flyx = ObjGet(idx,O_ X) ;
flyy = ObjGet(idx,O_Y);
if(flyy<=targy+pixy && flyy>=targy-pixy && flyx<=targx+pixx && flyx>=targx-pixx)
{
flyrand=gs_rand(4);
if(flyrand==0) {flyy-=speed; if(flyy<targy-pixy) flyy=targy-pixy; }
if(flyrand==1) {flyy+=speed; if(flyy>targy+pixy) flyy=targy+pixy; }
if(flyrand==2) {flyx-=speed; if(flyx<targx-pixx) flyx=targx-pixx; }
if(flyrand==3) {flyx+=speed; if(flyx>targx+pixx) flyx=targx+pixx; }
}
ObjSet(idx,O_X,flyx);
ObjSet(idx,O_Y,flyy);
}
func AIUpdateFlyY( idx,pix )
{
if(idx==-1) return;
if(ObjGet(idx,O_DISABLE)) return;
if(!IsUpdate(ObjGet(idx,O_DELAY))) return;
if(ObjGet(idx,O_STATUS)!=1) return;
id2 = ObjGet(idx,O_TARGET);
if(id2==0) return;
idx2 = ObjFind(id2);
if(idx2==-1) return;
speed = ObjGet(idx2,O_WAYPOINTSPEED);
flip = ObjGet(idx2,O_WAYPOINTFLIP);
targx = ObjGet(idx2,O_ X) ;
targy = ObjGet(idx2,O_Y);
flyx = ObjGet(idx,O_ X) ;
flyy = ObjGet(idx,O_Y);
ObjSet(idx,O_FLIP,flip);
if(flyy<targy) { flyy+=speed; if(flyy>targy) flyy=targy; }
if(flyy>targy) { flyy-=speed; if(flyy<targy) flyy=targy; }
if(flyx<=targx+pix && flyx>=targx-pix)
{
flyrand=gs_rand(2);
if(flyrand==0) {flyx-=2; if(flyx<targx-pix) flyx=targx-pix; }
if(flyrand==1) {flyx+=2; if(flyx>targx+pix) flyx=targx+pix; }
}
if(flyy==targy) // reached waypoint, change target
{
target = ObjGet(idx2,O_TARGET);
ObjSet(idx,O_TARGET,target);
}
ObjSet(idx,O_X,flyx);
ObjSet(idx,O_Y,flyy);
}
func AIUpdateFlyX( idx,pix )
{
if(idx==-1) return;
if(ObjGet(idx,O_DISABLE)) return;
if(!IsUpdate(ObjGet(idx,O_DELAY))) return;
if(ObjGet(idx,O_STATUS)!=1) return;
id2 = ObjGet(idx,O_TARGET);
if(id2==0) return;
idx2 = ObjFind(id2);
if(idx2==-1) return;
speed = ObjGet(idx2,O_WAYPOINTSPEED);
flip = ObjGet(idx2,O_WAYPOINTFLIP);
targx = ObjGet(idx2,O_ X) ;
targy = ObjGet(idx2,O_Y);
flyx = ObjGet(idx,O_ X) ;
flyy = ObjGet(idx,O_Y);
ObjSet(idx,O_FLIP,flip);
if(flyx<targx) { flyx+=speed; if(flyx>targx) flyx=targx; }
if(flyx>targx) { flyx-=speed; if(flyx<targx) flyx=targx; }
if(flyy<=targy+pix && flyy>=targy-pix)
{
flyrand=gs_rand(2);
if(flyrand==0) {flyy-=2; if(flyy<targy-pix) flyy=targy-pix; }
if(flyrand==1) {flyy+=2; if(flyy>targy+pix) flyy=targy+pix; }
}
if(flyx==targx) // reached waypoint, change target
{
target = ObjGet(idx2,O_TARGET);
ObjSet(idx,O_TARGET,target);
}
ObjSet(idx,O_X,flyx);
ObjSet(idx,O_Y,flyy);
Then update the room for the fly, obviously with the individual ID and you can change those coridinates.
func UpdateRoom_*_*() AIRandomFly(ObjFind(***),90,150);
In the map editor you'll need to place an invisible wavepoint, and each fly added must be targeted for that wavepoint, with their own ID any stuff, and I think they must be placed on the map in contact with it's wavepoint as a starting point, that's how I got it to work.. they will fly around the room. changing the coordinates will alter how far from the wavepoint they can travel. something like that.
Pretty simple, I hope I've explained it easily enough.. you can then have as many wavepoint and flies in as many rooms as you want.