Added subType for Player:getItem/getItems.

This commit is contained in:
BenDol 2014-04-20 07:45:10 +12:00
parent 65d556ef4e
commit 06855dd1de
1 changed files with 9 additions and 22 deletions

View File

@ -99,37 +99,24 @@ function Player:dismount()
end end
end end
function Player:getItem(itemid) function Player:getItem(itemId, subType)
for i=InventorySlotFirst,InventorySlotLast do return g_game.findPlayerItem(itemId, subType or -1)
local item = self:getInventoryItem(i)
if item and item:getId() == itemid then
return item
end
end
for i, container in pairs(g_game.getContainers()) do
for j, item in pairs(container:getItems()) do
if item:getId() == itemid then
item.container = container
return item
end
end
end
return items
end end
function Player:getItems(itemid) function Player:getItems(itemId, subType)
local subType = subType or -1
local items = {} local items = {}
for i=InventorySlotFirst,InventorySlotLast do for i=InventorySlotFirst,InventorySlotLast do
local item = self:getInventoryItem(i) local item = self:getInventoryItem(i)
if item and item:getId() == itemid then if item and item:getId() == itemId and (subType == -1 or item:getSubType() == subType) then
table.insert(items, item) table.insert(items, item)
end end
end end
for i, container in pairs(g_game.getContainers()) do for i, container in pairs(g_game.getContainers()) do
for j, item in pairs(container:getItems()) do for j, item in pairs(container:getItems()) do
if item:getId() == itemid then if item:getId() == itemId and (subType == -1 or item:getSubType() == subType) then
item.container = container item.container = container
table.insert(items, item) table.insert(items, item)
end end
@ -138,8 +125,8 @@ function Player:getItems(itemid)
return items return items
end end
function Player:getItemsCount(itemid) function Player:getItemsCount(itemId)
local items, count = self:getItems(itemid), 0 local items, count = self:getItems(itemId), 0
for i=1,#items do for i=1,#items do
count = count + items[i]:getCount() count = count + items[i]:getCount()
end end