diff options
Diffstat (limited to 'gamemode/inventorysystem/cl_common.lua')
| -rw-r--r-- | gamemode/inventorysystem/cl_common.lua | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/gamemode/inventorysystem/cl_common.lua b/gamemode/inventorysystem/cl_common.lua new file mode 100644 index 0000000..07fc786 --- /dev/null +++ b/gamemode/inventorysystem/cl_common.lua @@ -0,0 +1,59 @@ + +local com = {} + +--Displays a dropdown of options under the players mouse, if the option is clicked, does the function +--Requires a table of strings to functions, or strings to tables of strings to functions. +--Be careful not to make this a recursive table. +function com.CreateMenuFor(menu, tbl) + for k,v in pairs(tbl) do + if isfunction(v) then --This is a dead-end, add the menu + menu:AddOption(k,v) + else --Otherwise it should be a table, recursively call to create + local submenu = menu:AddSubMenu(k) + CreateMenuFor(submenu,v) + end + end +end + +function com.generatereceiver() + return function(self,panels,dropped,index,cx,cy) + if dropped then + local froment,toent = panels[1].info.owner,self.info.owner + local fromid,toid = panels[1].info.id,self.info.id + local frompos,topos = panels[1].info.pos,self.info.pos + local frominv,toinv = panels[1].info.inv,self.info.inv + print("Something was dropped on:",x,y) + PrintTable(panels) + print("froment:",froment) + print("toent:",toent) + print("fromid",fromid) + print("toid",toid) + print("frompos:",frompos) + PrintTable(panels[1].info.pos) + print("topos:",topos) + PrintTable(self.info.pos) + print("frominv",frominv) + print("toinv",toinv) + local item = frominv:Get(frompos) + print("item was", item) + --Fake remove the item, in case the position we want to move it to overlaps with where it is now. + frominv:Remove(frompos) + local cf = toinv:CanFitIn(topos,item) + frominv:Put(frompos,item) + print("canfit was:",cf) + if cf == true then + --Send the request + net.Start("art_RequestInvMove") + net.WriteEntity(froment) + net.WriteEntity(toent) + net.WriteUInt(fromid,32) + net.WriteUInt(toid,32) + net.WriteTable(frompos) + net.WriteTable(topos) + net.SendToServer() + end + end + end +end + +return com |
