local rewards = {
-- {{item_id, amount}, {item_id, amount}}
{{1111, 1}, {2222, 10}}, -- common
{{1111, 1}, {2222, 10}}, -- uncommon
{{1111, 1}, {2222, 10}} -- rare
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
local index = 1
local rand = math.random(1000)
if rand > 950 then
index = 3
elseif rand > 800 then
index = 2
end
rand = math.random(#rewards[index])
doPlayerAddItem(cid, rewards[index][rand][1], rewards[index][rand][2])
return true
end
local rewards = {
-- {{item_id, amount}, {item_id, amount}}
{{1111, 1}, {2222, 10}}, -- common
{{1111, 1}, {2222, 10}}, -- uncommon
{{1111, 1}, {2222, 10}} -- rare
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
local index = 1
local rand = math.random(1000)
if rand > 950 then
index = 3
elseif rand > 800 then
index = 2
end
rand = math.random(#rewards[index])
doPlayerAddItem(cid, rewards[index][rand][1], rewards[index][rand][2])
return true
end
local rewards = {
-- [min chance, max chance] = {item list here}
[{1, 10}] = {
{id = 123, count = {min = 1, max = 5}}
},
[{11, 100}] = {
{id = 123, count = {min = 1, max = 5}}
}
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local chance = math.random(100)
local rewardList = nil
for k, v in pairs(rewards) do
if k[1] >= chance and k[2] <= chance then
rewardList = v
break
end
end
if not rewardList then
print('no reward list specified for chance rolled: '.. chance)
return true
end
local reward = rewardList[math.random(#rewardList)]
player:addItem(reward.id, math.random(reward.count.min, reward.count.max))
return true
end
local config = {
rewards = {
[2160] = 1
},
}
function onThink(interval)
local players = {}
for _, player in ipairs(Game.getPlayers()) do
if not player:getGroup():getAccess() then
table.insert(players, player)
end
end
local c = #players
if c <= 0 then
return true
end
local winner = players[math.random(#players)]
local items = {}
for itemid, count in pairs(config.rewards) do
items[#items + 1] = itemid
end
local itemid = items[math.random(1000, #items)]
local amount = config.rewards[itemid]
winner:addItem(itemid, amount)
local it = ItemType(itemid)
local name = ""
if amount == 1 then
name = it:getArticle() .. " " .. it:getName()
else
name = amount .. " " .. it:getPluralName()
end
return true
end