diff options
Diffstat (limited to 'gamemode/core/inventory/item.lua')
| -rw-r--r-- | gamemode/core/inventory/item.lua | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/gamemode/core/inventory/item.lua b/gamemode/core/inventory/item.lua index 103da7f..a13efa9 100644 --- a/gamemode/core/inventory/item.lua +++ b/gamemode/core/inventory/item.lua @@ -23,14 +23,19 @@ local required_fields = { "Name","Serialize","DeSerialize" } -local items = {} --Master table of all item prototypes +local items = items or {} --Master table of all item prototypes function itm.RegisterItem(tbl) for k,v in pairs(required_fields) do assert(tbl[v] ~= nil, string.format("Attempted to register item without field %q",v)) end - assert(items[tbl.Name] == nil, string.format("Attempted to register 2 items with the same name %q",tbl.Name)) + --assert(items[tbl.Name] == nil, string.format("Attempted to register 2 items with the same name %q",tbl.Name)) + if items[tbl.Name] ~= nil then + MsgC(Color(255,255,0),"WARNING: attemtpted to register 2 items with the same name " .. tbl.Name .. "\n") + else + MsgC(Color(0,255,0),"Registered Item " .. tbl.Name .. "\n") + end items[tbl.Name] = tbl - print("Registered item: " .. tbl.Name) + --print("Registered item: " .. tbl.Name) end function itm.GetItemByName(name) @@ -49,11 +54,23 @@ function itm.GetItemFromData(name,data) return items[name]:DeSerialize(data) end +local function printitems() + local tbl = {} + for k,v in pairs(items) do + tbl[#tbl + 1] = k + end + print(table.concat(tbl,"\n")) +end + --Must be called in a coroutine. function itm.DeriveItem(tbl,name) + print("Attempting to derive item",name) while items[name] == nil do + print("it dosen't exist yet, items are") + printitems() coroutine.yield() end + print(name,"exists!") --Create a flywieght copy local ret = tbl local mt = { @@ -64,10 +81,8 @@ function itm.DeriveItem(tbl,name) setmetatable(ret,mt) end -concommand.Add("art_printitems",function() - for k,v in pairs(items) do - print(k) - end -end) +hook.Call("artery_include_items") + +concommand.Add("art_printitems",printitems) return itm |
