var name = 'streltsy' function run(creep) { const target = creep.pos.findClosestByRange(FIND_HOSTILE_CREEPS); if(target) { if(creep.rangedAttack(target) == ERR_NOT_IN_RANGE) { creep.moveTo(target); } } else { var currentWaypoint = Game.flags[creep.memory.waypoints[creep.memory.currentWaypoint]]; if(creep.pos.getRangeTo(currentWaypoint) > 0){ creep.moveTo(currentWaypoint); } else{ creep.memory.currentWaypoint += 1; if(creep.memory.currentWaypoint > creep.memory.waypoints.length){ creep.memory.currentWaypoint = 0; } } } } function spawn(spawnPoint, newWaypoints){ var newBody = spawnPoint.room.memory.creepBodies[name]; if(typeof newWaypoints === 'undefined') newWaypoints = ['A','B']; spawnPoint.spawnCreep(newBody, this.name + spawnPoint.room.name + "-" + Game.time, {memory : {role : this.name, waypoints : newWaypoints, currentWaypoint : 0} }); } module.exports = {name,run,spawn};