• 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 resetting storage after 24 hours

Kahras

Member
Joined
Aug 6, 2012
Messages
101
Reaction score
7
Location
Warsaw
Lua:
local function getExpForLevel(level)
    level = level - 1
    return ((50 * level * level * level) - (150 * level * level) + (400 * level)) / 3
end


local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
local talkState = {}
function onCreatureAppear(cid)                npcHandler:onCreatureAppear(cid)             end
function onCreatureDisappear(cid)             npcHandler:onCreatureDisappear(cid)         end
function onCreatureSay(cid, type, msg)         npcHandler:onCreatureSay(cid, type, msg)     end
function onThink()                             npcHandler:onThink()                         end


function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
        local creature = Player(cid)
        local npc = Npc(getNpcCid())

    if msg:lower() == "task" then
        if getPlayerStorageValue(cid, 31250) <= 0 then
            if getPlayerStorageValue(cid, 31252) <= os.time() then        -- sprawdza czy gracz odczekal 24h
                local tasks_ = {}
                local n = 0
                for k, v in pairs(tasks) do
                    n = n+1
                    if getPlayerLevel(cid) >= tasks[n].lvRange[1] and getPlayerLevel(cid) <= tasks[n].lvRange[2] then
                        table.insert(tasks_, {tasks[n], n})
                    end
                end
            if getPlayerStorageValue(cid, 31254) < 2 then
                if #tasks_ > 0 then
                    taskx[cid] = tasks_[math.random(1, #tasks_)]
                    selfSay("To twoja "..getPlayerStorageValue(cid, 31254).." misja. Musisz zabic "..taskx[cid][1].amount.." "..taskx[cid][1].name.."! Wroc gdy to zrobisz.", cid)
                    local task = taskx[cid][1]
                    setPlayerStorageValue(cid, 31250, taskx[cid][2])
                    setPlayerStorageValue(cid, 31251, 0)
                    doSendMagicEffect(getPlayerPosition(cid), 13)   
                else
                    selfSay("Sorry ale nie mam dla Ciebie zadan.", cid)
                end
            end
            else
                selfSay("Sorry ale taski mozesz robic co 24 godziny, przyjdz pozniej.", cid)            -- odpowi
            end
        else
            local task = tasks[getPlayerStorageValue(cid, 31250)]
            if task.amount <= getPlayerStorageValue(cid, 31251) then
                setPlayerStorageValue(cid, 31250, 0)
                setPlayerStorageValue(cid, 31251, 0)
                setPlayerStorageValue(cid, 31253, getPlayerStorageValue(cid, 31253) + task.points)
                doSendMagicEffect(getPlayerPosition(cid), 13)
                doSendMagicEffect(npc:getPosition(), CONST_ME_MAGIC_BLUE)
                creature:addExperience(getExpForLevel(creature:getLevel() + task.lvReward) - creature:getExperience(), false)
                selfSay("Brawo! Twoja nagroda to: "..task.lvReward.." lv oraz "..task.points.." task punktow.", cid)
                setPlayerStorageValue(cid, 31254, getPlayerStorageValue(cid, 31254) + 1)    -- BLOKADA MAX 2 TASKI
            if getPlayerStorageValue(cid, 31254) == 2 then
                setPlayerStorageValue(cid, 31252, os.time()+10) --dla testu 10 sekund
            end
            else
                selfSay("Jeszcze nie skonczyles zadania! Zostalo ci do zabicia "..task.amount-getPlayerStorageValue(cid, 31251).." "..task.name..".", cid)
            end
        end
    end   
    return true
end

npcHandler:setMessage(MESSAGE_GREET, "Witaj! |PLAYERNAME|! Moze mam dla Ciebie zadanie.. [task]")
npcHandler:setMessage(MESSAGE_FAREWELL, "Do zobaczenia!")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())


Hello i have a problem edited this script.
I want the player to be able to complete 2 missions every 24 hours.
this is getPlayerStorageValue(cid, 31254) which saves how many missions the player has completed
And I have a problem with resetting 31254 storage after 24 hours.

Can someone help me achieve this?
 
Back
Top