aboutsummaryrefslogtreecommitdiff
path: root/gamemode
diff options
context:
space:
mode:
Diffstat (limited to 'gamemode')
-rw-r--r--gamemode/ents/art_chest/cl_art_chest.lua64
-rw-r--r--gamemode/ents/art_chest/sh_art_chest.lua11
-rw-r--r--gamemode/ents/art_chest/sv_art_chest.lua58
3 files changed, 133 insertions, 0 deletions
diff --git a/gamemode/ents/art_chest/cl_art_chest.lua b/gamemode/ents/art_chest/cl_art_chest.lua
new file mode 100644
index 0000000..6800810
--- /dev/null
+++ b/gamemode/ents/art_chest/cl_art_chest.lua
@@ -0,0 +1,64 @@
+local ENT = nrequire("sh_art_chest.lua")
+--local invfuncs = include("../../../gamemode/shared/inventory_common.lua")
+local invfuncs = nrequire("inventory/inventory.lua")
+
+ENT.RenderGroup = RENDERGROUP_BOTH
+
+function ENT:Initialize()
+end
+
+function ENT:OnRemove()
+end
+
+function ENT:Think()
+end
+
+function ENT:Draw()
+
+ self:DrawModel()
+end
+
+local oldpanel = nil
+local namecache = {}
+
+net.Receive("openchestinv",function(len,ply)
+ if oldpanel ~= nil then oldpanel:Remove() end
+ local what = net.ReadEntity()
+ local chest = invfuncs.DeSerializeBackpack()
+ ShowInventory()
+ local dat = {}
+ dat.redraw = function()
+ net.Start("requestchestinv")
+ net.WriteEntity(what)
+ net.SendToServer()
+ end
+ dat.panel = vgui.Create( "DFrame" )
+ oldpanel = dat.panel
+ dat.panel.OnClose = function()
+ net.Start("closechestinv")
+ net.WriteEntity(what)
+ net.SendToServer()
+ end
+ table.insert(LocalPlayer().invdisplays,dat)
+ local width = ScrW()
+ local height = ScrH()
+ local invpanel = dat.panel
+ invpanel:SetPos( width - (width / 4), 0 )
+ invpanel:SetSize( width / 4, height )
+ if namecache[what] == nil then
+ net.Start("requestchestname")
+ net.WriteEntity(what)
+ net.SendToServer()
+ invpanel:SetTitle( "Chest" )
+ else
+ invpanel:SetTitle(namecache[what])
+ end
+ invpanel:SetDraggable( true )
+ invpanel:MakePopup()
+ local innerpanel = vgui.Create("DPanel",dat.panel)
+ innerpanel:Dock(FILL)
+ innerpanel.Paint = function( self, w, h ) draw.RoundedBox( 4, 0, 0, w, h, Color( 157, 160, 167 ) ) end
+ invfuncs.DrawBackpackOnDPanel(innerpanel, chest, 1, what)
+end)
+
+scripted_ents.Register(ENT, "art_chest")
diff --git a/gamemode/ents/art_chest/sh_art_chest.lua b/gamemode/ents/art_chest/sh_art_chest.lua
new file mode 100644
index 0000000..1cfd103
--- /dev/null
+++ b/gamemode/ents/art_chest/sh_art_chest.lua
@@ -0,0 +1,11 @@
+local ENT = {}
+
+ENT.Type = "anim"
+ENT.Base = "base_anim"
+
+hook.Add("artery_core_loaded","load_ent_art_chest",function()
+ local e = scripted_ents.Get("base_anim")
+ setmetatable(ENT,e)
+end)
+
+return ENT
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")