properties.Add

From Garry's Mod
Jump to: navigation, search
 properties.Add( )

Contents

Description

Add properties to the properties module

Arguments

string name

A unique name used to identify the property

Arguments

table propertyData

A table that defines the property. Uses the PropertyAdd structure.

Examples

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, player ) -- The action to perform upon using the property ( Serverside )
		local ent = net.ReadEntity()
		if ( !self:Filter( ent, player ) ) then return end
		
		ent:Ignite( 360 )
	end 
} )


Personal tools
Navigation