Skip to content

Instantly share code, notes, and snippets.

@2tunnels
Created March 9, 2018 15:25
Show Gist options
  • Save 2tunnels/5cd00f54a1a4597c8b5ad34ea9e295fa to your computer and use it in GitHub Desktop.
Save 2tunnels/5cd00f54a1a4597c8b5ad34ea9e295fa to your computer and use it in GitHub Desktop.
Screeps
// Spawn harvester
Game.spawns.Spawn_1.spawnCreep([WORK, CARRY, MOVE], `Harvester_${Game.time}`, {memory: {role: 'harvester'}});
// Loop has issues.
// If spawn is full, harvester will stop.
module.exports.loop = function () {
const creep1 = Game.creeps['Harvester{Game.time}'];
if (creep1.carry[RESOURCE_ENERGY] === creep1.carryCapacity) {
console.log(`${creep1.name} is full`);
const target = creep1.pos.findClosestByRange(FIND_MY_SPAWNS);
if(target) {
if(creep1.transfer(target, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep1.moveTo(target);
}
}
} else {
console.log(`${creep1.name} is not full`);
const target = creep1.pos.findClosestByRange(FIND_SOURCES_ACTIVE);
if(target) {
if(creep1.harvest(target) == ERR_NOT_IN_RANGE) {
creep1.moveTo(target);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment