--[[ A bunch of functions that a lot of inventories have in common, dragged out here so bugfixing is easier ]] 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) elseif istable(v) then --Otherwise it should be a table, recursively call to create local submenu = menu:AddSubMenu(k) CreateMenuFor(submenu,v) else error("I got wanted to make a menu for something not a function or a table:" + type(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 --Do nothing if we don't actually want to move anything anywhere local posequal = true if (froment ~= toent) or (fromid ~= toid) or (frominv ~= toinv) then posequal = false end if posequal then for k,v in pairs(frompos) do if topos[k] ~= v then posequal = false break end end end if posequal then return end local item = frominv:Get(frompos) --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) 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