Return to Main Docs Page

CreateEntityByName

NewerShared.png CBaseEntity CreateEntityByName(string classname )

Description:



Creates an entity.

Arguments:



  • 1) string classname
  • Classname of the entity to create.

Returns:



Example:



Code from a weapon_cola swep.
if !CLIENT then
   local ent = ToCPhysicsProp(CreateEntityByName("prop_cola"))
   if ent ~= NULL or ent ~= nil then
      ent:SetLocalOrigin(vecSrc + forward * 16)
      ent.m_nSkin = 1;
      ent:Spawn()		
      local phys = ent:VPhysicsGetObject()
      if phys ~= nil then
         phys:SetVelocity(forward * 1024,forward * 1024)
      end
   end
end