aboutsummaryrefslogtreecommitdiff
path: root/gamemode/core/inventory/item.lua
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2017-05-20 11:37:23 -0400
committerAlexander Pickering <alexandermpickering@gmail.com>2017-05-20 11:37:23 -0400
commitc6698dad925e75ffd2ca2f2e30a595d4ce48d240 (patch)
tree226338dc7ee26a6316951554cf953112ba072c76 /gamemode/core/inventory/item.lua
parent9e0537b0aa417e88a6a61238484ddcef74080ae0 (diff)
downloadartery-c6698dad925e75ffd2ca2f2e30a595d4ce48d240.tar.gz
artery-c6698dad925e75ffd2ca2f2e30a595d4ce48d240.tar.bz2
artery-c6698dad925e75ffd2ca2f2e30a595d4ce48d240.zip
Massive changes I guess
Diffstat (limited to 'gamemode/core/inventory/item.lua')
-rw-r--r--gamemode/core/inventory/item.lua31
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