Screeps Wiki
Advertisement

function (target) {

   if (!this.my) {
     return C.ERR_NOT_OWNER;
   }
   if (data(this.id).spawning) {
     return C.ERR_BUSY;
   }
   if (this.getActiveBodyparts(C.ATTACK) == 0) {
     return C.ERR_NO_BODYPART;
   }
   if (!target || !target.id || !register.creeps[target.id] && !register.structures[target.id] || !(target instanceof globals.Creep) && !(target instanceof globals.Spawn) && !(target instanceof globals.Structure)) {
     return C.ERR_INVALID_TARGET;
   }
   if (!target.pos.isNearTo(this.pos)) {
     return C.ERR_NOT_IN_RANGE;
   }
   intents[this.id] = intents[this.id] || {};
   intents[this.id].attack = {
     id: target.id,
     x: target.pos.x,
     y: target.pos.y
   };
   return C.OK;
 }

Advertisement