diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2018-01-14 15:38:14 -0500 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2018-01-14 15:38:14 -0500 |
| commit | 5e4b759e6b4fd8af9e66f76090ee868368bee467 (patch) | |
| tree | 0f8eded6108928bf0c5b080201af04ed330bb3a5 /gamemode/ents/art_chest/sv_art_chest.lua | |
| parent | dadd9486581d217c0482ddd639a13b95428e6366 (diff) | |
| download | artery-5e4b759e6b4fd8af9e66f76090ee868368bee467.tar.gz artery-5e4b759e6b4fd8af9e66f76090ee868368bee467.tar.bz2 artery-5e4b759e6b4fd8af9e66f76090ee868368bee467.zip | |
Moved art_chest entity into gamemode folder
Moved the art_chest entity to use the unusual artery system instead of
the default entity system.
Diffstat (limited to 'gamemode/ents/art_chest/sv_art_chest.lua')
| -rw-r--r-- | gamemode/ents/art_chest/sv_art_chest.lua | 58 |
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") |
