Advertisement
Guest User

Untitled

a guest
Jan 13th, 2015
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.52 KB | None | 0 0
  1.  
  2. addEventHandler("onPlayerJoin", root,
  3.     function ()
  4.         Backpack:create(source)
  5.     end
  6. )
  7.  
  8. addCommandHandler("put",
  9.     function (player, cmd, itemname, amount)
  10.         if not itemname or itemname:len() == 0 then
  11.             outputChatBox(("Syntax: /put <item> (optional: <amount>)"):format(itemname), player, 255, 100, 100)
  12.         elseif not Item.exists(itemname) then
  13.             outputChatBox(("* The item %q does not exist"):format(itemname), player, 255, 100, 100)
  14.         else
  15.             local backpack = Backpack(player)
  16.             amount = amount and tonumber(amount) or 1
  17.            
  18.             if backpack:addItem(Item(itemname), amount) then
  19.                 outputChatBox(("* Added %d %s to your backpack [Weight: %d]"):format(amount, itemname, backpack:getWeight()), player, 0, 255, 0)
  20.             else
  21.                 outputChatBox(("* Could not add %d %s to your backpack"):format(amount, itemname), player, 255, 100, 100)
  22.             end
  23.         end
  24.     end
  25. )
  26.  
  27. addCommandHandler("items",
  28.     function (player)
  29.         local items = Backpack(player):getItems(true)
  30.  
  31.         if #items == 0 then
  32.             outputChatBox("* You have no items in your backpack", player, 255, 100, 100)
  33.         else
  34.             outputChatBox("* Your backpack items:", player, 0, 255, 0)
  35.  
  36.             for index, slot in pairs(items) do
  37.                 outputChatBox(("  %dx %s (%s)"):format(slot.amount, slot.item:getName(), slot.item:getCategory()), player, 130, 130, 130)
  38.             end
  39.         end
  40.     end
  41. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement