diff options
Diffstat (limited to 'gamemode/inventorysystem/cl_common.lua')
| -rw-r--r-- | gamemode/inventorysystem/cl_common.lua | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/gamemode/inventorysystem/cl_common.lua b/gamemode/inventorysystem/cl_common.lua index 559c8f0..bf9fb6f 100644 --- a/gamemode/inventorysystem/cl_common.lua +++ b/gamemode/inventorysystem/cl_common.lua @@ -2,6 +2,7 @@ A bunch of functions that a lot of inventories have in common, dragged out here so bugfixing is easier ]] +local log = nrequire("log.lua") local com = {} --Displays a dropdown of options under the players mouse, if the option is clicked, does the function @@ -20,6 +21,26 @@ function com.CreateMenuFor(menu, tbl) end end +-- Move an item internally between two inventories +function com.MoveItem(f,frominv,toinv) + local frompos = frominv:Has(f) + assert(frompos,string.format("Failed to find item %q in inventory %q",tostring(f),frominv.Name)) + log.debug("Returned position:" .. frompos[1]) + local item = frominv:Get(frompos) + assert(item,string.format("Failed to get item %q out of %q",tostring(f),frominv.Name)) + local topos = toinv:FindPlaceFor(item) + assert(topos,string.format("Failed to find a place in %q to put a %q",toinv.Name,tostring(f))) + + net.Start("art_RequestInvMove") + net.WriteEntity(LocalPlayer()) + net.WriteEntity(LocalPlayer()) + net.WriteUInt(frominv.id,32) + net.WriteUInt(toinv.id,32) + net.WriteTable(frompos) + net.WriteTable(topos) + net.SendToServer() +end + function com.generatereceiver() return function(self,panels,dropped,index,cx,cy) if dropped then |
