how to make turrets target NPC invaders
-
I have the basic code for the turret straight from the documentation with some modifications but it doesn't seem to target the NPC invaders for some reason, btw the code isn't recognizing the NPC invaders in the testing environment, its not returning an error but it just flashes red (which if I remember correctly indicates it works but It cant do anything).
var hostiles = Game.rooms[roomName].find(FIND_HOSTILE_CREEPS); if(hostiles.length > 0) { var username = hostiles[0].owner.username; game.notify('HOSTILE UNIT SPOTTED BY TOWER IN ROOM ' + roomName); var towers = game.rooms[roomName].find(FIND_MY_STRUCTURES, {filter: {structureType: STRUCTURE_TOWER}}); towers.forEach(tower => tower.attack(hostiles[0])); }
any solutions?