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")