aboutsummaryrefslogtreecommitdiff
path: root/gamemode/ents/art_chest/sv_art_chest.lua
diff options
context:
space:
mode:
Diffstat (limited to 'gamemode/ents/art_chest/sv_art_chest.lua')
-rw-r--r--gamemode/ents/art_chest/sv_art_chest.lua58
1 files changed, 58 insertions, 0 deletions
diff --git a/gamemode/ents/art_chest/sv_art_chest.lua b/gamemode/ents/art_chest/sv_art_chest.lua
new file mode 100644
index 0000000..2eeea7b
--- /dev/null
+++ b/gamemode/ents/art_chest/sv_art_chest.lua
@@ -0,0 +1,58 @@
+local ENT = nrequire("sh_art_chest.lua")
+local inv = nrequire("inventory/inventory.lua")
+local track = nrequire("inventory/sv_invtracker.lua")
+
+--local invfuncs = include("../../../gamemode/shared/inventory_common.lua")
+function ENT:Initialize()
+ self.Openedby = {}
+ self:SetModel(self.Model or "models/props_junk/Rock001a.mdl")
+ self:PhysicsInit(SOLID_VPHYSICS)
+ self:SetMoveType(MOVETYPE_NONE)
+ self:SetSolid(SOLID_VPHYSICS)
+ self:SetCollisionGroup(COLLISION_GROUP_INTERACTIVE)
+ self:SetUseType(SIMPLE_USE)
+ local phys = self:GetPhysicsObject()
+ phys:EnableMotion(false)
+ phys:Sleep()
+
+ self.data = {
+ inventories = {}
+ }
+
+ local myinv = inv.CreateInventory(self.InvType or "Shaped Inventory")
+ myinv.Owner = self
+
+ timer.Simple(0, function()
+ myinv.id = self:GetCreationID()
+ self.data.inventories[myinv.id] = myinv
+ end) --Wait until the entity is initalized
+
+ self.Observers = {}
+end
+
+local uans = {"openchestinv", "closechestinv"}
+
+for k, v in pairs(uans) do
+ util.AddNetworkString(v)
+end
+
+net.Receive("closechestinv", function(ln, ply)
+ local chest = net.ReadEntity()
+ local obsid = chest.Observers[ply]
+ chest.data.inventories[chest:GetCreationID()]:RemoveObserver(obsid)
+ chest.Observers[ply] = nil
+end)
+
+--NOTE:Why is it important to allow a table to this argument?
+function ENT:SendInventory(towho)
+ local observer = track.MakeInventoryObserver(towho, self:GetCreationID())
+ local obsid = self.data.inventories[self:GetCreationID()]:AddObserver(observer)
+ self.Observers[towho] = obsid
+ track.NotifyPlayerOfInventory(towho, self.data.inventories[self:GetCreationID()])
+end
+
+function ENT:Use(ply)
+ self:SendInventory(ply)
+end
+
+scripted_ents.Register(ENT, "art_chest")