• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Globalevent dont start

chupaescadatri

Banned User
Joined
Jul 5, 2014
Messages
338
Reaction score
49
globalevents.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<globalevents>
<globalevent name="globalsave" time="17:06:00" event="script" value="save.lua"/>
        </globalevents>
save.lua
Code:
function prepareShutdown(minutes) if(minutes <= 0) then
        doSetGameState(GAMESTATE_CLOSED)
        return false
    end
 
 
    if(minutes == 1) then
        doBroadcastMessage("Server is going down in " .. minutes .. " minute for global save, please log out now!")
    elseif(minutes <= 3) then
        doBroadcastMessage("Server is going down in " .. minutes .. " minutes for global save, please log out.")
    else
        doBroadcastMessage("Server is going down in " .. minutes .. " minutes for global save.")
    end
 
 
    shutdownEvent = addEvent(prepareShutdown, 60000, minutes - 1)
    return true
end


function onTime(interval)
    if os.date('%H') == "3" and getWorldUpTime() > 20*60*60 then
        return prepareShutdown(10)
    end
return TRUE
end
Am I doing something wrong?
simply arrive on time and no message appears
+rep
 
Solution
globalevents.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<globalevents>
<globalevent name="globalsave" time="17:06:00" event="script" value="save.lua"/>
        </globalevents>
save.lua
Code:
function prepareShutdown(minutes) if(minutes <= 0) then
        doSetGameState(GAMESTATE_CLOSED)
        return false
    end


    if(minutes == 1) then
        doBroadcastMessage("Server is going down in " .. minutes .. " minute for global save, please log out now!")
    elseif(minutes <= 3) then
        doBroadcastMessage("Server is going down in " .. minutes .. " minutes for global save, please log out.")
    else
        doBroadcastMessage("Server is going down in " .. minutes .. " minutes for global save.")
    end...
globalevents.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<globalevents>
<globalevent name="globalsave" time="17:06:00" event="script" value="save.lua"/>
        </globalevents>
save.lua
Code:
function prepareShutdown(minutes) if(minutes <= 0) then
        doSetGameState(GAMESTATE_CLOSED)
        return false
    end


    if(minutes == 1) then
        doBroadcastMessage("Server is going down in " .. minutes .. " minute for global save, please log out now!")
    elseif(minutes <= 3) then
        doBroadcastMessage("Server is going down in " .. minutes .. " minutes for global save, please log out.")
    else
        doBroadcastMessage("Server is going down in " .. minutes .. " minutes for global save.")
    end


    shutdownEvent = addEvent(prepareShutdown, 60000, minutes - 1)
    return true
end


function onTime(interval)
    if os.date('%H') == "3" and getWorldUpTime() > 20*60*60 then
        return prepareShutdown(10)
    end
return TRUE
end
Am I doing something wrong?
simply arrive on time and no message appears
+rep
You're activating the event at hour 17 yet you are only allowing the prepareShutdown func to run if the hour is 3. There's no need to have that part in the if statement. I don't see a need to check the server uptime either. Just run the prepareShutdown func without any conditional statements.

Also if you have an automatic restart set up on your machine then it's probably best to use doSaveServer instead of setting game state to closed. Like how it's used in this script:
otservme/global860 (https://github.com/otservme/global860/blob/571183a2858e638d49778cca914c8126bd6f17ce/data/globalevents/scripts/save.lua)
 
Solution
Back
Top