GM/OnEntityCreated

From Garry's Mod
Revision as of 16:18, 17 December 2015 by Jvs (Talk | contribs)
Jump to: navigation, search
 GM:OnEntityCreated( )

Contents

Description

Called right after the Entity has been made visible to Lua.

NOTE: In the current version of gmod, vehicles passed to this function will not be considered valid until they're fully spawned.
As a temporary workaround, see the example below.

Arguments

Entity entity

The entity

Examples

Example

When a prop spawns it yells.

function GM:OnEntityCreated( ent )
	if ( ent:GetClass() == "prop_physics" ) then
		ent:EmitSound( "vo/npc/male01/no02.wav" )
	end
end


Examples

Example

When a vehicle is created, wait until the entity is valid and change its color to blue. Without a timer the ent will not validate and you may encounter errors.

function GM:OnEntityCreated( ent )
    timer.Simple( .01, function()
        if IsValid( ent ) and ent:IsVehicle() then
            ent:SetColor( Color( 0, 0, 255 ) )
        end
    end)
end


Personal tools
Navigation