Untitled

mail@pastecode.io avatar
unknown
lua
a year ago
2.1 kB
2
Indexable
Never
local function startEventCounter(table,xx)
    --addEvent(startEventCounter,xx,xx)
    local eventStartHour = table["h"]
    local eventStartMinute = table["m"]
    local rafi = tonumber(os.date('%H'))
    local chuju = tonumber(os.date('%M'))
    local eventStartToMinute = eventStartHour*60 + eventStartMinute
    local rightNowTimeToMinute = rafi*60 + chuju
    local isStarted = false
    local nextTime = 0
 
 
 
 
 
    if (rafi == eventStartHour and chuju == eventStartMinute) then
        isStarted = true
        doBroadcastMessage(18,"Event has just started with 20% more experiance, which lasts 1 hour.")
        local players = getAllPlayers()
        for _, pid in ipairs(players) do
            doPlayerSendTextMessage(pid, MESSAGE_STATUS_CONSOLE_BLUE, "Event has just started with 20% more experiance, which lasts 1 hour.")
            doPlayerSetExpBonus(pid,BONUSEXPEVENT)
        end
    -- godzina kolejny event do wylaczenia eventu..
    addEvent(startEventCounter, 3600000,table)
   --elseif (rafi==eventStartHour + 1  and chuju == eventStartMinute) then
    elseif (isStarted == false) then
        local players = getAllPlayers()
        for _, pid in ipairs(players) do
            doPlayerSendTextMessage(pid, MESSAGE_STATUS_CONSOLE_BLUE, "End of bonus")
            doPlayerSetExpBonus(pid,0)
        end
    end
 
    if(rightNowTimeToMinute < eventStartToMinute) then
 
        nextTime = eventStartToMinute - rightNowTimeToMinute
        addEvent(startEventCounter, nextTime  * 60 * 1000,table)
    end
 
    if (rightNowTimeToMinute > eventStartToMinute) then
 
        nextTime = 1440 - rightNowTimeToMinute + eventStartToMinute
        addEvent(startEventCounter, nextTime * 60 * 1000, table)
    end
 
end
 
eventCounterStarted=false
 
function doStartEventCounter(xxx)
 
    if(eventCounterStarted==false) then
        eventCounterStarted=true
    local eventFirst = {}
    local eventSecond = {}
    eventFirst["h"] = 16
    eventFirst["m"] = 00
    eventSecond["h"] = 20
    eventSecond["m"] = 00
        startEventCounter(eventFirst,xxx)
        startEventCounter(eventSecond,xxx)
    end
end