• 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 quest random chest

VonSemog

New Member
Joined
Jun 3, 2022
Messages
6
Reaction score
0
I searched in many forums for a script of this type. A chest that drops a random item.

The topics I found is always a daily reward chest that the player can pick up every day. What I would like was a script with a chest to give random items once to the player and not be able to get the reward again. Does anyone have something like this?

tibia 8.6, tfs 0.4
 
Solution
it works!! only you have a chance of not receiving anything. Which line should I remove for this not to happen?
easiest way without rewriting the entire script..

change
Lua:
    local tmp = {}
    for i = 1, #items do
        local chance = items[i].itemChance
        if (chance == true or math.random(1, 100) <= chance) then
            local id = items[i].itemId
            local count = items[i].itemCount
            if not getItemInfo(id).stackable then
                for i = 1, count do
                    doPlayerAddItem(cid, id, 1)
                end
            else
                doPlayerAddItem(cid, id, count)
            end
            table.insert(tmp, count .. " " .. getItemNameById(id))
            break...
I searched in many forums for a script of this type. A chest that drops a random item.

The topics I found is always a daily reward chest that the player can pick up every day. What I would like was a script with a chest to give random items once to the player and not be able to get the reward again. Does anyone have something like this?

tibia 8.6, tfs 0.4
Maybe this can work for you:

Lua:
local storage = 5964 -- change this value
local cooldown = 24 -- hours
local effect = CONST_ME_MAGIC_BLUE
local items = {
    { itemId = 5162, itemCount = 1, itemChance = 1 },
    { itemId = 5599, itemCount = 1, itemChance = 10 },
    { itemId = 5166, itemCount = 20, itemChance = 30 },
    { itemId = 5114, itemCount = 1, itemChance = 50 },
    { itemId = 5263, itemCount = 50, itemChance = 70 },
    { itemId = 2160, itemCount = 30, itemChance = true }, -- set itemChance = true for 100%
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local storageValue = getCreatureStorage(cid, storage)
    if storageValue - os.time() >= 1 then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, "You have received this reward, must wait.")
        return true
    end

    local tmp = {}
    for i = 1, #items do
        local chance = items[i].itemChance
        if (chance == true or math.random(1, 100) <= chance) then
            local id = items[i].itemId
            local count = items[i].itemCount
            if not getItemInfo(id).stackable then
                for i = 1, count do
                    doPlayerAddItem(cid, id, 1)
                end
            else
                doPlayerAddItem(cid, id, count)
            end
            table.insert(tmp, count .. " " .. getItemNameById(id))
            break
        end
    end

    if effect then
        doSendMagicEffect(getThingPosition(cid), effect)
    end

    local text = #tmp == 0 and "You have no received nothing. :(" or string.format("You have received %s.", table.concat(tmp, ", "))
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, text)
    doCreatureSetStorage(cid, storage, os.time() + (60 * 60 * cooldown))
    return true
end

Source:
 
To make the above script a 1 time only random reward..

Remove
Lua:
local cooldown = 24 -- hours
----
Change
Lua:
local storageValue = getCreatureStorage(cid, storage)
if storageValue - os.time() >= 1 then
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, "You have received this reward, must wait.")
    return true
end
to
Lua:
if getCreatureStorage(cid, storage) == 1 then
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, "It is empty.")
    return true
end
--
Change
Lua:
doCreatureSetStorage(cid, storage, os.time() + (60 * 60 * cooldown))
to
Lua:
doCreatureSetStorage(cid, storage, 1)
 
To make the above script a 1 time only random reward..

Remove
Lua:
local cooldown = 24 -- hours
----
Change
Lua:
local storageValue = getCreatureStorage(cid, storage)
if storageValue - os.time() >= 1 then
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, "You have received this reward, must wait.")
    return true
end
to
Lua:
if getCreatureStorage(cid, storage) == 1 then
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, "It is empty.")
    return true
end
--
Change
Lua:
doCreatureSetStorage(cid, storage, os.time() + (60 * 60 * cooldown))
to
Lua:
doCreatureSetStorage(cid, storage, 1)
I will test. I'll tell you soon if it worked
 
it works!! only you have a chance of not receiving anything. Which line should I remove for this not to happen?
easiest way without rewriting the entire script..

change
Lua:
    local tmp = {}
    for i = 1, #items do
        local chance = items[i].itemChance
        if (chance == true or math.random(1, 100) <= chance) then
            local id = items[i].itemId
            local count = items[i].itemCount
            if not getItemInfo(id).stackable then
                for i = 1, count do
                    doPlayerAddItem(cid, id, 1)
                end
            else
                doPlayerAddItem(cid, id, count)
            end
            table.insert(tmp, count .. " " .. getItemNameById(id))
            break
        end
    end
to
Lua:
    local tmp = {}
    while #tmp == 0 do
        for i = 1, #items do
            local chance = items[i].itemChance
            if (chance == true or math.random(1, 100) <= chance) then
                local id = items[i].itemId
                local count = items[i].itemCount
                if not getItemInfo(id).stackable then
                    for i = 1, count do
                        doPlayerAddItem(cid, id, 1)
                    end
                else
                    doPlayerAddItem(cid, id, count)
                end
                table.insert(tmp, count .. " " .. getItemNameById(id))
                break
            end
        end
    end
 
Solution
Back
Top