Anonymous

Module:Sandbox/Items: Difference between revisions

From Melvor Idle
m
no edit summary
mNo edit summary
mNo edit summary
Tag: Undo
Line 68: Line 68:


function p.getItemByID(ID)
function p.getItemByID(ID)
--local result = Shared.clone(ItemData.Items[ID + 1])
local result = Shared.clone(ItemData.Items[ID + 1])
--if result ~= nil then
if result ~= nil then
-- result.id = ID
result.id = ID
--end
end
--return result
return result
return ItemData.Items[ID + 1]
end
end


function p.getItem(name)
function p.getItem(name)
--local result = nil
local result = nil
name = string.gsub(name, "%%27", "'")
name = string.gsub(name, "%%27", "'")
name = string.gsub(name, "'", "'")
name = string.gsub(name, "'", "'")
Line 83: Line 82:
local itemName = string.gsub(item.name, '#', '')
local itemName = string.gsub(item.name, '#', '')
if name == itemName then
if name == itemName then
return item
result = Shared.clone(item)
--result = Shared.clone(item)
--Make sure every item has an id, and account for Lua being 1-index
--Make sure every item has an id, and account for Lua being 1-index
--result.id = i - 1
result.id = i - 1
--break
break
end
end
end
end
--return result
return result
end
end


Line 98: Line 96:
for i, item in ipairs(ItemData.Items) do
for i, item in ipairs(ItemData.Items) do
if checkFunc(item) then
if checkFunc(item) then
--local newItem = Shared.clone(item)
local newItem = Shared.clone(item)
--newItem.id = i - 1
newItem.id = i - 1
itemCount = itemCount + 1
itemCount = itemCount + 1
result[itemCount] = item
result[itemCount] = newItem
end
end
end
end