Here's a collection of commands to use server powers to do various things. Be careful when using them, I usually find and print an object's state before editing it, since it's very easy to get in a broken state by editing the database directly like that and having the previous values helps in reconstructing it if you mess up.
// Refresh every room's image assets
storage.db.rooms.find().then(rooms => Promise.all(rooms.map(({ _id }) => map.updateRoomImageAssets(_id))));
// Set bot auto spawn
bots.spawn("grey-company", "W5N8", { auto: true, username: "BlackCompany" });
// Reset market and recreate orders. Mostly useful when changing the static market configuration.
storage.db['market.orders'].clear();
system.runCronjob("recreateNpcOrders");
// Checking invader goals
storage.db["rooms"].findOne({ _id: "E25S6"}).then(o => print(o.invaderGoal));
storage.db["rooms.objects"].find({room: "E25S6", type: {$in: ['source']}}).then(rs => print(rs.reduce((sum, s) => sum += s.invaderHarvested, 0)));
// Make dem pop
storage.db["rooms"].update({ _id: "E25S6"}, { $set: { invaderGoal: 10000 } });
system.runCronjob("genInvaders");
// AFTER RESET UNFUCK
storage.db['rooms.objects'].update({type:"spawn"}, {$set: {storeCapacityResource:{energy:300}}});
storage.db['rooms.objects'].update({type:"extension"}, {$set: {storeCapacityResource:{energy:200}}}); // or 50/100 depending on RCL
storage.db['rooms.objects'].update({type:"link"}, {$set: {storeCapacityResource:{energy:800}}});
storage.db['rooms.objects'].update({type:"tower"}, {$set: {storeCapacityResource:{energy:1000}}});
// Force-disable rooms (use after a reset)
storage.db.rooms.update({ active: true }, { $set: { active: false } });
// Disable CPU processing for a user
storage.db.users.update({ username: 'Traxus' }, { $set: { active: 0 } });
/*
* Default active value is 10000. Some things, like the GCL-to-CPU mode in admin-utils, expect
* that value to perform the CPU update.
*/
// Undocumented env stuff
storage.env.smembers(storage.env.keys.ACTIVE_ROOMS);
Object.keys(storage.env);
// => keys,get,mget,sadd,smembers,set,setex,expire,ttl,del,hmget,hmset,hget,hset,hgetall,incr,flushall
// Read user
storage.db["users"].findOne({ username: "Traxus" }).then(print)
// Lotsa monies
storage.db["users"].update({ username: "Traxus"}, { $set: { money: 100000000000 } }).then(print);
storage.db["users"].update({ username: "Traxus"}, { $set: { power: 1000000 } }).then(print);
storage.db["users"].update({ username: "Traxus"}, { $set: { gcl: 50000000 } }).then(print);
// Lotsa energi
storage.db["rooms.objects"].update({_id: "659328d21967d906b8d02b5d" }, { $set: { "store.energy": 300000 } })
storage.db["rooms.objects"].update({_id: "659453f8d51fa5001c2dcc06" }, { $set: { "store.energy": 300 } })
storage.db["rooms.objects"].update({_id: "65764dce2e686901ab50de5e" }, { $set: { "store.ops": 40000 } })
// Edit pcreep powers
storage.db["users.power_creeps"].update({ _id: "6591b1928a936c001ba8b463" }, { $set: { level: 7, powers: { "1": { level: 3 }, "2": { level: 1 }, "3": { level: 1 }, "6": { level: 1 }, "19": { level: 1 },}}})
storage.db["rooms.objects"].update({ _id: "6591b1928a936c001ba8b463" }, { $set: { level: 7, powers: { "1": { level: 3 }, "2": { level: 1 }, "3": { level: 1 }, "6": { level: 1 }, "19": { level: 1 },}}})
// update powercreep spawn times
storage.db["users.power_creeps"].update({ _id: "6591b1928a936c001ba8b463" }, { $set: { spawnCooldownTime: 1692327427061} })
// Room RCL level
storage.db['rooms.objects'].update({ room: "E25S7", type: 'controller' }, { $set: { level: 8 } })
// Auto-complete sites
// Note that it will cause the builder's store to overflow, so use sparingly!
storage.db['rooms.objects'].update({ room: "E4S19", type: 'constructionSite' }, { $set: { progress: 10000 } })
// Unexpiring creeps
storage.db['rooms.objects'].update({ _id: "65086f144b63f3002e74d267" }, { $set: { ageTime: 999999 } })
// Fill all extensions
storage.db['rooms.objects'].update({ room: "E4S19", type: 'extension' }, { $set: { "store.energy": 200 } })
// Complete spawning faster
storage.env.get(storage.env.keys.GAMETIME).then(tick => storage.db['rooms.objects'].update({ room: "E7S16", type: 'spawn' }, { $set: { "spawning.spawnTime": parseInt(tick, 10) + 1 } }))
// Heal a creep
let creep;
storage.db['rooms.objects'].findOne({_id: "6508e9d2009a9600318f4bf6"}).then(d => creep = d);
creep.body.forEach((d, idx) => d.hits = 100);
storage.db["rooms.objects"].update({_id: "6508ebf0009a9600318f4c3d" }, { $set: { "body": creep.body, "hits": creep.hitsMax } })
// Generate a powerbank at the given position
// Taken from the engine's cronjob
// Reset the room's powerbank timer so that it allows adding one in
storage.db["rooms"].update({ bus: true, status: "normal" }, { $set: { powerBankTime: 0 } })
// easy to read version, but won't execute as the server evals lines one by one
async function makePowerBank(roomName, x, y, crit) {
if (x < 0 || x > 49 || y < 0 || y > 49) {
return false;
}
const room = await storage.db['rooms'].findOne({ _id: roomName });
if (!room) return false;
const POWER_BANK_HITS = 2000000;
const POWER_BANK_DECAY = 5000;
const POWER_BANK_CAPACITY_MIN = 500;
const POWER_BANK_CAPACITY_MAX = 5000;
const POWER_BANK_CAPACITY_CRIT = 0.3;
if (crit === undefined) {
crit = POWER_BANK_CAPACITY_CRIT;
}
let power = Math.floor(Math.random() * (POWER_BANK_CAPACITY_MAX - POWER_BANK_CAPACITY_MIN) + POWER_BANK_CAPACITY_MIN);
if (Math.random() < crit) {
power += POWER_BANK_CAPACITY_MAX;
}
const gameTime = await storage.env.get(storage.env.keys.GAMETIME);
return await storage.db['rooms.objects'].insert({
type: 'powerBank',
x, y,
room: roomName,
store: {power},
hits: POWER_BANK_HITS,
hitsMax: POWER_BANK_HITS,
decayTime: parseInt(gameTime) + POWER_BANK_DECAY
});
return true;
}
// Execute that one in the cli so the function exists
async function makePowerBank(roomName, x, y, crit) { if (x < 0 || x > 49 || y < 0 || y > 49) { return false; } const room = await storage.db['rooms'].findOne({ _id: roomName }); if (!room) return false; const POWER_BANK_HITS = 2000000; const POWER_BANK_DECAY = 5000; const POWER_BANK_CAPACITY_MIN = 500; const POWER_BANK_CAPACITY_MAX = 5000; const POWER_BANK_CAPACITY_CRIT = 0.3; if (crit === undefined) { crit = POWER_BANK_CAPACITY_CRIT; } let power = Math.floor(Math.random() * (POWER_BANK_CAPACITY_MAX - POWER_BANK_CAPACITY_MIN) + POWER_BANK_CAPACITY_MIN); if (Math.random() < crit) { power += POWER_BANK_CAPACITY_MAX; } const gameTime = await storage.env.get(storage.env.keys.GAMETIME); return await storage.db['rooms.objects'].insert({ type: 'powerBank', x, y, room: roomName, store: {power}, hits: POWER_BANK_HITS, hitsMax: POWER_BANK_HITS, decayTime: parseInt(gameTime) + POWER_BANK_DECAY }); }
// Then you can create as many powerbanks as you want
makePowerBank("W38N12", 12, 12);