Garry's Mod Wiki

properties.Add

  properties.Add( string name, table propertyData )

Description

Add properties to the properties module. Properties can be blocked via GM:CanProperty.

Arguments

1 string name
A unique name used to identify the property
2 table propertyData
A table that defines the property. Uses the PropertyAdd structure.

Example

Defines a property that can be used to ignite entities (from Sandbox)

properties.Add( "ignite", { MenuLabel = "#ignite", -- Name to display on the context menu Order = 999, -- The order to display this property relative to other properties MenuIcon = "icon16/fire.png", -- The icon to display next to the property Filter = function( self, ent, ply ) -- A function that determines whether an entity is valid for this property if ( !IsValid( ent ) ) then return false end if ( ent:IsPlayer() ) then return false end if ( !CanEntityBeSetOnFire( ent ) ) then return false end if ( !gamemode.Call( "CanProperty", ply, "ignite", ent ) ) then return false end return !ent:IsOnFire() end, Action = function( self, ent ) -- The action to perform upon using the property ( Clientside ) self:MsgStart() net.WriteEntity( ent ) self:MsgEnd() end, Receive = function( self, length, ply ) -- The action to perform upon using the property ( Serverside ) local ent = net.ReadEntity() if ( !properties.CanBeTargeted( ent, ply ) ) then return end if ( !self:Filter( ent, ply ) ) then return end ent:Ignite( 360 ) end } )