Screeps: World

Screeps: World

Not enough ratings
API's handbook
By lethern
   
Award
Favorite
Favorited
Unfavorite
If your creep needs to find...
Handy notes starts here~ Based on http://support.screeps.com/hc/en-us/articles/203084991-API-Reference

(can be accessed as creep.pos, or any other RoomPosition. Documentation[support.screeps.com])

creep.pos.findClosestByRange(type, options)
-- returns one object, type is FIND_xx, for example:
target = creep.pos.findClosestByRange(FIND_MY_SPAWNS);

creep.pos.findClosestByPath(type, options)
-- as above, but more CPU costly (searches by real path, not distance)

creep.pos.findInRange(type, range, options)
-- array, type is FIND_xx. Searches in square. All 8 adjacent tiles to creep are in range 1

creep.pos.lookFor(type)
-- array of objects that are at same position as creep. Type is LOOK_xx, for example LOOK_CONSTRUCTION_SITES


(can be accessed as creep.room, or any other Room. Documentation[support.screeps.com])

creep.room.find(type, options)
-- array, type is FIND_xx, for example FIND_DROPPED_RESOURCES. Options can have filter - as a function or object, like
creep.room.find(FIND_MY_STRUCTURES, { filter: { structureType: STRUCTURE_EXTENSION } }); creep.room.find(FIND_MY_STRUCTURES, { filter: (s) => s.structureType==STRUCTURE_EXTENSION });

creep.room.lookForAt(type, x, y)
-- array, type is LOOK_xx, for example
creep.room.lookForAt(LOOK_CREEPS, 10, 10 )
If you need info regarding creep..
Creep's properties:
creep. name -- obvious
creep.body -- array, like [WORK, WORK, ...]
creep.carry -- object with amount of all carried resources, like
creep.carry.energy creep.carry[RESOURCE_ZYNTHIUM]
creep.carryCapacity -- maximum amount of all resources able to carry
creep.hits, creep.hitsMax -- current / max hit points
creep.room.x, creep.room.y, creep.room.roomName -- position properties: x, y, room

If you need info about room...
Info of room:
(can be accessed as creep.room or Room object)
creep.room.energyAvailable -- how much energy available to spawn creep
creep.room. name -- name, like 'E1N1'.
creep.room.storage -- room's StructureStorage, if built


Global objects:
Game.constructionSites -- object (map), key is id, value is construction site
Game.creeps -- object (map), key is name, value is Creep. Usage for example
Game.creeps['Vincent']
Game.flags -- object (map), key is name, value is Flag. Usage:
Game.flags.MyFlag1 or Game.flags['MyFlag1']
Game.rooms -- object (map), rooms available to you (rooms which contains your creep), key is roomName. Usage: Game.rooms['E1N1']
Game.time -- tick counter
Creep's actions
creep.attack(target) -- attacks target (each ATTACK part does 30dmg in one tick)
creep.build(target) -- builds a Construction Site
creep.claimController(target) -- tries to take ownage of target neutral controller. You can get controller as creep.room.controller
creep.harvest(target) -- harvests Source for energy (or Mineral for other resources)
creep.repair(target) -- repairs a structure (each WORK part repairs a structure for 100 hits in one tick which costs 1 energy)
creep.transfer(target, RESOURCE_xxx, amount) -- transfer specific amount of resource, like RESOURCE_ENERGY. Careful, we can't transfer more than target has storage
creep.upgradeController(target) -- transfers energy into controller


Moving
creep.moveTo(target) -- moves one step to target Object, position, or moveTo(x,y). By default engine caches path for 5 steps, before recalculating it
Additional
creep.spawning -- when Creep is not yet alive, this will be true
creep.ticksToLive -- how many ticks till creep dies
creep.room.controller -- the room's Controller

creep.pos.getRangeTo(target) -- returns linear range to something. can be getRangeTo(x,y)

Game.getObjectById(id) -- returns object by its ID (you will use it when storing something in Memory - you can't store Object, but you can store id). ID is also visible in the GUI


Other actions
creep.say(string) -- displays short message on top of creep for you (max 10 characters)
creep.pickup(target) -- picks up dropped energy, example:
var targets = creep.pos.findInRange(FIND_DROPPED_ENERGY, 1); if(targets.length) { var result = creep.pickup(targets[0]); if( result==OK ) creep.say('Gotcha'); }


Notes
-construction site's id is different from the completed building's later on
-using FIND_MY_STRUCTURES you will not get walls, roads, containers
CONSTANTS
Result of action:
OK: 0 ERR_NOT_OWNER: -1 ERR_NO_PATH: -2 ERR_NAME_EXISTS: -3 ERR_BUSY: -4 ERR_NOT_FOUND: -5 ERR_NOT_ENOUGH_ENERGY / RESOURCES / EXTENSIONS: -6 ERR_INVALID_TARGET: -7 ERR_FULL: -8 ERR_NOT_IN_RANGE: -9 ERR_INVALID_ARGS: -10 ERR_TIRED: -11 ERR_NO_BODYPART: -12 ERR_RCL_NOT_ENOUGH: -14 ERR_GCL_NOT_ENOUGH: -15


Searching - FIND_xx (not all listed):
FIND_CREEPS FIND_MY_CREEPS FIND_HOSTILE_CREEPS FIND_SOURCES FIND_DROPPED_ENERGY FIND_DROPPED_RESOURCES FIND_STRUCTURES FIND_MY_STRUCTURES FIND_HOSTILE_STRUCTURES FIND_FLAGS FIND_CONSTRUCTION_SITES FIND_MY_SPAWNS FIND_HOSTILE_SPAWNS FIND_MY_CONSTRUCTION_SITES FIND_MINERALS


Searching - LOOK_xx (not all listed)
LOOK_CREEPS LOOK_ENERGY LOOK_RESOURCES LOOK_SOURCES LOOK_MINERALS: LOOK_STRUCTURES LOOK_FLAGS LOOK_CONSTRUCTION_SITES LOOK_TERRAIN


structureType (not all listed)
STRUCTURE_SPAWN STRUCTURE_EXTENSION STRUCTURE_ROAD STRUCTURE_WALL STRUCTURE_RAMPART STRUCTURE_CONTROLLER STRUCTURE_LINK STRUCTURE_STORAGE STRUCTURE_TOWER STRUCTURE_EXTRACTOR STRUCTURE_LAB STRUCTURE_TERMINAL STRUCTURE_CONTAINER
1 Comments
Elaxe™ 12 Jul, 2016 @ 9:58am 
Thanks for this. help me a lot :balloonicorn: