zirra
Member
So I don't wanna try adding a bunch of codes hoping it works, I've searched for this and came up empty already. I want to add chance to certain items. like a 1% chance for one item and the rest equally random. I know this is probably something easy but I can't think of which way to do it. For ex; Item 11640 needs to have a much rarer probability. near impossible. while the others are all random with equal chance.
Code:
local items = {{2152, 10}, {2394, 100}, {2391, 37}, {2392, 4}, {11640, 1}, {11641, 1}}
local min_level = 20 --Minimum level to pick up the items in the chest.
local time = 1440 --how many minutes to recive reward.
local storage = 91838
function onUse(cid, item, frompos, item2, topos)
if getPlayerLevel(cid) >= min_level then
if getPlayerStorageValue(cid, storage) < os.time() then
local it = items[math.random(#items)]
doPlayerAddItem(cid, it[1], it[2])
doPlayerSendTextMessage(cid, 27, "You have received "..it[2].." "..getItemNameById(it[1])..". You can take your reward in "..time.." minutes.")
setPlayerStorageValue(cid, storage, os.time() + time * 60)
else
return doPlayerSendCancel(cid, "You have already received your reward for today.")
end
else
return doPlayerSendCancel(cid, "You do not have the required level to receive this reward ["..min_lv.."].")
end
return true
end