local storage_id = 43346

local rewards = {
    [43347] = {reward_id = 7406, reward_count = 1}, -- [chest uid] = {reward item id, reward item count},
    [43348] = {reward_id = 7380, reward_count = 1},
    [43349] = {reward_id = 7392, 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_EVENT_ADVANCE, "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