Advertisement
poopman123

ClientSideInventorySystem

Nov 14th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.61 KB | None | 0 0
  1. function inventory:client_updateSlot(i,id,amt)
  2.     --print("sending")
  3.     Event:FireClient(self.plyr,"UPDATESLOT",i,id,amt)
  4. end
  5.  
  6. function inventory:client_updateSize(size)
  7.    
  8. end
  9.  
  10. function inventory:client_getContents()
  11.     return self.slots
  12. end
  13.  
  14. function inventory.new(plyr)
  15.     local i = {}
  16.     setmetatable(i,inventory)
  17.     i.plyr = plyr
  18.     i.slots = {}
  19.     i.size = 10 -- number of slots
  20.     return i
  21. end
  22. -- way to interact with all player inventories for all server
  23. inventoryHandler = {}
  24. -- inventory handler data
  25. inventoryHandler.PlayerInventories = {}
  26. -- inventory handler functions
  27. function inventoryHandler:GetInventory(plyr)
  28.     return self.PlayerInventories[plyr] or warn("Could not find inventory for player upon server request")
  29. end
  30.  
  31. function inventoryHandler:GiveClientContents(plyr)
  32.     local inventory = self:GetInventory(plyr)
  33.     if inventory then
  34.         return inventory.slots
  35.     end
  36. end
  37.  
  38. function inventoryHandler:GiveClientInfo(plyr)
  39.     local inventory = self:GetInventory(plyr)
  40.     if inventory then
  41.         return inventory.slots,inventory.size
  42.     end
  43. end
  44.  
  45. function inventoryHandler:NewPlayer(plyr)
  46.     local i = inventory.new(plyr)
  47.     self.PlayerInventories[plyr] = i
  48.     return i
  49. end
  50.  
  51. function inventoryHandler:RemovePlayer(plyr)
  52.     self.PlayerInventories[plyr] = nil
  53. end
  54.  
  55. function inventoryHandler.FunctionInvoke(plyr,req)
  56.     print("invoked")
  57.     if req == "REQCONTENT" then
  58.         return inventoryHandler:GiveClientContents(plyr)
  59.     elseif req == "REQINFO" then
  60.         return inventoryHandler:GiveClientInfo(plyr)
  61.     end
  62. end
  63.  
  64. function inventoryHandler:RemoteInit()
  65.     Function.OnServerInvoke = self.FunctionInvoke
  66. end
  67.  
  68. return inventoryHandler
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement