aboutsummaryrefslogtreecommitdiff
path: root/gamemode/core/inventory
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2018-07-15 19:57:27 -0400
committerAlexander Pickering <alexandermpickering@gmail.com>2018-07-15 19:57:27 -0400
commit534103be54a129d8255988fc1e75a21a63c6021f (patch)
treec172b0884b4ca26452c5a74f5033b3b1526b6e3a /gamemode/core/inventory
parent34d9ae7c4f4176fa9a943e9c2776afc32a867163 (diff)
downloadartery-534103be54a129d8255988fc1e75a21a63c6021f.tar.gz
artery-534103be54a129d8255988fc1e75a21a63c6021f.tar.bz2
artery-534103be54a129d8255988fc1e75a21a63c6021f.zip
Finished gather quest arcs
Finished base quest system, and added "Gather" arcs, where players gather a certain number of a certain item.
Diffstat (limited to 'gamemode/core/inventory')
-rw-r--r--gamemode/core/inventory/inventory.lua4
-rw-r--r--gamemode/core/inventory/sv_invtracker.lua22
2 files changed, 23 insertions, 3 deletions
diff --git a/gamemode/core/inventory/inventory.lua b/gamemode/core/inventory/inventory.lua
index 52443a8..c7cdc9a 100644
--- a/gamemode/core/inventory/inventory.lua
+++ b/gamemode/core/inventory/inventory.lua
@@ -183,6 +183,10 @@ function inv.CreateInventoryFromData(name,data,owner)
return ret
end
+--- Prints all inventories
+-- Prints all inventories known to the game
+--@usage artery_printinventories
+--@concommand artery_printinventories
concommand.Add("artery_printinventories", function(ply,cmd,args)
PrintTable(inventories)
end)
diff --git a/gamemode/core/inventory/sv_invtracker.lua b/gamemode/core/inventory/sv_invtracker.lua
index 8795d2a..ed5da4a 100644
--- a/gamemode/core/inventory/sv_invtracker.lua
+++ b/gamemode/core/inventory/sv_invtracker.lua
@@ -187,6 +187,7 @@ end
--@tparam string data The data to deserialize the inventory with
--@tparam table|nil higharchy The spot in the higharchy to place the inventory.
function track.GiveInventoryWithData(ply,name,data,higharchy)
+ log.debug(string.format("Giving %s a %q inventory with data: %s",ply:Nick(),name,data))
local hi = higharchy or {}
local i = inv.CreateInventoryFromData(name,data,ply)
local nid = #ply.data.inventories + 1
@@ -234,15 +235,27 @@ function plymeta:RemoveItem(tbl)
return item
end
+---Places an item in a player's inventory
+-- Puts an item in a specific position in a specific inventory for a player
+--@metamethod player:PutItem(location,item)
+--@tparam table loc The location to put the item (returned by plymeta:HasItem())
+function plymeta:PutItem(loc,item)
+ local nid = loc[1]
+ local pos = loc[2]
+ self.data.inventories[nid]:Put(pos,item)
+end
+
---A shortcut for giving an item to a player.
-- Gives an item to a player
--@metamethod player:GiveItem(tbl)
--@param itemtbl tbl The item to give the player
--@raises "Uanble to find place to put item" Raises an exception if we cannot find a location to put the item.
function plymeta:GiveItem(tbl)
+ assert(type(tbl) == "table", "Attempted to give a player an item that was not a table:" .. tostring(tbl))
for k,v in pairs(self.data.inventories) do
local p = v:FindPlaceFor(tbl)
if type(p) == "table" then
+ log.debug("Found inventory that would take item:" .. v.Name)
v:Put(p,tbl)
return
else
@@ -294,17 +307,19 @@ function(ply,cmd,args)
end)
---Gives an inventory to a player.
--- Gives a new inventory to a player ![Requires admin](./req_admin)
+-- Gives a new inventory to a player
--@usage artery_AddInventory <inventory name>
--@concommand artery_AddInventory
--@reqadmin
+--@tparam string invname The name of the inventory
+--@see @{inventory.artery_printinventories}
concommand.Add("artery_AddInventory",function(ply,cmd,args)
if not ply:IsAdmin() then return end
track.GiveInventoryTo(ply,args[1])
end)
---Gives an item to the player.
--- Gives a new item to the player ![Requires admin](./req_admin)
+-- Gives a new item to the player
--@usage artery_GiveItem <item name>
--@concommand artery_GiveItem
--@reqadmin
@@ -313,7 +328,8 @@ concommand.Add("artery_GiveItem",function(ply,cmd,args)
xpcall(function()
ply:GiveItem(itm.GetItemByName(args[1]))
end,function(err)
- print("Could not give that item!:", err)
+ log.debug("Could not give that item!:" .. err)
+ log.debug(debug.traceback())
end)
end)