ents/Create

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
m (Warning template)
(Added note about failure)
Line 1: Line 1:
 
{{Func
 
{{Func
|Description=Starts creating an entity.
+
|Description=Creates an entity. This function will fail and return NULL if the soft-edict limit is hit (8172), or the provided entity class doesn't exist.
  
 
{{Warning|Do not use before {{HookFunction|GM|InitPostEntity}} has been called, otherwise the server will crash!<br>If you need to perform entity creation when the game starts, create a hook for {{HookFunction|GM|InitPostEntity}} and do it there}}
 
{{Warning|Do not use before {{HookFunction|GM|InitPostEntity}} has been called, otherwise the server will crash!<br>If you need to perform entity creation when the game starts, create a hook for {{HookFunction|GM|InitPostEntity}} and do it there}}
 
|Realm=Server
 
|Realm=Server
 
|IsClass=No
 
|IsClass=No
|Name=Create
 
|Parent=ents
 
 
}}
 
}}
 
{{Arg
 
{{Arg
Line 15: Line 13:
 
{{Ret
 
{{Ret
 
|type=Entity
 
|type=Entity
|desc=The created entity
+
|desc=The created entity, or NULL if failed
 
}}
 
}}
 
{{Example
 
{{Example

Revision as of 10:19, 10 September 2017

 ents.Create( )

Contents

Description

Creates an entity. This function will fail and return NULL if the soft-edict limit is hit (8172), or the provided entity class doesn't exist.

WARNING

Do not use before GM:InitPostEntity has been called, otherwise the server will crash!
If you need to perform entity creation when the game starts, create a hook for GM:InitPostEntity and do it there

Arguments

string class

The classname of the entity to create

Returns

Entity

The created entity, or NULL if failed

Examples

Example

Creates a gmod_button entity near 0,0,0

local button = ents.Create( "gmod_button" )
if ( !IsValid( button ) ) then return end // Check whether we successfully made an entity, if not - bail
button:SetModel( "models/dav0r/buttons/button.mdl" )
button:SetPos( Vector( 0, 0, 100 ) )
button:Spawn()


Personal tools
Navigation