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

Box Give RadomItem with chance

legadoss

New Member
Joined
Jun 1, 2014
Messages
142
Reaction score
4
hey, i trying to create a box with giving item from table
Lua:
table {
[2160] = {chance = 1000}   -- 1%
[2152] = {chance = 2500}   -- 2,5% ............
....
...
...
..
}
rand = math.rand(1,100000)
if(rand <= chance) then
player:addItem(?,?)
end

can someone help? thanks
 
Solution
it will return 1 item?
Will give 1 random item from the list of items, if the random number chosen is less then or equal to the chance value.

-- Edit

Sorry, I should be more clear.

The script will choose a random item, then compare the random number against the chance value of the random item chosen.
There's no guarantee of an item.
something like this I guess
Lua:
local item_table = {
    -- {item_id, max_count, chance}
    {1111, 1, 1000},
    {2222, 2, 2500},
    {3333, 3, 7000}
}

local index = math.random(#item_table)
local rand = math.random(100000)
if rand <= item_table[index][3] then
    player:addItem(item_table[index][1], math.random(item_table[index][2]))
end
 
something like this I guess
Lua:
local item_table = {
    -- {item_id, max_count, chance}
    {1111, 1, 1000},
    {2222, 2, 2500},
    {3333, 3, 7000}
}

local index = math.random(#item_table)
local rand = math.random(100000)
if rand <= item_table[index][3] then
    player:addItem(item_table[index][1], math.random(item_table[index][2]))
end
it will return 1 item?
 
it will return 1 item?
Will give 1 random item from the list of items, if the random number chosen is less then or equal to the chance value.

-- Edit

Sorry, I should be more clear.

The script will choose a random item, then compare the random number against the chance value of the random item chosen.
There's no guarantee of an item.
 
Last edited:
Solution
Back
Top