Screeps: World
Auto Safemode - Code for new players
Hi Guys

So if you want auto-safemode, here's what I did:

If a wall or rampart looses all its hitpoints down to five (change the numbe rif you like), activate the safemode.

Main:

var myRoomName = 'INSERT YOUR ROOM HERE'; var lastResort = require("room.failSafe"); lastResort.saveMyRoom(myRoomName);

Module called 'room.failSafe '

module.exports = { saveMyRoom: function(myRoomName) { var walls = Game.rooms[myRoomName].find(FIND_STRUCTURES, {filter: (s) => s.structureType == STRUCTURE_WALL || s.structureType == STRUCTURE_RAMPART}); for (let wall of walls) { if (wall.hits <= 5) { Game.rooms[myRoomName].controller.activateSafeMode(); } } } };

Disclaimer: I put this in a module, because i just have to comment out "lastResort.saveMyRoom(myRoomName);" to deactivate this.

Why would you wan tto deactivate it?

Because if you BUILD a wall / ramapart, it starts out with 1 healthpoint and triggers your failsafe.

SO BEFORE YOU BUILD WALLS, DEACTIVATE IT (or it triggers)!!
Last edited by JOHNNY GUEGGU; Dec 1, 2016 @ 3:48pm
< >
Showing 1-1 of 1 comments
goto64 Dec 7, 2016 @ 2:13pm 
At some point you are likely going to forget deactivating it.
It would be safer to add a check for hostiles in the room, and only activate safe mode in case of hostiles.

var hostiles = Game.rooms[myRoomName].find(FIND_HOSTILE_CREEPS); if (hostiles.length > 0) { Game.rooms[myRoomName].controller.activateSafeMode(); }

Also, are you sure that the "wall.hits <= 5" condition will trigger if for example your wall is reduced from 100 to 0 hit points in one tick? Depends if the wall exists for one tick with 0 hit points.
< >
Showing 1-1 of 1 comments
Per page: 1530 50