Lua:
local storage_id = 2545
local random_rewards = {
[1] = {chest_uid = 1577, reward_id = 14282, reward_count = 1},
[2] = {chest_uid = 1577, reward_id = 14361, reward_count = 1},
[3] = {chest_uid = 1577, reward_id = 14358, reward_count = 1},
[4] = {chest_uid = 1577, reward_id = 14360, reward_count = 1},
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local storage = player:getStorageValue(storage_id)
if storage > 0 then
return player:sendTextMessage(MESSAGE_INFO_DESCR, "It is empty.")
end
local randoms = {}
for i = 1, #random_rewards do
if random_rewards[i].chest_uid == item.uid then
randoms[#randoms + 1] = random_rewards[i]
end
end
local bag = Game.createItem(1987)
bag:addItem(reward.reward_id, reward.reward_count)
local random_num = math.random(1, #randoms)
bag:addItem(randoms[random_num].reward_id, randoms[random_num].reward_count)
if player:addItemEx(bag) then
player:sendTextMessage(MESSAGE_INFO_DESCR, "You have found a bag.")
player:setStorageValue(storage_id, 1)
else
local weight = bag:getWeight()
player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a bag weighing ' .. weight / 100 .. ' oz it\'s too heavy or you do not have enough room.')
end
return true
end