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

create wait before giving reward

Sr.Taco

Member
Joined
Jul 9, 2015
Messages
21
Reaction score
8
Hi, I have this script working, that gives reward, random and every x time

but I wanted to open it to create the illusion that you are looking for something
an example is this

the script I use is this

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local waitTime = 1*60      --
local storage = 123456      --


local t = {
    { item = 2140, count = 1 },
    { item = 2121, count = 1 },
    { item = 2152, count = 1 },
    { item = 2143, count = 1 },
    { item = 2237, count = 1 }
}

local posicion = {x = 1015, y = 1032, z = 8} -- Posicion a donde sera teletransportado

--! Nabs don't configure !--
local queststatus = getPlayerStorageValue(cid,storage)
                if queststatus + (waitTime) <= os.time() then
   setPlayerStorageValue(cid,storage,os.time())
                        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR,"reward chest entregada.")
                        local random = math.random(1, #t)
      doPlayerAddItem(cid, t[random].item, t[random].count)
      doTeleportThing(cid, posicion)
        doSendMagicEffect(posicion, 10)
   elseif getPlayerStorageValue(cid, storage)-os.time()+(waitTime) <= 60 then
   doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR,"It is empty, come back in ".. getPlayerStorageValue(cid, storage)-os.time()+(waitTime) .." seconds.")
   else
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR,"It is empty, come back in ".. timeString(getPlayerStorageValue(cid, storage)-os.time()+(waitTime)) ..".")
    end
   return true
   end
 
 
   function timeString(timeDiff)
    local dateFormat = {
        {"day", timeDiff / 60 / 60 / 24},
        {"hour", timeDiff / 60 / 60 % 24},
        {"minute", timeDiff / 60 % 60},
        {"second", timeDiff % 60}
    }

    local out = {}
    for k, t in ipairs(dateFormat) do
        local v = math.floor(t[2])
        if(v > 0) then
            table.insert(out, (k < #dateFormat and (#out > 0 and ', ' or '') or ' and ') .. v .. ' ' .. t[1] .. (v ~= 1 and 's' or ''))
        end
    end
   
    return table.concat(out)
end

Code:
<action uniqueid="xxxx" event="script" value="rewardchest.lua" />


sorry for my bad English
 
Last edited:
The function you are after is addEvent. Search your codebase, there is probably already scripts that use it your can use as template.

The AddEvent function loses all context. Pass everything you'll need as a parameter.

There are no guarantees. Do sanity checks. The first param you'll pass to the callback as probably the player's cid. Make sure this cid is still a player that is online, or you'll cause yourself issues. If you try to act on a cid of a player's that's now logged out, you may crash things.
 

Similar threads

Back
Top