local items = { --The sum of all % must be 100
--{itemId, count, win %},
{1111, 1, 10},
{2222, 1, 40},
{3333, 1, 50}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
local chance = math.random(1,100)
for i = 1, #items, 1 do
if(chance < items[i][3]) then
local itemInfo = getItemInfo(items[i][1])
doPlayerAddItem(cid, items[i][1], items[i][2])
if(items[i][2] == 1) then
itemInfo = itemInfo.article .. " " .. itemInfo.name
else
itemInfo = items[i][2] .. " " .. itemInfo.plural
end
doPlayerSendTextMessage(cid, 25, "You have received " .. itemInfo .. ".")
doRemoveItem(item.uid)
return true
else
chance = chance - items[i][3]
end
end
--This should never happen if done correctly!
doPlayerSendTextMessage(cid, 25, "You failed to open the box.")
return false
end