Lights above a entity


I have created a script that will bind a dynamic light to a car. Currently, I want it to be floating on the car’s roof. I’ll do this using trial and error but currently, I cant even get the new position.

concommand.Add( "SpawnJeep",function( ply )

	local trace = { }  
	trace.start = ply:EyePos()  
	trace.endpos = trace.start + ply:GetAimVector() * 85  
	trace.filter = ply  
	local tr = util.TraceLine( trace )  
	local car = ents.Create("prop_vehicle_jeep")  
    local CarPos = car:GetPos()
    m_entLight = ents.Create("light_dynamic")
	m_entLight:SetKeyValue("_light", "255,93,0 100")
	m_entLight:SetKeyValue("brightness", "6")
	m_entLight:SetKeyValue("distance", "300")
	m_entLight:Fire("TurnOn", "", 0)
end )

I created that but when I spawn the car, the light is at the car’s GetPos() rather then the carPos variable. Is this because the variable is constantly updating? Anyway, got any ideas?

Look into LocalToWorld and WorldToLocal - They let you take a vector, say Vector( 0, 0, 50 ) and map it to a location on the car so it shows up on the player roof, or to get a localized location on the car.

Dynamic lights aren’t good for “effects”; they create splash-lighting on the world. You may be better off with sprites.

From your suggestion about sprites, I ran the following command (Clientside)

render.DrawSprite( LocalPlayer():GetPos(), 50, 50, Color( 255, 0, 0, 255 ) )

Nothing happend, nor did any errors occur?

If you draw a sprite in a console command; it’ll be there and gone in a frame. It needs to be sustained ( draw it every frame ); unless you use an entity and do the same thing that you were doing with the DynamicLight.

If you “draw” a sprite with a console command, it will never draw because you can draw a sprite with console command.

In order to draw a sprite with Lua, you gotta call the render.* functions CLIENT side and in a specific hook.

Usually PostDrawTranslucentRenderables.

Also, don’y use ents.Create for dynamic lights, use DynamicLight global functions as suggested by Acecool.

If you need more info on any of those functions, visit garrysmod wiki first.

Concommands can be clientside; for this one the sprite wouldn’t draw and would give an error which is why I said he’d need to use an entity for the way he is doing it. Spawning an entity for each light/sprite is how some people do it. I don’t; which is why I explained the other method of rendering the sprite each frame.

Maybe I should’ve been more clear for the sprite; but he said nothing happens, no error, meaning he probably tried it in a client concommand and I explained it would be there and gone in a frame ( meaning it won’t work or accomplish what the op wants to do with it - if it does or doesn’t render, it doesn’t matter because it won’t work for the op ).

The thing, it won’t be there. render.* functions only work in rendering hooks.

The thing is, if it were there, it’d only be there for 1 frame; that is ~0.03030303030303030303030303030303 to 0.01666666666666666666666666666667 seconds, or less depending on FPS. It wouldn’t be there long enough to be of any use which is what I was trying to get across.

Well, yes, but your “If you draw a sprite in a console command;” is misleading, a sprite will never draw for one frame by itself, nor it will ever draw from render.DrawSprite in a console command or anywhere clientside that is not a part of drawing hook, unless you specifically code it to do so in a drawing hook.

My point is, the point you are trying to make is pointless, wrong, and misleading. End of the story.