Server Crash Recover script

Based off of Server Recover done by Marco over at Killing Floor

What this script basically does is if your server crashes will change the map to the one the server was current on or was going to switch to, and if the server crashes on the same map more then the set amount using the cvar max_crash_count then change to the next map in the map cycle file or a random map based on the prefixes defined in the .lua (I left a comment for those who don’t know)

Credits to Jetboom for the code to switch to a random map

Download:

GitHub:

[editline]23rd March 2016[/editline]

Hmm I set the post tag to addon but it choose WIP Module, not sure if I can change it

Try adding it to github please?

Done, https://github.com/ForrestMarkX/glua-server-crash-recover

Title made me think this catches a potential crash and resets the map instead but it just makes the server go back to the map it was on before the crash. The script is very sloppy btw.

Some of this code seems very unnecessary or over complicated. There is no reason to be doing stuff like overriding RunConsoleCommand. You should simple have a text file and update it every time the map changes with the current map. If you want you could even add the current round or time depending on the gamemode. Then, whenever the server boots up have it read the file and change the map accordingly.


if string.find(stringCommand, "changelevel") then

Wow, don’t do that please, it’s very bad.
You have to split the stringCommand with spaces and then get the first element of it. Then you can check if it is “changelevel”.

The problem with your current code is that it will work with a command like : MyCustomAddon changelevel “map”

Next,


local map = string.Replace(stringCommand, "changelevel", "")

This should be the second element of the table.

When you split a string by a character, it returns a array of all your elements, ordered.

Example :



local theCommand = "changelevel gm_flatgrass" // Or whatever it is
local split = string.Split(theCommand, " ")
PrintTable(split)
// This should print :
//[1] : "changelevel"
//[2] : "gm_flatgrass"

// You then have to check if the command is valid :
if !split or !split[1] or !split[2] then return end

You now have all you need :
if split[1] == "changelevel" then ... end
local map = split[2]

// Next, you have to check if the map is valid


I did not know this, I have no experience with spliting strings into tables and did not know about this. Thanks for the info

I override RunConsoleCommand because there is no hook or anything to check if engine level cvars are called and the primary reason for it is to save the text file for the map the server is going to change to incase if it crashes during map change. I don’t know about saving the current time as many gamemodes could have there own vars for it, I’ll look into it

Instead you should use the Initialize hook and in there copy down the current map into the text file.