Facebook
From Commodious Macaw, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 68
  1. local plyMeta = FindMetaTable( "Player" )        
  2.     function plyMeta:AddInventoryItem(ent, count)
  3.         local eq = loadData(self,"Inventory")  
  4.         if eq == nil then
  5.             eq = {}
  6.             for i=1,16 do
  7.                 eq[i] = {}
  8.                 eq[i].isOccupied = false
  9.                 eq[i].Count = 0
  10.                 eq[i].Name = "unknown"
  11.                 eq[i].ItemClass = "unknown"
  12.                 eq[i].WeaponClass = "unknown"
  13.                 eq[i].SingleWeight = 0
  14.             end
  15.         end
  16.         local totalWeight = getTotalWeight(eq)
  17.         for i, slot in ipairs(eq) do
  18.             if ent.StackSize == nil then ent.StackSize = 1 end
  19.             if slot.isOccupied == false or (ent.StackSize > slot.Count and slot.ItemClass == ent:GetClass()) then
  20.                 if ent.Weight ~= nil then
  21.                     slot.SingleWeight = ent.Weight
  22.                 else
  23.                     slot.SingleWeight = 1
  24.                 end
  25.                 if (slot.SingleWeight + totalWeight) <= getMaxWeight(self, "Inventory") then
  26.                     slot.isOccupied = true
  27.                     if ent.Name ~= nil then slot.Name = ent.Name else
  28.                         slot.Name = ent:GetClass()
  29.                     end
  30.                     slot.ItemClass = ent:GetClass()
  31.                     slot.Count = slot.Count + 1
  32.                     slot.Model = ent:GetModel()
  33.                     slot.MaxStack = ent.StackSize
  34.                     if slot.ItemClass == "spawned_weapon" then  
  35.                         slot.WeaponClass = ent:GetWeaponClass()
  36.                     else
  37.                         slot.WeaponClass = nil
  38.                     end  
  39.                     saveData(self, eq,"Inventory")
  40.                     if ent:GetClass() == "spawned_weapon" and ent:Getamount() > 1 then
  41.                         ent:Setamount(ent:Getamount()-1)
  42.                     else
  43.                         ent:Remove()
  44.                     end
  45.                     self:EmitSound(InventoryConfig.Sounds.pickUp)
  46.                     return
  47.                 else
  48.                     showNotification(self, InventoryConfig.Messages.tooHeavy)
  49.                     return
  50.                 end
  51.             end  
  52.         end
  53.         -- no space
  54.         showNotification(ply, InventoryConfig.Messages.noSpace)
  55.     end