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

Percentage chance?

bybbzan

mapper
Joined
Aug 4, 2012
Messages
809
Solutions
2
Reaction score
135
Location
Sweden
Hello guys!

I need some help with this script, is it possible to make it in percentage chance of getting certain items?

Like:
30% to get itemid xxxx
10% to get itemid xxxx
and so on.

Code:
local items = {9969, 9932, 7735, 22409, 22415, 22403, 2352, 21696, 22424, 21707, 21706, 21692, 21725}
function onUse(cid, item, fromPosition, itemEx, toPosition)
local random = math.random(1, #items)
local name = getItemName(items[random])
doPlayerAddItem(cid, donations[random])
doCreatureSay(cid, "Congratz. Enjoy your "..name, TALKTYPE_ORANGE_1)
doSendMagicEffect(getPlayerPosition(cid), 27)
doRemoveItem(item.uid)
end
 
Quickly written code

Code:
local donations = {9969, 9932, 7735, 22409, 22415, 22403, 2352, 21696, 22424, 21707, 21706, 21692, 21725}
function onUse(cid, item, fromPosition, itemEx, toPosition)
local random = math.random(1, 100) -- we randomly number from 1-100
if (rand <= 10) then  -- if we randomly 1-10 (10% chance)
local name = getItemName(items[1]) -- get item name 1 (id 9969)
doPlayerAddItem(cid, donations[1]) -- give player item from array 1 (id9969)
doCreatureSay(cid, "Congratz. Enjoy your "..name, TALKTYPE_ORANGE_1)
doSendMagicEffect(getPlayerPosition(cid), 27)
doRemoveItem(item.uid)
elseif (rand > 10) and (rand <= 20) then -- if we randomly 11-20 (10% chance)
local name = getItemName(items[2]) -- get item name 2 (id 9932)
doPlayerAddItem(cid, donations[2]) -- give player item from array 2 (id9932)
doCreatureSay(cid, "Congratz. Enjoy your "..name, TALKTYPE_ORANGE_1)
doSendMagicEffect(getPlayerPosition(cid), 27)
doRemoveItem(item.uid)
elseif (rand > 30) and (rand <= 50) then -- if we randomly 31-50 (30% chance)
local name = getItemName(items[3]) -- get item name 3 (id 7735)
doPlayerAddItem(cid, donations[3]) -- give player item from array 2 (7735)
doCreatureSay(cid, "Congratz. Enjoy your "..name, TALKTYPE_ORANGE_1)
doSendMagicEffect(getPlayerPosition(cid), 27)
doRemoveItem(item.uid)


...
...

end
end
 
Last edited:
We randomly select a number from 1 - 100
And set the range.

Code:
if (rand <= 10) then -- if we randomly 1-10 (10% chance)
If the number is less than or equal to.
For example, If you will draw the number 1,2,3,4,5,6,7,8,9,10 - We give the object from the array at index 1


Code:
elseif (rand > 30) and (rand <= 50) then -- if we randomly 31-50 (30% chance)
If draws 31,32,33,34,35,36, [...] 47,48,49, 50

then we give player item 3 from array.

Code:
doPlayerAddItem(cid, donations[3]) -- give player item from array 3  (7735)
 
@bybbzan

U want give a more item in at one time?


You want to have every item separately chances being drawn. So as the monsters loot in Tibia?

Or you want to give away a 100% chance.

Item No. 1 - 10% from 90% left
Item No. 1 - 25% from 65% left
Item No. 1 - 5% from 60% left
 
@kamioool @Ninja

I thought it could be like this.. that i could set them into groups. like

local percentage
10% (itemid xxx), (itemid xxx),
20% (itemid xxx), (itemid xxx),
30% (itemid xxx), (itemid xxx),

So that you could add items into the percentage tables or something.
So that a very rare item could be under 10%, so its harder to get.
 
Last edited:
Back
Top