Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function onUse(player, item, fromPosition, target, toPosition, isHotkey)
- if not item:isContainer() then
- return false
- end
- local uniqueId = item:getUniqueId()
- if uniqueId == 0 then
- return false
- end
- if player:getStorageValue(uniqueId) ~= -1 then
- player:sendTextMessage(MESSAGE_INFO_DESCR, "The " .. item:getName() .. " is empty.")
- return true
- end
- local reward = item:getItem(0)
- local stackable = reward:getType():isStackable()
- local weight = reward:getWeight()
- local name = reward:getName()
- if stackable then
- if reward:getCount() > 1 then
- name = reward:getCount() .. " " .. reward:getPluralName()
- else
- name = reward:getName()
- end
- end
- if reward:getArticle():len() > 0 and reward:getCount() <= 1 then
- name = reward:getArticle() .. " " .. name
- end
- if weight > player:getFreeCapacity() then
- local term = "it is"
- if stackable and reward:getCount() > 1 then
- term = "they are"
- end
- player:sendTextMessage(MESSAGE_INFO_DESCR, string.format("You have found %s. Weighing %d.%02d oz %s too heavy.", name, weight / 100, weight % 100, term))
- return true
- end
- -- give items
- for _, item in ipairs(item:getItems()) do
- local clone = item:clone()
- if player:addItemEx(clone) ~= RETURNVALUE_NOERROR then
- clone:remove()
- return false
- end
- end
- player:sendTextMessage(MESSAGE_INFO_DESCR, "You have found " .. name .. ".")
- player:setStorageValue(uniqueId, 1)
- return true
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement