Advertisement
Guest User

Untitled

a guest
Oct 25th, 2021
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.44 KB | None | 0 0
  1. function onUse(player, item, fromPosition, target, toPosition, isHotkey)
  2.     if not item:isContainer() then
  3.         return false
  4.     end
  5.  
  6.     local uniqueId = item:getUniqueId()
  7.     if uniqueId == 0 then
  8.         return false
  9.     end
  10.  
  11.     if player:getStorageValue(uniqueId) ~= -1 then
  12.         player:sendTextMessage(MESSAGE_INFO_DESCR, "The " .. item:getName() .. " is empty.")
  13.         return true
  14.     end
  15.  
  16.     local reward = item:getItem(0)
  17.     local stackable = reward:getType():isStackable()
  18.     local weight = reward:getWeight()
  19.     local name = reward:getName()
  20.  
  21.     if stackable then
  22.         if reward:getCount() > 1 then
  23.             name = reward:getCount() .. " " .. reward:getPluralName()
  24.         else
  25.             name = reward:getName()
  26.         end
  27.     end
  28.    
  29.     if reward:getArticle():len() > 0 and reward:getCount() <= 1 then
  30.         name = reward:getArticle() .. " " .. name
  31.     end
  32.  
  33.     if weight > player:getFreeCapacity() then
  34.         local term = "it is"
  35.         if stackable and reward:getCount() > 1 then
  36.             term = "they are"
  37.         end
  38.         player:sendTextMessage(MESSAGE_INFO_DESCR, string.format("You have found %s. Weighing %d.%02d oz %s too heavy.", name, weight / 100, weight % 100, term))
  39.         return true
  40.     end
  41.  
  42.     -- give items
  43.     for _, item in ipairs(item:getItems()) do
  44.         local clone = item:clone()
  45.         if player:addItemEx(clone) ~= RETURNVALUE_NOERROR then
  46.             clone:remove()
  47.             return false
  48.         end
  49.     end
  50.  
  51.     player:sendTextMessage(MESSAGE_INFO_DESCR, "You have found " .. name .. ".")
  52.     player:setStorageValue(uniqueId, 1)
  53.     return true
  54. end
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement