I am working on a custom entity and i need it to emit light around it, i’m using this code but i just found out that DynamicLight has to be ran clientside?
-- light effect start
-- light effect sample code start
local dlight = DynamicLight( self )
if ( dlight ) then
dlight.pos = self.pos()
dlight.r = 255
dlight.g = 255
dlight.b = 255
dlight.brightness = 2
dlight.Decay = 1000
dlight.Size = 256
dlight.DieTime = CurTime() + 1
end
--light effect sample code end
-- light effect end
How do i run this code client side for the serverside entity?
include( "shared.lua" )
function ENT:Initialize()
if !self:IsValid() then return end
-- light code start
if ( CLIENT ) then
local dlight = DynamicLight( ent:EntIndex() )
if ( dlight ) then
dlight.pos = ent.pos()
dlight.r = 200
dlight.g = 200
dlight.b = 255
dlight.brightness = 2
dlight.Decay = 1000
dlight.Size = 256
dlight.DieTime = CurTime() + 1
end
end
-- light code end
end
Would this work?
could you give me an example for net messages with this?
If you’re just doing it on initialize then you shouldn’t have to use net messages. Just declare ENT:Initialize within the shared file, as the init file is never called client side.
Fear not, for there is a serverside light entity you can use!
[lua]
local light = ents.Create(“light_dynamic”)
light:Spawn()
light:Activate()
light:SetKeyValue(“distance”, 400) – ‘distance’ is equivalent to the radius of your light
light:SetKeyValue(“brightness”, 2)
light:SetKeyValue("_light", “255 0 0 255”) – ‘_light’ is the color of your light. This currently makes it red
light:Fire(“TurnOn”)
[/lua]
thank you so much lol, is there a way to parent it to an entity?
[editline]21st May 2016[/editline]
oh its an ent so i can parent it thank you so much i will test this now.
[editline]21st May 2016[/editline]
function ENT:Initialize()
local light = ents.Create("light_dynamic")
light:Spawn()
light:Activate()
light:SetPos( self.GetPos() )
light:SetKeyValue("distance", 400) -- 'distance' is equivalent to the radius of your light
light:SetKeyValue("brightness", 2)
light:SetKeyValue("_light", "255 0 0 255") -- '_light' is the color of your light. This currently makes it red
light:Fire("TurnOn")
light:SetParent(ent, 1)
For some reason SetPos is not working? using self.getpos or ent.getpos is not working? its an error
[editline]22nd May 2016[/editline]
got it working just trying to parent it.
[editline]22nd May 2016[/editline]
Thanks for the help guys i got it working.
local tespos = self:GetPos()
local light = ents.Create("light_dynamic")
light:Spawn()
light:Activate()
light:SetPos( tespos )
light:SetKeyValue("distance", 400) -- 'distance' is equivalent to the radius of your light
light:SetKeyValue("brightness", 2)
light:SetKeyValue("_light", "255 0 0 255") -- '_light' is the color of your light. This currently makes it red
light:Fire("TurnOn")
light:SetParent( self )