local config = {
fromPosition = Position(1000, 1000, 7),
toPosition = Position(1100, 1100, 7),
rewards = {
{chance = {from = 0, to = 30.5}, message = 'You try to concentrate and your dream comes true. You wished for something cool.', itemId = 123, count = 2},
{chance = {from = 30.5, to = 60}, message = 'You try to concentrate and your dream comes true. You wished for something cool.', itemId = 123, count = 2},
{chance = {from = 60, to = 100}, message = 'You try to concentrate and your dream comes true. You wished for something cool.', itemId = 123, count = 2},
}
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
if not isInRange(player:getPosition(), config.fromPosition, config.toPosition) then
return false
end
local chance = math.random(0, 10000) / 100
for _, reward in ipairs(config.rewards) do
if chance >= reward.chance.from and chance < reward.chance.to then
player:addItem(reward.itemId, reward.count)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, reward.message)
item:remove(1)
return true
end
end
return true
end