diff options
Diffstat (limited to 'gamemode/core/inventory')
| -rw-r--r-- | gamemode/core/inventory/inventory.lua | 4 | ||||
| -rw-r--r-- | gamemode/core/inventory/item.lua | 5 | ||||
| -rw-r--r-- | gamemode/core/inventory/sv_invtracker.lua | 28 |
3 files changed, 17 insertions, 20 deletions
diff --git a/gamemode/core/inventory/inventory.lua b/gamemode/core/inventory/inventory.lua index 5ff4c10..b96d168 100644 --- a/gamemode/core/inventory/inventory.lua +++ b/gamemode/core/inventory/inventory.lua @@ -46,6 +46,7 @@ ]] local inv = {} +local log = nrequire("log.lua") --Creates a partial copy of a table(tables are copied, functions are not) local function TableCopy(tbl) @@ -122,7 +123,7 @@ function inv.RegisterInventory(tbl) --assert(inventories[tbl.Name] == nil, -- string.format("Attempted to register 2 inventories with the same name: %q", tbl.Name)) if inventories[tbl.Name] ~= nil then - MsgC(Color(255,255,0),"Registering 2 inventories with the same name:" .. tbl.Name) + log.warn(string.format("Registered 2 inventories with the same name %q, overwriteing",tbl.Name)) end assert((tbl.AddObserver == nil and tbl.RemoveObserver == nil) or (tbl.AddObserver ~= nil and tbl.RemoveObserver ~= nil), @@ -131,6 +132,7 @@ function inv.RegisterInventory(tbl) SetDefaultObservers(tbl) end inventories[tbl.Name] = tbl + log.info("Registered inventory: " .. tbl.Name) --print("Registered inventory: " .. tbl.Name) end diff --git a/gamemode/core/inventory/item.lua b/gamemode/core/inventory/item.lua index a598fc2..80e2a88 100644 --- a/gamemode/core/inventory/item.lua +++ b/gamemode/core/inventory/item.lua @@ -18,6 +18,7 @@ Items may also have methods from one or more interfaces registered with RegisterInterface ]] +local log = nrequire("log.lua") local itm = {} local required_fields = { "Name","Serialize","DeSerialize" @@ -30,9 +31,9 @@ function itm.RegisterItem(tbl) end --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") + log.warn(string.format("Attempted to register 2 items with the same name: %q, overwriteing previous",tbl.Name)) else - MsgC(Color(0,255,0),"Registered Item " .. tbl.Name .. "\n") + log.info(string.format("Registered item %s",tbl.Name)) end items[tbl.Name] = tbl --print("Registered item: " .. tbl.Name) diff --git a/gamemode/core/inventory/sv_invtracker.lua b/gamemode/core/inventory/sv_invtracker.lua index ab39e41..537d61d 100644 --- a/gamemode/core/inventory/sv_invtracker.lua +++ b/gamemode/core/inventory/sv_invtracker.lua @@ -4,6 +4,7 @@ local inv = nrequire("inventory/inventory.lua") local itm = nrequire("item.lua") +local log = nrequire("log.lua") local track = {} for k,v in pairs({ @@ -33,30 +34,23 @@ end) topos ::table ]] net.Receive("art_RequestInvMove",function(len,ply) - print("ply",ply,"requested inv move") --Read the data from the net message local froment,toent = net.ReadEntity(),net.ReadEntity() local frominvid,toinvid = net.ReadUInt(32),net.ReadUInt(32) local frompos,topos = net.ReadTable(),net.ReadTable() + log.debug(string.format("ply %q requested inventory move from (%q,%d) to (%q,%d)",tostring(ply),tostring(froment),frominvid,tostring(toent),toinvid)) --Make sure the player is not stealing! assert(not (froment:IsPlayer() and toent:IsPlayer() and froment ~= toent), "Tried to move item between players!") - print("froment",froment) - print("froment.data:",froment.data) - print("froment.data.inventories",froment.data.inventories) - PrintTable(froment.data.inventories) - print("invid:",froment.data.inventories[frominvid]) + --Make sure the entity from has that inventory assert(froment.data ~= nil and froment.data.inventories ~= nil and froment.data.inventories[frominvid] ~= nil, "From entity did not have that inventory!") - print("toent",toent) - print("toent.data",toent.data) - print("toent.data.inventories",toent.data.inventories) - PrintTable(toent.data.inventories) - print("toinvid",toinvid) - print("toent.data.inventories[invid]",toent.data.inventories[toinvid]) + --Make sure the entity to has that inventory assert(toent.data ~= nil and toent.data.inventories ~= nil and toent.data.inventories[toinvid] ~= nil, "To entity did not have that inventory!") local frominv = froment.data.inventories[frominvid] local toinv = toent.data.inventories[toinvid] local item = frominv:Get(frompos) + --Make sure the frominv has an item at that pos assert(item ~= nil, "Could not find an item at that position!") + --Make sure it can fit in toinv assert(toinv:CanFitIn(topos,item), "Could not fit the item in that position!") --If we've gotten here without error, we're all good! Move the item! frominv:Remove(frompos) @@ -245,11 +239,11 @@ function track.SendPlayerData(ply) net.Send(ply) end -concommand.Add("artery_SendMeData",function(ply,cmd,args) - track.ClearInventories(ply) - track.GiveInventoryTo(ply,"Equipment") - track.SendPlayerData(ply) -end) +-- concommand.Add("artery_SendMeData",function(ply,cmd,args) +-- track.ClearInventories(ply) +-- track.GiveInventoryTo(ply,"Equipment") +-- track.SendPlayerData(ply) +-- end) concommand.Add("artery_ShowMyInventories",function(ply,cmd,args) PrintTable(ply.data.inventories) |
