Spawning clientside entities?

It seems I can’t do it. I want to create an entity to indicate where you will spawn stuff (Gamemaster) but it keeps saying that it can’t find the factory for the entity. Already put InitializeAsClientEntity() in the init thingy from the entity, but still doesn’t work. Any ideas?

Use prop_physics.

Here’s what I’m currently using…

cl_init.lua
[lua]
// function for spawning clientside entities
function ENT:SpawnCL( data )

local ent = ents.Create( data.class or "prop_physics" )
if( !ent:IsValid() ) then return NULL end
	ent:SetColor( unpack( data.color or {255,255,255,255} ) )
	ent:SetPos( self:GetPos() + ( data.pos or Vector(0) ) )
	ent:SetModelScale( data.scale or Vector( 1,1,1 ) )
	ent:SetAngles( data.ang or Angle(0) )
	ent:SetMaterial( data.mat or '' )
	ent:SetModel( data.model )
	ent:SetParent( self )
	ent:Spawn()
	table.insert( self.clientents, ent )
return ent

end
[/lua]

My prop data is stored in a seperate table, but you needn’t do this…
[lua]
local parts = {
BODY = {
model = Model(‘models/props/sphere.mdl’),
color = {30,30,30,255},
mat = ‘models/debug/debugwhite’
},
STUB = {
model = Model(‘models/props_c17/oildrum001.mdl’),
pos = Vector( 0,0,14 ),
color = {50,50,50,255},
scale = Vector( 0.25,0.25,0.25 )
},
ect…

			}

[/lua]

I prefer to use my own entity since it has a draw hook with some additional render stuff, so I can’t use prop_physics (unless I can somehow change the drawing hook of it)

Oh, you want to make a clientside SEnt, I misunderstood.
I’ve never done this so have no experience with it.

As you’ve probably noticed there’s no documentation for the InitializeAsClientEntity function, and it’s not currently used anywhere in gmod.
I guess that leaves it down to trial & error, or hope that someone has done the trial & error thing before and knows how it works.

If this helps here’s how it’s used by Valve :


 InitializeAsClientEntity( pszModelName, RENDER_GROUP_OPAQUE_ENTITY )

http://www.koders.com/cpp/fid8F25C5407EEC99E1BD95D951A340722F2E337E6F.aspx?s=InitializeAsClientEntity+valve#L56

We can probably safely assume InitializeAsClientEntity is simply a binding for it’s C++ equivalent, it apparently returns a boolean too.

[editline]1[/editline]
Here’s how it’s defined :
http://www.koders.com/cpp/fidE4849FF34B3660FEB5665828F4260A9FEB85759F.aspx?s=InitializeAsClientEntity+Valve#L953