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

Random reward Chest

GuilleMoniz

New Member
Joined
Dec 5, 2016
Messages
23
Reaction score
3
Hello folks!

using tfs 1.0
tibia 8.60

Im trying to figure out how to make a 100% random reward chest.

Idea:

When you open the chest at final quest room, there will be only 1 chest. but with random reward, like

10% chance golden helmet
20% chance dragon scale legs
50% chance mpa
20% demon armor

Also you can only open it once ofc hahaha

Im pretty newbie at scripts lol so I can't make it work >.> i will apreciate any help!
 
Solution
Theres an error :(
Code:
[21/08/2017 14:57:02] [Error - Action Interface]
[21/08/2017 14:57:02] data/actions/scripts/Quests/legendaryquest.lua:onUse
[21/08/2017 14:57:02] Description:
[21/08/2017 14:57:02] data/actions/scripts/Quests/legendaryquest.lua:9: attempt to index local 'player' (a number value)
[21/08/2017 14:57:02] stack traceback:
[21/08/2017 14:57:02]     data/actions/scripts/Quests/legendaryquest.lua:9: in function <data/actions/scripts/Quests/legendaryquest.lua:8>

Lua:
local rewards = {
    {id = xxxx, chance = yyyy, count = 1},
    {id = xxxx, chance = yyyy, count = 1},
    {id = xxxx, chance = yyyy, count = 1},
    {id = xxxx, chance = yyyy, count = 1},
}

function onUse(player, item, fromPosition, target...
Lua:
local rewards = {
    {id = xxxx, chance = yyyy, count = 1},
    {id = xxxx, chance = yyyy, count = 1},
    {id = xxxx, chance = yyyy, count = 1},
    {id = xxxx, chance = yyyy, count = 1},
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local bag = player:addItem(2000)
    local msg = {"You have recieved a bag containing: "}
    for i = 1, #rewards do
        local reward = rewards[i]
        local rand = math.random(100)
        if rand >= reward.chance then
            local item = bag:addItem(reward.id, reward.count)
            msg[#msg+1] = string.format("%s%s", (count == 1) and item:getArticle() or count, (reward.count == 1) and item:getName() or item:getPluralName())
        end
    end
    msg[#msg+1] = (#msg == 1 and "nothing." or ".")
    player:sendTextMessage(MESSAGE_INFO_DESCR, table.concat(msg))
    return true
end
doesn't check for valid capacity though
 
Lua:
local rewards = {
    {id = xxxx, chance = yyyy, count = 1},
    {id = xxxx, chance = yyyy, count = 1},
    {id = xxxx, chance = yyyy, count = 1},
    {id = xxxx, chance = yyyy, count = 1},
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local bag = player:addItem(2000)
    local msg = {"You have recieved a bag containing: "}
    for i = 1, #rewards do
        local reward = rewards[i]
        local rand = math.random(100)
        if rand >= reward.chance then
            local item = bag:addItem(reward.id, reward.count)
            msg[#msg+1] = string.format("%s%s", (count == 1) and item:getArticle() or count, (reward.count == 1) and item:getName() or item:getPluralName())
        end
    end
    msg[#msg+1] = (#msg == 1 and "nothing." or ".")
    player:sendTextMessage(MESSAGE_INFO_DESCR, table.concat(msg))
    return true
end
doesn't check for valid capacity though


Theres an error :(
Code:
[21/08/2017 14:57:02] [Error - Action Interface]
[21/08/2017 14:57:02] data/actions/scripts/Quests/legendaryquest.lua:onUse
[21/08/2017 14:57:02] Description:
[21/08/2017 14:57:02] data/actions/scripts/Quests/legendaryquest.lua:9: attempt to index local 'player' (a number value)
[21/08/2017 14:57:02] stack traceback:
[21/08/2017 14:57:02]     data/actions/scripts/Quests/legendaryquest.lua:9: in function <data/actions/scripts/Quests/legendaryquest.lua:8>
 
Theres an error :(
Code:
[21/08/2017 14:57:02] [Error - Action Interface]
[21/08/2017 14:57:02] data/actions/scripts/Quests/legendaryquest.lua:onUse
[21/08/2017 14:57:02] Description:
[21/08/2017 14:57:02] data/actions/scripts/Quests/legendaryquest.lua:9: attempt to index local 'player' (a number value)
[21/08/2017 14:57:02] stack traceback:
[21/08/2017 14:57:02]     data/actions/scripts/Quests/legendaryquest.lua:9: in function <data/actions/scripts/Quests/legendaryquest.lua:8>

Lua:
local rewards = {
    {id = xxxx, chance = yyyy, count = 1},
    {id = xxxx, chance = yyyy, count = 1},
    {id = xxxx, chance = yyyy, count = 1},
    {id = xxxx, chance = yyyy, count = 1},
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local player = Player(cid)

    local bag = player:addItem(2000)
    local msg = {"You have recieved a bag containing: "}
    for i = 1, #rewards do
        local reward = rewards[i]
        local rand = math.random(100)
        if rand >= reward.chance then
            local item = bag:addItem(reward.id, reward.count)
            msg[#msg+1] = string.format("%s%s", (count == 1) and item:getArticle() or count, (reward.count == 1) and item:getName() or item:getPluralName())
        end
    end
    msg[#msg+1] = (#msg == 1 and "nothing." or ".")
    player:sendTextMessage(MESSAGE_INFO_DESCR, table.concat(msg))
    return true
end
 
Solution
Lua:
local rewards = {
    {id = xxxx, chance = yyyy, count = 1},
    {id = xxxx, chance = yyyy, count = 1},
    {id = xxxx, chance = yyyy, count = 1},
    {id = xxxx, chance = yyyy, count = 1},
}

function onUse(cid, item, fromPosition, target, toPosition)
    local player = Player(cid)
    local bag = player:addItem(2000)
    local msg = {"You have recieved a bag containing: "}
    for i = 1, #rewards do
        local reward = rewards[i]
        local rand = math.random(100)
        if rand >= reward.chance then
            local item = bag:addItem(reward.id, reward.count)
            msg[#msg+1] = string.format("%s%s", (count == 1) and item:getArticle() or count, (reward.count == 1) and item:getName() or item:getPluralName())
        end
    end
    msg[#msg+1] = (#msg == 1 and "nothing." or ".")
    player:sendTextMessage(MESSAGE_INFO_DESCR, table.concat(msg))
    return true
end
 
Back
Top