local storage_id = 2000
local rewards = {
[11750] = {reward_id = 2494, reward_count = 1}, -- [chest uid] = {reward item id, reward item count},
[11751] = {reward_id = 2400, reward_count = 1},
[11752] = {reward_id = 2431, reward_count = 1},
[11753] = {reward_id = 2421, 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 reward = rewards[item.uid]
local reward_type = reward and ItemType(reward.reward_id)
if reward_type then
if player:addItem(reward.reward_id, reward.reward_count, false, 1, CONST_SLOT_WHEREEVER) then
player:sendTextMessage(MESSAGE_INFO_DESCR, "You have found a " .. reward_type:getName():lower() .. ".")
player:setStorageValue(storage_id, 1)
else
local weight = reward_type:getWeight()
player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found an item weighing ' .. weight / 100 .. ' oz it\'s too heavy or you do not have enough room.')
end
end
return true
end