God Mythera
Veteran OT User
data/actions/actions.xml
Code:
<action itemid="15515" script="other/barofgold.lua"/>
data/actions/scripts/barofgold.lua
Code:
local config = {
{ rate = 1, item = 2152, count = { min = 5, max = 25 }}
}
local sumOfRate = 0
for i,v in ipairs(config) do
sumOfRate = sumOfRate + v.rate
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You have received some gold.")
local rand = math.random(1, sumOfRate)
local subSum = 0
local exactItem = nil
for i,v in ipairs(config) do
if (subSum > rand) then
if (i > 1) then
exactItem = i-1
end
break
end
subSum = subSum + v.rate
if (subSum >= rand) then
exactItem = i
break
end
end
if (config[exactItem].count.const ~= nil) then
doPlayerAddItem(cid, config[exactItem].item, config[exactItem].count.const)
else
doPlayerAddItem(cid, config[exactItem].item, math.random(config[exactItem].count.min, config[exactItem].count.max))
end
doRemoveItem(item.uid, 1)
end