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

RevScripts random time

alcapone

Member
Joined
Jan 13, 2021
Messages
246
Reaction score
19
Lua:
local raids = {
    -- Weekly
    --Segunda-Feira
    ['Monday'] = {
        ['06:00'] = {raidName = 'RatsThais'},
    },

    --Terça-Feira
    ['Tuesday'] = {
        ['16:00'] = {raidName = 'Midnight Panther'}
    },

    --Quarta-Feira
    ['Wednesday'] = {
        ['12:00'] = {raidName = 'Draptor'}
    },

    --Quinta-Feira
    ['Thursday'] = {
        ['19:00'] = {raidName = 'Undead Cavebear'}
    },

    --Sexta-feira
    ['Friday'] = {
        ['06:00'] = {raidName = 'Titanica'}
    },

    --Sábado
    ['Saturday'] = {
        ['20:00'] = {raidName = 'Draptor'}
    },

    --Domingo
    ['Sunday'] = {
        ['15:00'] = {raidName = 'Midnight Panther'},
        ['13:00'] = {raidName = 'Orc Backpack'}
    },

    -- By date (Day/Month)
    ['31/10'] = {
        ['16:00'] = {raidName = 'Halloween Hare'}
    }
}

local spawnRaids = GlobalEvent("spawn raids")
function spawnRaids.onThink(interval, lastExecution, thinkInterval)
    local day, date = os.date('%A'), getRealDate()

    local raidDays = {}
    if raids[day] then
        raidDays[#raidDays + 1] = raids[day]
    end
    if raids[date] then
        raidDays[#raidDays + 1] = raids[date]
    end
    if #raidDays == 0 then
        return true
    end

    for i = 1, #raidDays do
        local settings = raidDays[i][getRealTime()]
        if settings and not settings.alreadyExecuted then
            Game.startRaid(settings.raidName)
            settings.alreadyExecuted = true
        end
    end
    return true
end

spawnRaids:interval(60000)
spawnRaids:register()
the original file is above I would like the time to be random

--Domingo
['Sunday'] = {
{raidName = 'Midnight Panther'},
{raidName = 'Orc Backpack'}
},

example on Sunday he would run the raid once at random time
 
Before game.start raid add local randomSpawn = math.random(1,10)
If randomSpawn == 1 then
Game.startraid
 
It is possible that it is not what you are looking for exactly, but here I will leave you a code that I modify for you

data/scripts/spawnraids.lua
Lua:
-- TFS 1.3+
if not RaidSpawnList then
    RaidSpawnList = {
        -- Weekly
        --Segunda-Feira
        ['Monday'] = {
            { raidName='RatsThais' }
        },
        --Terça-Feira
        ['Tuesday'] = {
            { raidName='Midnight Panther' }
        },
        --Quarta-Feira
        ['Wednesday'] = {
            { raidName='Draptor' }
        },
        --Quinta-Feira
        ['Thursday'] = {
            { raidName='Undead Cavebear' }
        },
        --Sexta-feira
        ['Friday'] = {
            { raidName='Titanica' }
        },
        --Sábado
        ['Saturday'] = {
            { raidName='Draptor' }
        },
        --Domingo
        ['Sunday'] = {
            { raidName='Midnight Panther' },
            { raidName='Orc Backpack' }
        }
    }
end
local globalEvent = GlobalEvent("spawnRaidStartup's")
function globalEvent.onStartup()
    for day, raid in pairs(RaidSpawnList) do
        for key, info in pairs(raid) do
            local date = os.date("*t")
            local hour, min = math.random(0, 23), math.random(0, 60)
            if hour < date.hour or (hour == date.hour and min < date.min) then
                info.alreadyExecuted = true
            else
                RaidSpawnList[day][key].time = string.format("%02d:%02d", hour, min)
            end
        end
    end
    return true
end
globalEvent:register()
local spawnRaids = GlobalEvent("spawn raids")
function spawnRaids.onThink(interval, lastExecution, thinkInterval)
    local day = os.date('%A')
    local foundDay = RaidSpawnList[day]
    if not foundDay or #foundDay == 0 then
        return true
    end
    local randomRaid = foundDay[math.random(1, #foundDay)]
    if randomRaid.alreadyExecuted or randomRaid.time ~= os.date('%H:%M') then
        return true
    end
    Game.startRaid(randomRaid.raidName)
    randomRaid.alreadyExecuted = true
    return true
end
spawnRaids:interval(60000)
spawnRaids:register()

The list only has names, but this list is updated with random times when the server is starting, everything is automatic, it is only a modification of its code, so you must restart the server every week how minimum so that the events are executed again in the days repeated ;)
 
Back
Top