Skip to content

Instantly share code, notes, and snippets.

@ColonelThirtyTwo
Created March 26, 2013 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ColonelThirtyTwo/5245305 to your computer and use it in GitHub Desktop.
Save ColonelThirtyTwo/5245305 to your computer and use it in GitHub Desktop.
Garry's Mod Alternate Entity Table Storage
AddCSLuaFile()
DEFINE_BASECLASS( "base_anim" )
ENT.PrintName = "Entity table test"
ENT.Author = "Alex 'Colonel Thirty Two' Parrill"
ENT.Information = "Proof of concept for better entity table storage"
ENT.Category = "Other"
ENT.Editable = true
ENT.Spawnable = true
ENT.AdminOnly = false
ENT.RenderGroup = RENDERGROUP_OPAQUE
local Entity_Tables = {}
function ENT:SpawnFunction( ply, tr, ClassName )
if ( !tr.Hit ) then return end
local SpawnPos = tr.HitPos + tr.HitNormal * 16
local ent = ents.Create( ClassName )
ent:SetPos( SpawnPos )
ent:Spawn()
ent:Activate()
return ent
end
function ENT:Initialize()
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
-- Create entity's table
print("Creating entity table for "..tostring(self))
Entity_Tables[self] = {}
if SERVER then
self:SetModel( "models/props_borealis/bluebarrel001.mdl" )
self:GetTable2().t = 0
end
end
function ENT:GetTable2()
-- Get entity table
return Entity_Tables[self]
end
function ENT:OnRemove()
print("Deleting entity table for "..tostring(self))
Entity_Tables[self] = nil
end
if SERVER then
function ENT:Think()
local tbl = self:GetTable2()
local t = tbl.t
local c = (t%50)*255/50
self:SetColor(Color(c,c,c,255))
tbl.t = t + 1
self:NextThink(CurTime())
end
function ENT:Use(activator, caller)
local tbl = self:GetTable2()
print("t = "..tostring(tbl.t))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment