blob: 2eeea7b553623b01f79c7065f0245046313d81cd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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")
|