Garry's Mod Wiki

Meta Tables

Meta Tables

Meta tables allow you to add functions to all classes in the game at the same time.

For example, adding a function to "Entity" meta table like so:

local meta = FindMetaTable( "Entity" ) function meta:ResetHealth() self:SetHealth( self:GetMaxHealth() ) end

Will allow you to use it on ALL entities like so:

local ply = Entity( 1 ) -- Gets the first player on the server ply:ResetHealth() -- We can call this function on any entity, including a player or an NPC.

However adding a function like this:

local ply = Entity( 1 ) function ply:ResetHealth() self:SetHealth( self:GetMaxHealth() ) end

Will not allow you to use that function on any other entity BUT Entity( 1 )

A list of type meta tables that can be retrieved with FindMetaTable can be found on TYPE enum.