You could do this from the players object.
Player object Step:
Code:
var nearestTurret = instance_nearest(x,y,oTurret); //Grab the nearest turret
var red = -1; //Is the nearest turret red? 0 for NO, 1 for YES
with(nearestTurret){ //With the nearest turret
playSounds = true; //Allow it to play sounds
if(turretType=="Red"){ //Check for it's type
red = 1; //Nearest turret is RED
}else{
red = 0; //Nearest turret is GREEN
}
}
var n; //We'll use this variable to iterate
if(red==1){ //Nearest turret was red, so look for green
for (n = 2; nearestTurret.TurretType=="Red"; n += 1){ //iterates till it finds
nearestTurret = instance_nth_nearest(x,y,obj,n); //nearest green turret
}
}else{ //Nearest turret was green, so look for red
for (n = 2; nearestTurret.TurretType=="Green"; n+=1){ //iterates till it finds
nearestTurret = instance_nth_nearest(x,y,obj,n); //nearest red turret
}
}
with(nearestTurret){ //With the nearest second type of turret
playSounds = true; //Allow it to play sounds
}
This will set the variable 'playSounds' to true for the nearest 'red' and the nearest 'green' turret.
It utilizes the nifty
instance_nth_nearest() script from gmlscripts.
It won't disable them once the player triggered them however!
You can put something like
playSounds == false; in the begin Step of oTurret to remedy this.
- Jeremy
EDIT: I read over the fact that you have 20 different turrets,
instead of just the red and green one from the example...
You should be able to modify the code using switch statements to achieve this,
I think you get the idea now.