aboutsummaryrefslogtreecommitdiff
path: root/gamemode/core/inventory
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
parent9e0537b0aa417e88a6a61238484ddcef74080ae0 (diff)
downloadartery-c6698dad925e75ffd2ca2f2e30a595d4ce48d240.tar.gz
artery-c6698dad925e75ffd2ca2f2e30a595d4ce48d240.tar.bz2
artery-c6698dad925e75ffd2ca2f2e30a595d4ce48d240.zip
Massive changes I guess
Diffstat (limited to 'gamemode/core/inventory')
-rw-r--r--gamemode/core/inventory/inventory.lua20
-rw-r--r--gamemode/core/inventory/item.lua31
-rw-r--r--gamemode/core/inventory/sv_invtracker.lua13
3 files changed, 40 insertions, 24 deletions
diff --git a/gamemode/core/inventory/inventory.lua b/gamemode/core/inventory/inventory.lua
index 6b6f6f4..62e4819 100644
--- a/gamemode/core/inventory/inventory.lua
+++ b/gamemode/core/inventory/inventory.lua
@@ -85,8 +85,8 @@ local function SetDefaultObservers(tbl)
local oldput,oldremove = tbl.Put,tbl.Remove
tbl.Put = function(self,position,item)
for k,v in pairs(self.observers) do
- print("Calling put on observer:")
- PrintTable(v)
+ --print("Calling put on observer:")
+ --PrintTable(v)
v:Put(position,item)
end
oldput(self,position,item)
@@ -120,20 +120,20 @@ function inv.RegisterInventory(tbl)
string.format("Attempted to register inventory with field %q of type %q when it should have been %q",v[1],type(tbl[v[1]]),v[2]))
end
assert(inventories[tbl.Name] == nil,
- "Attempted to register 2 inventories with the same name:" .. tbl.Name)
+ string.format("Attempted to register 2 inventories with the same name: %q", tbl.Name))
assert((tbl.AddObserver == nil and tbl.RemoveObserver == nil) or
(tbl.AddObserver ~= nil and tbl.RemoveObserver ~= nil),
- "AddObserver and RemoveObserver must be defined in pairs")
+ "AddObserver and RemoveObserver must be defined in pairs")
if tbl.AddObserver == nil then
SetDefaultObservers(tbl)
end
inventories[tbl.Name] = tbl
- print("Registered inventory: " .. tbl.Name)
+ --print("Registered inventory: " .. tbl.Name)
end
--Create an inventory
function inv.CreateInventory(name)
- print("Createing inventory", name)
+ --print("Createing inventory", name)
assert(inventories[name] ~= nil, string.format("Tried to create a copy of inventory that does not exist:%s\nValid inventories are:\n\t%s",name,table.concat(table.GetKeys(inventories),"\n\t")))
local ret = TableCopy(inventories[name])
ret.observers = {}
@@ -143,11 +143,11 @@ end
--Recreates an inventory from data
function inv.CreateInventoryFromData(name,data)
local tinv = inv.CreateInventory(name)
- print("tinv was", tinv)
- PrintTable(tinv)
+ --print("tinv was", tinv)
+ --PrintTable(tinv)
tinv:DeSerialize(data)
- print("is now",tinv)
- PrintTable(tinv)
+ --print("is now",tinv)
+ --PrintTable(tinv)
return tinv
end
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
diff --git a/gamemode/core/inventory/sv_invtracker.lua b/gamemode/core/inventory/sv_invtracker.lua
index 47dd164..56407e2 100644
--- a/gamemode/core/inventory/sv_invtracker.lua
+++ b/gamemode/core/inventory/sv_invtracker.lua
@@ -246,25 +246,26 @@ function track.SendPlayerData(ply)
net.Send(ply)
end
-concommand.Add("SendMeData",function(ply,cmd,args)
+concommand.Add("artery_SendMeData",function(ply,cmd,args)
track.ClearInventories(ply)
track.GiveInventoryTo(ply,"Equipment")
track.SendPlayerData(ply)
end)
-concommand.Add("ShowMyInventories",function(ply,cmd,args)
+concommand.Add("artery_ShowMyInventories",function(ply,cmd,args)
PrintTable(ply.data.inventories)
end)
-concommand.Add("AddInventory",function(ply,cmd,args)
+concommand.Add("artery_AddInventory",function(ply,cmd,args)
track.GiveInventoryTo(ply,args[1])
end)
-concommand.Add("GiveItem",function(ply,cmd,args)
+concommand.Add("artery_GiveItem",function(ply,cmd,args)
xpcall(function()
ply:GiveItem(itm.GetItemByName(args[1]))
- end,function()
- print("Could not find a position to put that in!")
+ end,function(err)
+ print("Could not give that item!:")
+ print(err)
end)
end)