--[[
- Set each chest with a different uid, and register them all in actions.xml
- Give each chest the same aid and this is used for the storage value
- Place the item you want the chest to give inside using rme, bags with items will work as well
- This script is reusable for another quests with a different action id
NOTE: Be careful not to use the action id elsewhere besides the quest chests
]]
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
if player:getStorageValue(item.actionid) > 0 then
return player:sendTextMessage(MESSAGE_INFO_DESCR, "It is empty.")
end
local reward = item:getItem(0):clone()
local playerCap = player:getFreeCapacity()
local itemType = reward:getType()
local count = reward:getCount()
local article = count > 1 and count or "a"
local name = count > 1 and reward:getPluralName() or itemType:getName()
if playerCap >= reward:getWeight() then
player:addItemEx(reward)
player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found ' .. article .. ' ' .. name .. '.')
player:setStorageValue(item.actionid, 1)
else
player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found ' .. article .. ' ' .. name .. ' weighing ' .. reward:getWeight() / 100 .. ' oz it\'s too heavy.')
end
return true
end