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

TFS 0.X Action, box with luck to get item

roriscrave

Advanced OT User
Joined
Dec 7, 2011
Messages
1,188
Solutions
34
Reaction score
201
Hi guys, how are u?
I need one action, if u use a box, u can get some items, like this:

{ItemID,Chance %}
{ItemID2,Chance2 %}
{ItemID3,Chance3 %}
.
.
.

I use tibia 8.6 tfs 0.4
 
Lua:
local gifts = {
-- 1% - 10, 5% - 50, 10% - 100 , 100% - 1000
        {50, 14096, 1}, -- {percent, ID, count}
        {10, 2439, 1}
    }

function onUse(cid, item, frompos, item2, topos)

local item = {}
local reward = 0
local count = ""

    for i = 1, #gifts do
        item = gifts[i]
        if (math.random(0,999) < item[1]) then
            reward = item[2]
            subType = item[3]
            print(reward)
                if subType > 1 then
                    count = subType ..""
                else
                    count = "1"
                end
            break
        end
    end
  
    doRemoveItem(item2.uid, 1)
    doPlayerAddItem(cid, reward, subType)
    doSendMagicEffect(getCreaturePosition(cid), 29)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,"** You get: " .. count .."x " .. getItemNameById(reward) .. " from box!")
end
 
Hi guys, how are u?
I need one action, if u use a box, u can get some items, like this:

{ItemID,Chance %}
{ItemID2,Chance2 %}
{ItemID3,Chance3 %}
.
.
.

I use tibia 8.6 tfs 0.4
Get 1 random item or can get more then one at once?
Is there a chance to not get any item?
@Fresh
I'm not good at combinatorics, but I think that with you script you got chance:
Item 1: 5%
Item 2: 0.95% (1% of 95%)
Lose: 94.05% (rest)
With higher item chances, it goes even worse. You need to remember about that ,when configuring script or you need to rewrite it to sum all items up to 1000 and then choose one of them (or few) by random number.
 
Last edited:
Back
Top