17,030
edits
m (getItems: Allow returning IDs only) |
m (Revert to previous revision) |
||
Line 58: | Line 58: | ||
function p.getItemByID(ID) | function p.getItemByID(ID) | ||
local result = Shared.clone(ItemData.Items[ID + 1]) | |||
if result ~= nil then | |||
result.id = ID | |||
end | |||
return result | |||
end | end | ||
Line 68: | Line 72: | ||
for i, item in pairs(ItemData.Items) do | for i, item in pairs(ItemData.Items) do | ||
local itemName = string.gsub(item.name, '#', '') | local itemName = string.gsub(item.name, '#', '') | ||
if (name == itemName) then | if(name == itemName) then | ||
result = Shared.clone(item) | |||
--Make sure every item has an id, and account for Lua being 1-index | |||
result.id = i - 1 | |||
break | |||
end | |||
end | end | ||
return result | |||
end | end | ||
function p.getItems(checkFunc | function p.getItems(checkFunc) | ||
local result = {} | local result = {} | ||
for i, item in pairs(ItemData.Items) do | for i, item in pairs(ItemData.Items) do | ||
if checkFunc(item) then | if checkFunc(item) then | ||
local newItem = Shared.clone(item) | |||
newItem.id = i - 1 | |||
table.insert(result, newItem) | |||
end | end | ||
end | end |