Auto map clean script

Lopaskurwa

Banned User
Joined
Oct 6, 2017
Messages
694
Reaction score
32
Hello i cant find anywhere auto map clean that happens every 2hours and puts warning before map is cleaned. It should remove items and corpses from map but no items from houses. TFS 1.2
 

Apollos

Dude who does stuff
Joined
Apr 22, 2009
Messages
737
Reaction score
450
Location
United States
Hello i cant find anywhere auto map clean that happens every 2hours and puts warning before map is cleaned. It should remove items and corpses from map but no items from houses. TFS 1.2
Lua:
local function cleanMapTimer(clean)
    if not clean then
        broadcastMessage("Map clean in 2 minutes. Be aware, there may be some lag.", MESSAGE_STATUS_WARNING)
        addEvent(cleanMapTimer, 2 * 60 * 1000, true)
    else
        cleanMap()
        broadcastMessage("Map cleaned.", MESSAGE_STATUS_WARNING)
    end
end

function onThink(interval, lastExecution)
    broadcastMessage("Map clean in 5 minutes.", MESSAGE_STATUS_WARNING)
    addEvent(cleanMapTimer, 3 * 60 * 1000, false)
    return true
end
 

bybbzan

mapper
Premium User
Joined
Aug 4, 2012
Messages
723
Reaction score
62
Hello i cant find anywhere auto map clean that happens every 2hours and puts warning before map is cleaned. It should remove items and corpses from map but no items from houses. TFS 1.2
You could use this aswell, saves the map and cleans it aswell if you change 'false' to 'true'

Lua:
local shutdownAtServerSave = false
local cleanMapAtServerSave = false

local function serverSave()
    if shutdownAtServerSave then
        Game.setGameState(GAME_STATE_SHUTDOWN)
    else
        Game.setGameState(GAME_STATE_NORMAL)
    end

    if cleanMapAtServerSave then
        cleanMap()
    end

    saveServer()
end

local function secondServerSaveWarning()
    Game.broadcastMessage('Server is saving game in one minute. Please go to a safe place.', MESSAGE_STATUS_WARNING)
    addEvent(serverSave, 60000)
end

local function firstServerSaveWarning()
    Game.broadcastMessage('Server is saving game in 3 minutes. Please go to a safe place.', MESSAGE_STATUS_WARNING)
    addEvent(secondServerSaveWarning, 120000)
end

function onTime(interval)
    Game.broadcastMessage('Server is saving game in 5 minutes. Please go to a safe place.', MESSAGE_STATUS_WARNING)
    Game.setGameState(GAME_STATE_STARTUP)
    addEvent(firstServerSaveWarning, 120000)
    return not shutdownAtServerSave
end
 
OP
Lopaskurwa

Lopaskurwa

Banned User
Joined
Oct 6, 2017
Messages
694
Reaction score
32
Lua:
local function cleanMapTimer(clean)
    if not clean then
        broadcastMessage("Map clean in 2 minutes. Be aware, there may be some lag.", MESSAGE_STATUS_WARNING)
        addEvent(cleanMapTimer, 2 * 60 * 1000, true)
    else
        cleanMap()
        broadcastMessage("Map cleaned.", MESSAGE_STATUS_WARNING)
    end
end

function onThink(interval, lastExecution)
    broadcastMessage("Map clean in 5 minutes.", MESSAGE_STATUS_WARNING)
    addEvent(cleanMapTimer, 3 * 60 * 1000, false)
    return true
end
Is it in globalevents?
You could use this aswell, saves the map and cleans it aswell if you change 'false' to 'true'

Lua:
local shutdownAtServerSave = false
local cleanMapAtServerSave = false

local function serverSave()
    if shutdownAtServerSave then
        Game.setGameState(GAME_STATE_SHUTDOWN)
    else
        Game.setGameState(GAME_STATE_NORMAL)
    end

    if cleanMapAtServerSave then
        cleanMap()
    end

    saveServer()
end

local function secondServerSaveWarning()
    Game.broadcastMessage('Server is saving game in one minute. Please go to a safe place.', MESSAGE_STATUS_WARNING)
    addEvent(serverSave, 60000)
end

local function firstServerSaveWarning()
    Game.broadcastMessage('Server is saving game in 3 minutes. Please go to a safe place.', MESSAGE_STATUS_WARNING)
    addEvent(secondServerSaveWarning, 120000)
end

function onTime(interval)
    Game.broadcastMessage('Server is saving game in 5 minutes. Please go to a safe place.', MESSAGE_STATUS_WARNING)
    Game.setGameState(GAME_STATE_STARTUP)
    addEvent(firstServerSaveWarning, 120000)
    return not shutdownAtServerSave
end
I dont really like game shutdowns its kinda annoying
 

Apollos

Dude who does stuff
Joined
Apr 22, 2009
Messages
737
Reaction score
450
Location
United States
Nice then. How do i need to install it does it goes in globlalevent or events or global.lua?
Both are globalevents. Add this into your global and name the script clean_map.lua. Intervals in globalevents are in milliseconds so 1000 = 1 second. This is for 2 hours:
XML:
<globalevent name="Clean Map" interval="7200000" script="clean_map.lua" />
If you want to use bybbzan's code you need to change:
Lua:
function onTime(interval)
to
Lua:
function onThink(interval, lastExecution)
 
OP
Lopaskurwa

Lopaskurwa

Banned User
Joined
Oct 6, 2017
Messages
694
Reaction score
32
Both are globalevents. Add this into your global and name the script clean_map.lua. Intervals in globalevents are in milliseconds so 1000 = 1 second. This is for 2 hours:
XML:
<globalevent name="Clean Map" interval="7200000" script="clean_map.lua" />
If you want to use bybbzan's code you need to change:
Lua:
function onTime(interval)
to
Lua:
function onThink(interval, lastExecution)
I will use yours. Btw is true that it might lag server or its a bait? ;D
 
Top