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

Tfs 1.2 math.random hours

president vankk

Web Developer & AuraOT Owner
Joined
Jul 10, 2009
Messages
5,719
Solutions
9
Reaction score
339
Hi folks! Could someone help me with my new script?

It is suppost to works like if it is 20th of the month then between 9am to 1p.m will broadcast a message, a did a little shit, check out.

Code:
local hours = {9, 10, 11, 12, 13}

function onThink(interval, lastExecution, thinkInterval)
    if os.date("%d", os.time()) == 20 then
        -- math.random between hours
        -- broadcast a message
    return true
end

Thanks.
 
os.date returns a string, so you need to convert it to a number.
Code:
local hours = {9, 10, 11, 12, 13}

function onThink(interval, lastExecution, thinkInterval)
    if tonumber( os.date("%d", os.time()) ) == 20 then
        -- math.random between hours
        -- broadcast a message
    return true
end
 
Can be used like this @Marcelo Druida ?

Code:
local hours = {9, 10, 11, 12, 13}

function onThink(interval, lastExecution, thinkInterval)
    if tonumber(os.date("%d", os.time())) == 20 then
        if hours[math.random(1,#hours)] then
            -- broadcast shit message
        end
    end
    return true
end
 
Code:
local hours = {9, 10, 11, 12, 13}
local randomhour = hours[math.random(1,#hours)]

function onThink(interval, lastExecution, thinkInterval)
    if tonumber(os.date("%d", os.time())) == 20 then
        if tonumber(os.date("%h", os.time())) == randomhour then
            randomhour = hours[math.random(1,#hours)]
            -- broadcast shit message
        end
    end
    return true
end
 
Back
Top