Advertisement
Cavitt

Untitled

Feb 17th, 2012
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.67 KB | None | 0 0
  1.  
  2. Self.Count = function(itemid, container)
  3.     if(container)then -- count specific container
  4.         return Container.GetByName(container):CountItemsOfID(itemid) or 0
  5.     end
  6.    
  7.     local value = 0
  8.     local slots = {Self.Head, Self.Armor, Self.Legs, Self.Feet, Self.Amulet, Self.Weapon, Self.Ring, Self.Shield, Self.Ammo}
  9.    
  10.     for i = 1, #slots do -- count slots
  11.         local slot = slots[i]()
  12.         if(slot.id == itemid)then
  13.             value = value + math.max(slot.count, 1)
  14.         end
  15.     end
  16.    
  17.     if(container == nil)then -- count everything
  18.         local cont = Container.GetFirst()
  19.         while (cont:isOpen()) do
  20.             value = value + cont:CountItemsOfID(itemid)
  21.             cont = cont:GetNext()
  22.         end
  23.     end
  24.  
  25.     return value
  26. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement