ents.Create
From GMod Wiki
Function | |
Syntax |
ents.Create( String entity class ) Where is this used? |
Description: | |
Create the specified entity. | |
Returns: | Entity |
Part of Library: | Ents |
Realm: | |
BBCode Link: | [b][url=http://wiki.garrysmod.com/?title=Ents.Create]Ents.Create [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] |
Example
Description | This example spawns an angry zombie in front of the first player in the server (Usually you!). |
---|---|
Used on | |
Code | local ply = Entity(1) -- The first entity is always the first player local tr = ply:GetEyeTrace() -- tr now contains a trace object local ent = ents.Create("npc_zombie") -- This creates our zombie entity ent:SetPos(tr.HitPos) -- This positions the zombie at the place our trace hit. ent:Spawn() -- This method spawns the zombie into the world, run for your lives! ( or just crowbar it dead(er) ) |
Output | Entity |
Additional Notes
- Can be used client-side - only some entities can be created, and those can only be seen by the client - If an entity can't be created client-side you'll get the message "Can't find factory for entity: <classname>" in the console.
- If you are trying to make gamemodes spawn entities on map load, you need to make sure that all entities are initialized first (such as by using Gamemode.InitPostEntity), otherwise the game will crash while loading.