• 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!

events timer

jareczekjsp

Member
Joined
Jan 30, 2023
Messages
217
Reaction score
15
GitHub
Jarek123
Hello I use TFS 0.4 and I have problem with timer events script I have Error in console and script not working can anyone help me ?please
my script in globalevents is :

Lua:
local EventsListalist = {
        
        {time = "01:00", name = "Snowball Event"},       
        {time = "02:00", name = "DesertWar Event"},
        {time = "03:00", name = "Capture The Flag"},
        {time = "04:00", name = "FireStorm Event"},
        {time = "09:00", name = "Defend The Tower"},
        {time = "10:00", name = "Snowball Event"},
        {time = "11:00", name = "DesertWar Event"},
        {time = "12:00", name = "Capture The Flag"},
        {time = "13:00", name = "FireStorm Event"},
        {time = "15:00", name = "Battlefield Event"},
        {time = "16:00", name = "Defend The Tower"},
        {time = "17:00", name = "Snowball Event"},
        {time = "18:00", name = "DesertWar Event",},
        {time = "19:00", name = "Capture The Flag",},
        {time = "20:00", name = "FireStorm Event"},
        {time = "21:00", name = "Real Castle"},
        {time = "22:00", name = "Battlefield Event"},
        {time = "23:00", name = "Defend The Tower"}
        

    }
    
    local position = {x = 158, y = 49, z = 7}
    
    
    function onThink(interval, lastExecution)
        
     local people = getPlayersOnline()
    if #people == 0 then
        return true
    end
    
    local Count = 0
      for _, t in ipairs(EventsListalist) do
            local eventTime = hourToNumber(t.time)
            local realTime = hourToNumber(os.date("%H:%M:%S"))
            if eventTime >= realTime then
           doPlayerSay(people[1], "Próximo evento ŕs {"..t.time.."h} "..t.name..", faltam "..timeString(eventTime - realTime)..".", TALKTYPE_MONSTER_SAY, false, 0, position)
                return true
            end
            Count = Count + 1
        end
        return true
    end

and error in console is :


Code:
[12:3:44] [Error - GlobalEvent Interface]
[12:3:44] data/globalevents/scripts/eventsHenrique.lua:onThink
[12:3:44] Description:
[12:3:44] data/globalevents/scripts/eventsHenrique.lua:37: attempt to call global 'hourToNumber' (a nil value)
[12:3:44] stack traceback:
[12:3:44]       data/globalevents/scripts/eventsHenrique.lua:37: in function <data/globalevents/scripts/eventsHenrique.lua:28>
[12:3:44] [Error - GlobalEvents::think] Couldn't execute event: eventos
 
try.
Lua:
local EventsList = {
    {time = "01:00", name = "Snowball Event"},
    {time = "02:00", name = "DesertWar Event"},
    {time = "03:00", name = "Capture The Flag"},
    {time = "04:00", name = "FireStorm Event"},
    {time = "09:00", name = "Defend The Tower"},
    {time = "10:00", name = "Snowball Event"},
    {time = "11:00", name = "DesertWar Event"},
    {time = "12:00", name = "Capture The Flag"},
    {time = "13:00", name = "FireStorm Event"},
    {time = "15:00", name = "Battlefield Event"},
    {time = "16:00", name = "Defend The Tower"},
    {time = "17:00", name = "Snowball Event"},
    {time = "18:00", name = "DesertWar Event"},
    {time = "19:00", name = "Capture The Flag"},
    {time = "20:00", name = "FireStorm Event"},
    {time = "21:00", name = "Real Castle"},
    {time = "22:00", name = "Battlefield Event"},
    {time = "23:00", name = "Defend The Tower"}
}

local position = {x = 158, y = 49, z = 7}

function hourToNumber(hourString)
    local hour, minute = string.match(hourString, "(%d+):(%d+)")
    return tonumber(hour) * 60 + tonumber(minute)
end

function onThink(interval, lastExecution)
    local people = getPlayersOnline()
    if #people == 0 then
        return true
    end

    local Count = 0
    for _, t in ipairs(EventsList) do
        local eventTime = hourToNumber(t.time)
        local realTime = hourToNumber(os.date("%H:%M"))
        if eventTime >= realTime then
            doPlayerSay(people[1], "Next event at {"..t.time.."} "..t.name..", missing "..eventTime - realTime.." minutes.", TALKTYPE_MONSTER_SAY, false, 0, position)
            return true
        end
        Count = Count + 1
    end
    return true
end
 
Back
Top