Garry's Mod Wiki

Revision Difference

ents.Create#514591

<function name="Create" parent="ents" type="libraryfunc">⤶ <description>⤶ Creates an entity. This function will fail and return NULL if the networked-edict limit is hit (around 8176), or the provided entity class doesn't exist.⤶ ⤶ <warning>Do not use before <page>GM:InitPostEntity</page> has been called, otherwise the server will crash!&amp;lt;br&amp;gt;If you need to perform entity creation when the game starts, create a hook for <page>GM:InitPostEntity</page> and do it there</warning>⤶ </description>⤶ <realm>Server</realm>⤶ <args>⤶ <arg name="class" type="string">The classname of the entity to create</arg>⤶ </args>⤶ <rets>⤶ <ret name="" type="Entity">The created entity, or NULL if failed</ret>⤶ </rets>⤶ </function>⤶ ⤶ <example>⤶ <description>Creates a gmod_button entity near 0,0,0</description>⤶ <code>⤶ 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()⤶ </code>⤶ ⤶ </example>