From b8bcd3692cfe9eb0e683addf274bea4287a28e62 Mon Sep 17 00:00:00 2001 From: Redox <69946827+wrefgtzweve@users.noreply.github.com> Date: Mon, 8 Dec 2025 19:13:27 +0100 Subject: [PATCH 01/18] Use ProjectedTexture directly instead projecttexture entity --- lua/entities/gmod_wire_lamp.lua | 138 ++++++++++++++++---------------- 1 file changed, 67 insertions(+), 71 deletions(-) diff --git a/lua/entities/gmod_wire_lamp.lua b/lua/entities/gmod_wire_lamp.lua index 03a37e4895..2ccf7f9c12 100644 --- a/lua/entities/gmod_wire_lamp.lua +++ b/lua/entities/gmod_wire_lamp.lua @@ -6,7 +6,14 @@ ENT.RenderGroup = RENDERGROUP_BOTH ENT.WireDebugName = "Lamp" function ENT:SetupDataTables() - self:NetworkVar("Bool", 0, "On") + self:NetworkVar("Bool", "On") + self:NetworkVar("Int", "FOV") + self:NetworkVar("Int", "Red") + self:NetworkVar("Int", "Green") + self:NetworkVar("Int", "Blue") + self:NetworkVar("Int", "Distance") + self:NetworkVar("Int", "Brightness") + self:NetworkVar("String", "Texture") end function ENT:GetEntityDriveMode() @@ -57,7 +64,7 @@ if CLIENT then render.SetMaterial(light) - local color = self:GetColor() + local color = Color(self:GetRed(), self:GetGreen(), self:GetBlue()) color.a = math.Clamp((1000 - math.Clamp(distance, 32, 800)) * visdot, 0, 100) local size = math.Clamp(distance * visdot * (light_info.Scale or 2), 64, 512) @@ -71,100 +78,89 @@ if CLIENT then BaseClass.DrawTranslucent(self, flags) self:DrawEffects() end -end -function ENT:Switch(on) - if on == IsValid(self.flashlight) then return end + function ENT:Think() + if not self:GetOn() then + if IsValid( self.ProjTex ) then + self.ProjTex:Remove() + self.ProjTex = nil + self.LastLampHash = nil + end + return + end - self.on = on - self:SetOn(on) + -- Projected texture + if not IsValid( self.ProjTex ) then + self.ProjTex = ProjectedTexture() + end - if not on then - SafeRemoveEntity(self.flashlight) - self.flashlight = nil + local light_info = self:GetLightInfo() + local lightpos = self:LocalToWorld(light_info.Offset or vector_offset) - return + -- Projected texture update + local projtex = self.ProjTex + projtex:SetTexture( self:GetTexture() ) + projtex:SetFOV( self:GetFOV() ) + projtex:SetFarZ( self:GetDistance() ) + projtex:SetBrightness( self:GetBrightness() / 255 ) + projtex:SetColor( Color( self:GetRed(), self:GetGreen(), self:GetBlue() ) ) + projtex:SetPos( lightpos ) + projtex:SetAngles( self:LocalToWorldAngles( light_info.Angle or angle_zero ) ) + + local currentPos = self:GetPos() + local currentAng = self:GetAngles() + local lampHash = currentPos.x + currentPos.y * 17 + currentPos.z * 23 + currentAng.p * 29 + currentAng.y * 31 + currentAng.r * 37 + local lastLampHash = self.LastLampHash or 0 + if lastLampHash ~= lampHash then + projtex:Update() + end + self.LastLampHash = lampHash end - local flashlight = ents.Create("env_projectedtexture") - self.flashlight = flashlight - flashlight:SetParent(self) - - local singleplayer = game.SinglePlayer() - local light_info = self:GetLightInfo() - local offset = (light_info.Offset or vector_offset) * -1 - offset.x = offset.x + 5 - - flashlight:SetLocalPos(-offset) - flashlight:SetLocalAngles(light_info.Angle or angle_zero) - flashlight:SetKeyValue("enableshadows", 1) - flashlight:SetKeyValue("nearz", light_info.NearZ or 12) - flashlight:SetKeyValue("farz", singleplayer and self.Dist or math.Clamp(self.Dist, 64, 2048)) - flashlight:SetKeyValue("lightfov", singleplayer and self.FOV or math.Clamp(self.FOV, 10, 170)) - - local color = self:GetColor() - local brightness = singleplayer and self.Brightness or math.Clamp(self.Brightness, 0, 8) - flashlight:SetKeyValue("lightcolor", Format("%i %i %i 255", color.r * brightness, color.g * brightness, color.b * brightness)) - flashlight:Spawn() - - flashlight:Input("SpotlightTexture", NULL, NULL, self.Texture) -end - -function ENT:UpdateLight() - local color = Color(self.r, self.g, self.b, self:GetColor().a) - self:SetOverlayText(string.format("Red: %i Green: %i Blue: %i\nFOV: %i Distance: %i Brightness: %i", color.r, color.g, color.b, self.FOV, self.Dist, self.Brightness)) - self:SetColor(color) - - local flashlight = self.flashlight - if not IsValid(flashlight) then return end - - local singleplayer = game.SinglePlayer() - flashlight:Input("SpotlightTexture", NULL, NULL, self.Texture) - flashlight:Input("FOV", NULL, NULL, tostring(singleplayer and self.FOV or math.Clamp(self.FOV, 10, 170))) - flashlight:SetKeyValue("farz", singleplayer and self.Dist or math.Clamp(self.Dist, 64, 2048)) - - local brightness = singleplayer and self.Brightness or math.Clamp(self.Brightness, 0, 8) - flashlight:SetKeyValue("lightcolor", Format("%i %i %i 255", color.r * brightness, color.g * brightness, color.b * brightness)) + function ENT:OnRemove() + if IsValid( self.ProjTex ) then + self.ProjTex:Remove() + end + end end function ENT:TriggerInput(name, value) if name == "Red" then - self.r = math.Clamp(value, 0, 255) + self:SetRed(math.Clamp(value, 0, 255)) elseif name == "Green" then - self.g = math.Clamp(value, 0, 255) + self:SetGreen(math.Clamp(value, 0, 255)) elseif name == "Blue" then - self.b = math.Clamp(value, 0, 255) + self:SetBlue(math.Clamp(value, 0, 255)) elseif name == "RGB" then - self.r, self.g, self.b = math.Clamp(value.r, 0, 255), math.Clamp(value.g, 0, 255), math.Clamp(value.b, 0, 255) + self:SetRed(math.Clamp(value.r, 0, 255)) + self:SetGreen(math.Clamp(value.g, 0, 255)) + self:SetBlue(math.Clamp(value.b, 0, 255)) elseif name == "FOV" then - self.FOV = value + self:SetFOV(value) elseif name == "Distance" then - self.Dist = value + self:SetDistance(value) elseif name == "Brightness" then - self.Brightness = value + self:SetBrightness(value) elseif name == "On" then - self:Switch(value ~= 0) + self:SetOn(value ~= 0) elseif name == "Texture" then if value ~= "" then - self.Texture = value + self:SetTexture(value) else - self.Texture = "effects/flashlight001" + self:SetTexture("effects/flashlight001") end end - - self:UpdateLight() end function ENT:Setup(r, g, b, texture, fov, distance, brightness, on) - self.Texture = texture or "effects/flashlight001" - self.FOV = fov or 90 - self.Dist = distance or 1024 - self.Brightness = brightness or 8 - self.r, self.g, self.b = math.Clamp(r or 255, 0, 255), math.Clamp(g or 255, 0, 255), math.Clamp(b or 255, 0, 255) - - self.on = on and true or false - self:Switch(self.on) - self:UpdateLight() + self:SetRed(r) + self:SetGreen(g) + self:SetBlue(b) + self:SetTexture(texture) + self:SetFOV(fov) + self:SetDistance(distance) + self:SetBrightness(brightness) + self:SetOn(on) end duplicator.RegisterEntityClass("gmod_wire_lamp", WireLib.MakeWireEnt, "Data", "r", "g", "b", "Texture", "FOV", "Dist", "Brightness", "on") From 428df3bdd4f8270c7159d2413a7c117d980adebd Mon Sep 17 00:00:00 2001 From: Redox <69946827+wrefgtzweve@users.noreply.github.com> Date: Mon, 8 Dec 2025 19:26:54 +0100 Subject: [PATCH 02/18] Use matrix and add start on --- lua/entities/gmod_wire_lamp.lua | 12 +++++------- lua/wire/stools/lamp.lua | 7 ++++++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lua/entities/gmod_wire_lamp.lua b/lua/entities/gmod_wire_lamp.lua index 2ccf7f9c12..7364720639 100644 --- a/lua/entities/gmod_wire_lamp.lua +++ b/lua/entities/gmod_wire_lamp.lua @@ -84,7 +84,7 @@ if CLIENT then if IsValid( self.ProjTex ) then self.ProjTex:Remove() self.ProjTex = nil - self.LastLampHash = nil + self.LastLampMatrix = nil end return end @@ -107,14 +107,12 @@ if CLIENT then projtex:SetPos( lightpos ) projtex:SetAngles( self:LocalToWorldAngles( light_info.Angle or angle_zero ) ) - local currentPos = self:GetPos() - local currentAng = self:GetAngles() - local lampHash = currentPos.x + currentPos.y * 17 + currentPos.z * 23 + currentAng.p * 29 + currentAng.y * 31 + currentAng.r * 37 - local lastLampHash = self.LastLampHash or 0 - if lastLampHash ~= lampHash then + local lampMatrix = self:GetWorldTransformMatrix() + local lastLampMatrix = self.LastLampMatrix or 0 + if lastLampMatrix ~= lampMatrix then projtex:Update() end - self.LastLampHash = lampHash + self.LastLampMatrix = lampMatrix end function ENT:OnRemove() diff --git a/lua/wire/stools/lamp.lua b/lua/wire/stools/lamp.lua index 1f5bdf394a..7aae7e29cc 100644 --- a/lua/wire/stools/lamp.lua +++ b/lua/wire/stools/lamp.lua @@ -18,7 +18,7 @@ WireToolSetup.SetupMax(10) if SERVER then function TOOL:GetConVars() - return self:GetClientNumber("r"), self:GetClientNumber("g"), self:GetClientNumber("b"), self:GetClientInfo("texture"), self:GetClientNumber("fov"), self:GetClientNumber("distance"), self:GetClientNumber("brightness") + return self:GetClientNumber("r"), self:GetClientNumber("g"), self:GetClientNumber("b"), self:GetClientInfo("texture"), self:GetClientNumber("fov"), self:GetClientNumber("distance"), self:GetClientNumber("brightness"), self:GetClientNumber("on") ~= 0 end function TOOL:LeftClick_PostMake(ent, ply, trace) @@ -108,6 +108,7 @@ TOOL.ClientConVar["fov"] = 90 TOOL.ClientConVar["distance"] = 1024 TOOL.ClientConVar["brightness"] = 4 TOOL.ClientConVar["model"] = "models/lamps/torch.mdl" +TOOL.ClientConVar["on"] = 1 function TOOL:RightClick(trace) if CLIENT then return true end @@ -141,6 +142,10 @@ function TOOL.BuildCPanel(panel) combobox:AddChoice("Rope", "rope") combobox:AddChoice("Weld", "weld") combobox:AddChoice("None", "none") + + local startOn = panel:CheckBox("Start On", "wire_lamp_on") + startOn:SetTooltip("If checked, the lamp will be on when spawned.") + panel:ColorPicker("Color", "wire_lamp_r", "wire_lamp_g", "wire_lamp_b") local matselect = panel:MatSelect("wire_lamp_texture", nil, true, 0.33, 0.33) From 448355a7fa4a2793effe59496e2b1cf45e732351 Mon Sep 17 00:00:00 2001 From: Redox <69946827+wrefgtzweve@users.noreply.github.com> Date: Mon, 8 Dec 2025 19:36:30 +0100 Subject: [PATCH 03/18] Only update projecttexture when updating --- lua/entities/gmod_wire_lamp.lua | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/lua/entities/gmod_wire_lamp.lua b/lua/entities/gmod_wire_lamp.lua index 7364720639..00b23b1708 100644 --- a/lua/entities/gmod_wire_lamp.lua +++ b/lua/entities/gmod_wire_lamp.lua @@ -97,19 +97,17 @@ if CLIENT then local light_info = self:GetLightInfo() local lightpos = self:LocalToWorld(light_info.Offset or vector_offset) - -- Projected texture update - local projtex = self.ProjTex - projtex:SetTexture( self:GetTexture() ) - projtex:SetFOV( self:GetFOV() ) - projtex:SetFarZ( self:GetDistance() ) - projtex:SetBrightness( self:GetBrightness() / 255 ) - projtex:SetColor( Color( self:GetRed(), self:GetGreen(), self:GetBlue() ) ) - projtex:SetPos( lightpos ) - projtex:SetAngles( self:LocalToWorldAngles( light_info.Angle or angle_zero ) ) - local lampMatrix = self:GetWorldTransformMatrix() local lastLampMatrix = self.LastLampMatrix or 0 if lastLampMatrix ~= lampMatrix then + local projtex = self.ProjTex + projtex:SetTexture( self:GetTexture() ) + projtex:SetFOV( self:GetFOV() ) + projtex:SetFarZ( self:GetDistance() ) + projtex:SetBrightness( self:GetBrightness() / 255 ) + projtex:SetColor( Color( self:GetRed(), self:GetGreen(), self:GetBlue() ) ) + projtex:SetPos( lightpos ) + projtex:SetAngles( self:LocalToWorldAngles( light_info.Angle or angle_zero ) ) projtex:Update() end self.LastLampMatrix = lampMatrix From 63c6b3bd6ad5304d72ea6cea24cec221fd34f60b Mon Sep 17 00:00:00 2001 From: Redox <69946827+wrefgtzweve@users.noreply.github.com> Date: Mon, 8 Dec 2025 19:38:37 +0100 Subject: [PATCH 04/18] Use GetClientBool --- lua/wire/stools/lamp.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/wire/stools/lamp.lua b/lua/wire/stools/lamp.lua index 7aae7e29cc..3b62208574 100644 --- a/lua/wire/stools/lamp.lua +++ b/lua/wire/stools/lamp.lua @@ -18,7 +18,7 @@ WireToolSetup.SetupMax(10) if SERVER then function TOOL:GetConVars() - return self:GetClientNumber("r"), self:GetClientNumber("g"), self:GetClientNumber("b"), self:GetClientInfo("texture"), self:GetClientNumber("fov"), self:GetClientNumber("distance"), self:GetClientNumber("brightness"), self:GetClientNumber("on") ~= 0 + return self:GetClientNumber("r"), self:GetClientNumber("g"), self:GetClientNumber("b"), self:GetClientInfo("texture"), self:GetClientNumber("fov"), self:GetClientNumber("distance"), self:GetClientNumber("brightness"), self:GetClientBool("on") end function TOOL:LeftClick_PostMake(ent, ply, trace) From 3777ea2cfc40622bfcfbb8f272adae1eb33b8fc5 Mon Sep 17 00:00:00 2001 From: Redox <69946827+wrefgtzweve@users.noreply.github.com> Date: Mon, 8 Dec 2025 19:41:22 +0100 Subject: [PATCH 05/18] Disable shadows --- lua/entities/gmod_wire_lamp.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/entities/gmod_wire_lamp.lua b/lua/entities/gmod_wire_lamp.lua index 00b23b1708..70cb86eae7 100644 --- a/lua/entities/gmod_wire_lamp.lua +++ b/lua/entities/gmod_wire_lamp.lua @@ -108,6 +108,7 @@ if CLIENT then projtex:SetColor( Color( self:GetRed(), self:GetGreen(), self:GetBlue() ) ) projtex:SetPos( lightpos ) projtex:SetAngles( self:LocalToWorldAngles( light_info.Angle or angle_zero ) ) + projtex:SetEnableShadows( false ) projtex:Update() end self.LastLampMatrix = lampMatrix From 2731e8e3cd477e1dbb24d86afd3490a16ea74b66 Mon Sep 17 00:00:00 2001 From: Redox <69946827+wrefgtzweve@users.noreply.github.com> Date: Mon, 8 Dec 2025 19:47:10 +0100 Subject: [PATCH 06/18] Use Updated netvar --- lua/entities/gmod_wire_lamp.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lua/entities/gmod_wire_lamp.lua b/lua/entities/gmod_wire_lamp.lua index 70cb86eae7..8d26b397f4 100644 --- a/lua/entities/gmod_wire_lamp.lua +++ b/lua/entities/gmod_wire_lamp.lua @@ -7,6 +7,7 @@ ENT.WireDebugName = "Lamp" function ENT:SetupDataTables() self:NetworkVar("Bool", "On") + self:NetworkVar("Bool", "Updated") self:NetworkVar("Int", "FOV") self:NetworkVar("Int", "Red") self:NetworkVar("Int", "Green") @@ -99,7 +100,7 @@ if CLIENT then local lampMatrix = self:GetWorldTransformMatrix() local lastLampMatrix = self.LastLampMatrix or 0 - if lastLampMatrix ~= lampMatrix then + if lastLampMatrix ~= lampMatrix or self:GetUpdated() then local projtex = self.ProjTex projtex:SetTexture( self:GetTexture() ) projtex:SetFOV( self:GetFOV() ) @@ -110,6 +111,10 @@ if CLIENT then projtex:SetAngles( self:LocalToWorldAngles( light_info.Angle or angle_zero ) ) projtex:SetEnableShadows( false ) projtex:Update() + + if self:GetUpdated() then + self:SetUpdated(false) + end end self.LastLampMatrix = lampMatrix end @@ -147,6 +152,13 @@ function ENT:TriggerInput(name, value) self:SetTexture("effects/flashlight001") end end + + self:SetUpdated(true) + timer.Simple(0, function() + if IsValid(self) then + self:SetUpdated(false) + end + end) end function ENT:Setup(r, g, b, texture, fov, distance, brightness, on) From a5f582980c2270572a53c0d6c6360596379215a5 Mon Sep 17 00:00:00 2001 From: Redox <69946827+wrefgtzweve@users.noreply.github.com> Date: Mon, 8 Dec 2025 20:24:39 +0100 Subject: [PATCH 07/18] Simplify update logic --- lua/entities/gmod_wire_lamp.lua | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lua/entities/gmod_wire_lamp.lua b/lua/entities/gmod_wire_lamp.lua index 8d26b397f4..ce269f3d65 100644 --- a/lua/entities/gmod_wire_lamp.lua +++ b/lua/entities/gmod_wire_lamp.lua @@ -7,7 +7,6 @@ ENT.WireDebugName = "Lamp" function ENT:SetupDataTables() self:NetworkVar("Bool", "On") - self:NetworkVar("Bool", "Updated") self:NetworkVar("Int", "FOV") self:NetworkVar("Int", "Red") self:NetworkVar("Int", "Green") @@ -15,6 +14,14 @@ function ENT:SetupDataTables() self:NetworkVar("Int", "Distance") self:NetworkVar("Int", "Brightness") self:NetworkVar("String", "Texture") + + self:NetworkVarNotify( "FOV", self.OnVarChanged ) + self:NetworkVarNotify( "Red", self.OnVarChanged ) + self:NetworkVarNotify( "Green", self.OnVarChanged ) + self:NetworkVarNotify( "Blue", self.OnVarChanged ) + self:NetworkVarNotify( "Distance", self.OnVarChanged ) + self:NetworkVarNotify( "Brightness", self.OnVarChanged ) + self:NetworkVarNotify( "Texture", self.OnVarChanged ) end function ENT:GetEntityDriveMode() @@ -100,7 +107,7 @@ if CLIENT then local lampMatrix = self:GetWorldTransformMatrix() local lastLampMatrix = self.LastLampMatrix or 0 - if lastLampMatrix ~= lampMatrix or self:GetUpdated() then + if lastLampMatrix ~= lampMatrix then local projtex = self.ProjTex projtex:SetTexture( self:GetTexture() ) projtex:SetFOV( self:GetFOV() ) @@ -111,10 +118,6 @@ if CLIENT then projtex:SetAngles( self:LocalToWorldAngles( light_info.Angle or angle_zero ) ) projtex:SetEnableShadows( false ) projtex:Update() - - if self:GetUpdated() then - self:SetUpdated(false) - end end self.LastLampMatrix = lampMatrix end @@ -124,6 +127,10 @@ if CLIENT then self.ProjTex:Remove() end end + + function ENT:OnVarChanged( varname, oldvalue, newvalue ) + self.LastLampMatrix = nil + end end function ENT:TriggerInput(name, value) @@ -152,13 +159,6 @@ function ENT:TriggerInput(name, value) self:SetTexture("effects/flashlight001") end end - - self:SetUpdated(true) - timer.Simple(0, function() - if IsValid(self) then - self:SetUpdated(false) - end - end) end function ENT:Setup(r, g, b, texture, fov, distance, brightness, on) From 90b16be62c0b3259bad3ca25cbbef87fec2fd873 Mon Sep 17 00:00:00 2001 From: Redox <69946827+wrefgtzweve@users.noreply.github.com> Date: Mon, 8 Dec 2025 20:33:53 +0100 Subject: [PATCH 08/18] Only update projtext when needed --- lua/entities/gmod_wire_lamp.lua | 45 +++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/lua/entities/gmod_wire_lamp.lua b/lua/entities/gmod_wire_lamp.lua index ce269f3d65..fa3f06abfb 100644 --- a/lua/entities/gmod_wire_lamp.lua +++ b/lua/entities/gmod_wire_lamp.lua @@ -15,13 +15,18 @@ function ENT:SetupDataTables() self:NetworkVar("Int", "Brightness") self:NetworkVar("String", "Texture") - self:NetworkVarNotify( "FOV", self.OnVarChanged ) - self:NetworkVarNotify( "Red", self.OnVarChanged ) - self:NetworkVarNotify( "Green", self.OnVarChanged ) - self:NetworkVarNotify( "Blue", self.OnVarChanged ) - self:NetworkVarNotify( "Distance", self.OnVarChanged ) - self:NetworkVarNotify( "Brightness", self.OnVarChanged ) - self:NetworkVarNotify( "Texture", self.OnVarChanged ) + if CLIENT then + local function callOnVarChanged( _, ... ) -- Fixes autorefresh + self:OnVarChanged( ... ) + end + self:NetworkVarNotify( "FOV", callOnVarChanged ) + self:NetworkVarNotify( "Red", callOnVarChanged ) + self:NetworkVarNotify( "Green", callOnVarChanged ) + self:NetworkVarNotify( "Blue", callOnVarChanged ) + self:NetworkVarNotify( "Distance", callOnVarChanged ) + self:NetworkVarNotify( "Brightness", callOnVarChanged ) + self:NetworkVarNotify( "Texture", callOnVarChanged ) + end end function ENT:GetEntityDriveMode() @@ -87,6 +92,19 @@ if CLIENT then self:DrawEffects() end + function ENT:UpdateProjTex() + local projtex = self.ProjTex + if not IsValid(projtex) then return end + + projtex:SetEnableShadows( false ) + projtex:SetTexture( self:GetTexture() ) + projtex:SetFOV( self:GetFOV() ) + projtex:SetFarZ( self:GetDistance() ) + projtex:SetBrightness( self:GetBrightness() / 255 ) + projtex:SetColor( Color( self:GetRed(), self:GetGreen(), self:GetBlue() ) ) + projtex:Update() + end + function ENT:Think() if not self:GetOn() then if IsValid( self.ProjTex ) then @@ -100,6 +118,7 @@ if CLIENT then -- Projected texture if not IsValid( self.ProjTex ) then self.ProjTex = ProjectedTexture() + self:UpdateProjTex() end local light_info = self:GetLightInfo() @@ -109,14 +128,8 @@ if CLIENT then local lastLampMatrix = self.LastLampMatrix or 0 if lastLampMatrix ~= lampMatrix then local projtex = self.ProjTex - projtex:SetTexture( self:GetTexture() ) - projtex:SetFOV( self:GetFOV() ) - projtex:SetFarZ( self:GetDistance() ) - projtex:SetBrightness( self:GetBrightness() / 255 ) - projtex:SetColor( Color( self:GetRed(), self:GetGreen(), self:GetBlue() ) ) projtex:SetPos( lightpos ) projtex:SetAngles( self:LocalToWorldAngles( light_info.Angle or angle_zero ) ) - projtex:SetEnableShadows( false ) projtex:Update() end self.LastLampMatrix = lampMatrix @@ -129,7 +142,11 @@ if CLIENT then end function ENT:OnVarChanged( varname, oldvalue, newvalue ) - self.LastLampMatrix = nil + timer.Simple( 0, function() + if not IsValid( self ) then return end + if not IsValid( self.ProjTex ) then return end + self:UpdateProjTex() + end ) end end From 2d9d8c95746b43131e8b5a08f038de4d372dac64 Mon Sep 17 00:00:00 2001 From: Redox <69946827+wrefgtzweve@users.noreply.github.com> Date: Mon, 8 Dec 2025 20:35:45 +0100 Subject: [PATCH 09/18] Implement old setup checks --- lua/entities/gmod_wire_lamp.lua | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lua/entities/gmod_wire_lamp.lua b/lua/entities/gmod_wire_lamp.lua index fa3f06abfb..bd4b76d6e3 100644 --- a/lua/entities/gmod_wire_lamp.lua +++ b/lua/entities/gmod_wire_lamp.lua @@ -179,14 +179,18 @@ function ENT:TriggerInput(name, value) end function ENT:Setup(r, g, b, texture, fov, distance, brightness, on) + r = math.Clamp(r or 255, 0, 255) + g = math.Clamp(g or 255, 0, 255) + b = math.Clamp(b or 255, 0, 255) + self:SetRed(r) self:SetGreen(g) self:SetBlue(b) - self:SetTexture(texture) - self:SetFOV(fov) - self:SetDistance(distance) - self:SetBrightness(brightness) - self:SetOn(on) + self:SetTexture(texture or "effects/flashlight001") + self:SetFOV(fov or 90) + self:SetDistance(distance or 1024) + self:SetBrightness(brightness or 8) + self:SetOn(on and true or false) end duplicator.RegisterEntityClass("gmod_wire_lamp", WireLib.MakeWireEnt, "Data", "r", "g", "b", "Texture", "FOV", "Dist", "Brightness", "on") From e420e8dfe294569e9cb8557c751b3aa8d89c4cfe Mon Sep 17 00:00:00 2001 From: Redox <69946827+wrefgtzweve@users.noreply.github.com> Date: Mon, 8 Dec 2025 20:41:40 +0100 Subject: [PATCH 10/18] Use entity color for lamp color --- lua/entities/gmod_wire_lamp.lua | 45 +++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/lua/entities/gmod_wire_lamp.lua b/lua/entities/gmod_wire_lamp.lua index bd4b76d6e3..aa7d52d515 100644 --- a/lua/entities/gmod_wire_lamp.lua +++ b/lua/entities/gmod_wire_lamp.lua @@ -8,9 +8,6 @@ ENT.WireDebugName = "Lamp" function ENT:SetupDataTables() self:NetworkVar("Bool", "On") self:NetworkVar("Int", "FOV") - self:NetworkVar("Int", "Red") - self:NetworkVar("Int", "Green") - self:NetworkVar("Int", "Blue") self:NetworkVar("Int", "Distance") self:NetworkVar("Int", "Brightness") self:NetworkVar("String", "Texture") @@ -20,9 +17,6 @@ function ENT:SetupDataTables() self:OnVarChanged( ... ) end self:NetworkVarNotify( "FOV", callOnVarChanged ) - self:NetworkVarNotify( "Red", callOnVarChanged ) - self:NetworkVarNotify( "Green", callOnVarChanged ) - self:NetworkVarNotify( "Blue", callOnVarChanged ) self:NetworkVarNotify( "Distance", callOnVarChanged ) self:NetworkVarNotify( "Brightness", callOnVarChanged ) self:NetworkVarNotify( "Texture", callOnVarChanged ) @@ -77,7 +71,7 @@ if CLIENT then render.SetMaterial(light) - local color = Color(self:GetRed(), self:GetGreen(), self:GetBlue()) + local color = self:GetColor() color.a = math.Clamp((1000 - math.Clamp(distance, 32, 800)) * visdot, 0, 100) local size = math.Clamp(distance * visdot * (light_info.Scale or 2), 64, 512) @@ -101,7 +95,7 @@ if CLIENT then projtex:SetFOV( self:GetFOV() ) projtex:SetFarZ( self:GetDistance() ) projtex:SetBrightness( self:GetBrightness() / 255 ) - projtex:SetColor( Color( self:GetRed(), self:GetGreen(), self:GetBlue() ) ) + projtex:SetColor( self:GetColor() ) projtex:Update() end @@ -125,14 +119,22 @@ if CLIENT then local lightpos = self:LocalToWorld(light_info.Offset or vector_offset) local lampMatrix = self:GetWorldTransformMatrix() - local lastLampMatrix = self.LastLampMatrix or 0 + local lastLampMatrix = self.LastLampMatrix if lastLampMatrix ~= lampMatrix then local projtex = self.ProjTex projtex:SetPos( lightpos ) projtex:SetAngles( self:LocalToWorldAngles( light_info.Angle or angle_zero ) ) projtex:Update() + + self.LastLampMatrix = lampMatrix + end + + local lastColor = self.LastColor + local currentColor = self:GetColor() + if lastColor ~= currentColor then + self:UpdateProjTex() + self.LastColor = currentColor end - self.LastLampMatrix = lampMatrix end function ENT:OnRemove() @@ -152,15 +154,22 @@ end function ENT:TriggerInput(name, value) if name == "Red" then - self:SetRed(math.Clamp(value, 0, 255)) + local currentColor = self:GetColor() + currentColor.r = math.Clamp(value, 0, 255) + self:SetColor(currentColor) elseif name == "Green" then - self:SetGreen(math.Clamp(value, 0, 255)) + local currentColor = self:GetColor() + currentColor.g = math.Clamp(value, 0, 255) + self:SetColor(currentColor) elseif name == "Blue" then - self:SetBlue(math.Clamp(value, 0, 255)) + local currentColor = self:GetColor() + currentColor.b = math.Clamp(value, 0, 255) + self:SetColor(currentColor) elseif name == "RGB" then - self:SetRed(math.Clamp(value.r, 0, 255)) - self:SetGreen(math.Clamp(value.g, 0, 255)) - self:SetBlue(math.Clamp(value.b, 0, 255)) + local r = math.Clamp(value[1], 0, 255) + local g = math.Clamp(value[2], 0, 255) + local b = math.Clamp(value[3], 0, 255) + self:SetColor(Color(r, g, b)) elseif name == "FOV" then self:SetFOV(value) elseif name == "Distance" then @@ -183,9 +192,7 @@ function ENT:Setup(r, g, b, texture, fov, distance, brightness, on) g = math.Clamp(g or 255, 0, 255) b = math.Clamp(b or 255, 0, 255) - self:SetRed(r) - self:SetGreen(g) - self:SetBlue(b) + self:SetColor(Color(r, g, b)) self:SetTexture(texture or "effects/flashlight001") self:SetFOV(fov or 90) self:SetDistance(distance or 1024) From 86d25c8f407e9ed08a4b24d8c5b7287c8f7c75c9 Mon Sep 17 00:00:00 2001 From: Redox <69946827+wrefgtzweve@users.noreply.github.com> Date: Mon, 8 Dec 2025 20:47:28 +0100 Subject: [PATCH 11/18] Revert "Use entity color for lamp color" This reverts commit e420e8dfe294569e9cb8557c751b3aa8d89c4cfe. --- lua/entities/gmod_wire_lamp.lua | 45 ++++++++++++++------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/lua/entities/gmod_wire_lamp.lua b/lua/entities/gmod_wire_lamp.lua index aa7d52d515..bd4b76d6e3 100644 --- a/lua/entities/gmod_wire_lamp.lua +++ b/lua/entities/gmod_wire_lamp.lua @@ -8,6 +8,9 @@ ENT.WireDebugName = "Lamp" function ENT:SetupDataTables() self:NetworkVar("Bool", "On") self:NetworkVar("Int", "FOV") + self:NetworkVar("Int", "Red") + self:NetworkVar("Int", "Green") + self:NetworkVar("Int", "Blue") self:NetworkVar("Int", "Distance") self:NetworkVar("Int", "Brightness") self:NetworkVar("String", "Texture") @@ -17,6 +20,9 @@ function ENT:SetupDataTables() self:OnVarChanged( ... ) end self:NetworkVarNotify( "FOV", callOnVarChanged ) + self:NetworkVarNotify( "Red", callOnVarChanged ) + self:NetworkVarNotify( "Green", callOnVarChanged ) + self:NetworkVarNotify( "Blue", callOnVarChanged ) self:NetworkVarNotify( "Distance", callOnVarChanged ) self:NetworkVarNotify( "Brightness", callOnVarChanged ) self:NetworkVarNotify( "Texture", callOnVarChanged ) @@ -71,7 +77,7 @@ if CLIENT then render.SetMaterial(light) - local color = self:GetColor() + local color = Color(self:GetRed(), self:GetGreen(), self:GetBlue()) color.a = math.Clamp((1000 - math.Clamp(distance, 32, 800)) * visdot, 0, 100) local size = math.Clamp(distance * visdot * (light_info.Scale or 2), 64, 512) @@ -95,7 +101,7 @@ if CLIENT then projtex:SetFOV( self:GetFOV() ) projtex:SetFarZ( self:GetDistance() ) projtex:SetBrightness( self:GetBrightness() / 255 ) - projtex:SetColor( self:GetColor() ) + projtex:SetColor( Color( self:GetRed(), self:GetGreen(), self:GetBlue() ) ) projtex:Update() end @@ -119,22 +125,14 @@ if CLIENT then local lightpos = self:LocalToWorld(light_info.Offset or vector_offset) local lampMatrix = self:GetWorldTransformMatrix() - local lastLampMatrix = self.LastLampMatrix + local lastLampMatrix = self.LastLampMatrix or 0 if lastLampMatrix ~= lampMatrix then local projtex = self.ProjTex projtex:SetPos( lightpos ) projtex:SetAngles( self:LocalToWorldAngles( light_info.Angle or angle_zero ) ) projtex:Update() - - self.LastLampMatrix = lampMatrix - end - - local lastColor = self.LastColor - local currentColor = self:GetColor() - if lastColor ~= currentColor then - self:UpdateProjTex() - self.LastColor = currentColor end + self.LastLampMatrix = lampMatrix end function ENT:OnRemove() @@ -154,22 +152,15 @@ end function ENT:TriggerInput(name, value) if name == "Red" then - local currentColor = self:GetColor() - currentColor.r = math.Clamp(value, 0, 255) - self:SetColor(currentColor) + self:SetRed(math.Clamp(value, 0, 255)) elseif name == "Green" then - local currentColor = self:GetColor() - currentColor.g = math.Clamp(value, 0, 255) - self:SetColor(currentColor) + self:SetGreen(math.Clamp(value, 0, 255)) elseif name == "Blue" then - local currentColor = self:GetColor() - currentColor.b = math.Clamp(value, 0, 255) - self:SetColor(currentColor) + self:SetBlue(math.Clamp(value, 0, 255)) elseif name == "RGB" then - local r = math.Clamp(value[1], 0, 255) - local g = math.Clamp(value[2], 0, 255) - local b = math.Clamp(value[3], 0, 255) - self:SetColor(Color(r, g, b)) + self:SetRed(math.Clamp(value.r, 0, 255)) + self:SetGreen(math.Clamp(value.g, 0, 255)) + self:SetBlue(math.Clamp(value.b, 0, 255)) elseif name == "FOV" then self:SetFOV(value) elseif name == "Distance" then @@ -192,7 +183,9 @@ function ENT:Setup(r, g, b, texture, fov, distance, brightness, on) g = math.Clamp(g or 255, 0, 255) b = math.Clamp(b or 255, 0, 255) - self:SetColor(Color(r, g, b)) + self:SetRed(r) + self:SetGreen(g) + self:SetBlue(b) self:SetTexture(texture or "effects/flashlight001") self:SetFOV(fov or 90) self:SetDistance(distance or 1024) From b29d5e05e5c19c9f0c2fc8e4ad77b342d1920ac4 Mon Sep 17 00:00:00 2001 From: Redox <69946827+wrefgtzweve@users.noreply.github.com> Date: Thu, 11 Dec 2025 15:04:34 +0100 Subject: [PATCH 12/18] Enable shadows --- lua/entities/gmod_wire_lamp.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/entities/gmod_wire_lamp.lua b/lua/entities/gmod_wire_lamp.lua index bd4b76d6e3..6dd5121345 100644 --- a/lua/entities/gmod_wire_lamp.lua +++ b/lua/entities/gmod_wire_lamp.lua @@ -96,7 +96,6 @@ if CLIENT then local projtex = self.ProjTex if not IsValid(projtex) then return end - projtex:SetEnableShadows( false ) projtex:SetTexture( self:GetTexture() ) projtex:SetFOV( self:GetFOV() ) projtex:SetFarZ( self:GetDistance() ) From d857fe9970901dcc4238dd7d3c5601067b4a7d6c Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Thu, 11 Dec 2025 17:46:16 +0300 Subject: [PATCH 13/18] Cleanup lamps --- lua/entities/gmod_wire_lamp.lua | 160 ++++++++++++++++---------------- lua/wire/stools/lamp.lua | 5 +- 2 files changed, 81 insertions(+), 84 deletions(-) diff --git a/lua/entities/gmod_wire_lamp.lua b/lua/entities/gmod_wire_lamp.lua index 6dd5121345..17fcdcd98c 100644 --- a/lua/entities/gmod_wire_lamp.lua +++ b/lua/entities/gmod_wire_lamp.lua @@ -16,16 +16,13 @@ function ENT:SetupDataTables() self:NetworkVar("String", "Texture") if CLIENT then - local function callOnVarChanged( _, ... ) -- Fixes autorefresh - self:OnVarChanged( ... ) - end - self:NetworkVarNotify( "FOV", callOnVarChanged ) - self:NetworkVarNotify( "Red", callOnVarChanged ) - self:NetworkVarNotify( "Green", callOnVarChanged ) - self:NetworkVarNotify( "Blue", callOnVarChanged ) - self:NetworkVarNotify( "Distance", callOnVarChanged ) - self:NetworkVarNotify( "Brightness", callOnVarChanged ) - self:NetworkVarNotify( "Texture", callOnVarChanged ) + self:NetworkVarNotify("FOV", self.OnVarChanged) + self:NetworkVarNotify("Red", self.OnVarChanged) + self:NetworkVarNotify("Green", self.OnVarChanged) + self:NetworkVarNotify("Blue", self.OnVarChanged) + self:NetworkVarNotify("Distance", self.OnVarChanged) + self:NetworkVarNotify("Brightness", self.OnVarChanged) + self:NetworkVarNotify("Texture", self.OnVarChanged) end end @@ -56,97 +53,104 @@ local vector_offset = Vector(5, 0, 0) if CLIENT then local light = Material("sprites/light_ignorez") - function ENT:DrawEffects() - if not self:GetOn() then return end - - local light_info = self:GetLightInfo() - local lightpos = self:LocalToWorld(light_info.Offset or vector_offset) + function ENT:DrawTranslucent(flags) + BaseClass.DrawTranslucent(self, flags) - local viewnormal = EyePos() - viewnormal:Negate() - viewnormal:Add(lightpos) + if self:GetOn() then + local light_info = self:GetLightInfo() + local lightpos = self:LocalToWorld(light_info.Offset or vector_offset) - local distance = viewnormal:Length() - viewnormal:Negate() + local viewnormal = EyePos() + viewnormal:Negate() + viewnormal:Add(lightpos) - local viewdot = viewnormal:Dot(self:LocalToWorldAngles(light_info.Angle or angle_zero):Forward()) / distance - if viewdot < 0 then return end + local distance = viewnormal:Length() + viewnormal:Negate() - local visibile = util.PixelVisible(lightpos, 16, self.PixVis) - local visdot = visibile * viewdot + local viewdot = viewnormal:Dot(self:LocalToWorldAngles(light_info.Angle or angle_zero):Forward()) / distance + if viewdot < 0 then return end - render.SetMaterial(light) + local visibile = util.PixelVisible(lightpos, 16, self.PixVis) + local visdot = visibile * viewdot - local color = Color(self:GetRed(), self:GetGreen(), self:GetBlue()) - color.a = math.Clamp((1000 - math.Clamp(distance, 32, 800)) * visdot, 0, 100) + render.SetMaterial(light) - local size = math.Clamp(distance * visdot * (light_info.Scale or 2), 64, 512) - render.DrawSprite(lightpos, size, size, color) + local color = Color(self:GetRed(), self:GetGreen(), self:GetBlue()) + color.a = math.Clamp((1000 - math.Clamp(distance, 32, 800)) * visdot, 0, 100) - color.r, color.g, color.b = 255, 255, 255 - render.DrawSprite(lightpos, size * 0.4, size * 0.4, color) - end + local size = math.Clamp(distance * visdot * (light_info.Scale or 2), 64, 512) + render.DrawSprite(lightpos, size, size, color) - function ENT:DrawTranslucent(flags) - BaseClass.DrawTranslucent(self, flags) - self:DrawEffects() + color.r, color.g, color.b = 255, 255, 255 + render.DrawSprite(lightpos, size * 0.4, size * 0.4, color) + end end - function ENT:UpdateProjTex() - local projtex = self.ProjTex - if not IsValid(projtex) then return end + function ENT:OnVarChanged(name, old, new) + local flashlight = self.Flashlight + if not flashlight then return end + + if name == "FOV" then + flashlight:SetFOV(game.SinglePlayer() and new or math.Clamp(new, 0, 170)) + elseif name == "Red" then + flashlight:SetColor(Color(new, self:GetGreen(), self:GetBlue())) + elseif name == "Green" then + flashlight:SetColor(Color(self:GetRed(), new, self:GetBlue())) + elseif name == "Blue" then + flashlight:SetColor(Color(self:GetRed(), self:GetGreen(), new)) + elseif name == "Distance" then + flashlight:SetFarZ(game.SinglePlayer() and new or math.Clamp(new, 64, 2048)) + elseif name == "Brightness" then + flashlight:SetBrightness(game.SinglePlayer() and new or math.Clamp(new, 0, 8)) + elseif name == "Texture" then + flashlight:SetTexture(new) + end - projtex:SetTexture( self:GetTexture() ) - projtex:SetFOV( self:GetFOV() ) - projtex:SetFarZ( self:GetDistance() ) - projtex:SetBrightness( self:GetBrightness() / 255 ) - projtex:SetColor( Color( self:GetRed(), self:GetGreen(), self:GetBlue() ) ) - projtex:Update() + self.LastLampMatrix = nil end function ENT:Think() if not self:GetOn() then - if IsValid( self.ProjTex ) then - self.ProjTex:Remove() - self.ProjTex = nil - self.LastLampMatrix = nil - end + self:OnRemove() + return end - -- Projected texture - if not IsValid( self.ProjTex ) then - self.ProjTex = ProjectedTexture() - self:UpdateProjTex() + if not self.Flashlight then + local flashlight = ProjectedTexture() + local singleplayer = game.SinglePlayer() + + flashlight:SetFOV(singleplayer and self:GetFOV() or math.Clamp(self:GetFOV(), 0, 170)) + flashlight:SetColor(Color(self:GetRed(), self:GetGreen(), self:GetBlue())) + flashlight:SetFarZ(singleplayer and self:GetDistance() or math.Clamp(self:GetDistance(), 64, 2048)) + flashlight:SetBrightness(singleplayer and self:GetBrightness() or math.Clamp(self:GetBrightness(), 0, 8)) + flashlight:SetTexture(self:GetTexture()) + + self.Flashlight = flashlight end - local light_info = self:GetLightInfo() - local lightpos = self:LocalToWorld(light_info.Offset or vector_offset) + local matrix = self:GetWorldTransformMatrix() + + if self.LastLampMatrix ~= matrix then + local flashlight = self.Flashlight + local light_info = self:GetLightInfo() + local lightpos = self:LocalToWorld(light_info.Offset or vector_offset) - local lampMatrix = self:GetWorldTransformMatrix() - local lastLampMatrix = self.LastLampMatrix or 0 - if lastLampMatrix ~= lampMatrix then - local projtex = self.ProjTex - projtex:SetPos( lightpos ) - projtex:SetAngles( self:LocalToWorldAngles( light_info.Angle or angle_zero ) ) - projtex:Update() + flashlight:SetPos(lightpos) + flashlight:SetAngles(self:LocalToWorldAngles(light_info.Angle or angle_zero)) + flashlight:Update() + + self.LastLampMatrix = lampMatrix end - self.LastLampMatrix = lampMatrix end function ENT:OnRemove() - if IsValid( self.ProjTex ) then - self.ProjTex:Remove() + if self.Flashlight then + self.Flashlight:Remove() + self.Flashlight = nil + self.LastLampMatrix = nil end end - - function ENT:OnVarChanged( varname, oldvalue, newvalue ) - timer.Simple( 0, function() - if not IsValid( self ) then return end - if not IsValid( self.ProjTex ) then return end - self:UpdateProjTex() - end ) - end end function ENT:TriggerInput(name, value) @@ -178,13 +182,9 @@ function ENT:TriggerInput(name, value) end function ENT:Setup(r, g, b, texture, fov, distance, brightness, on) - r = math.Clamp(r or 255, 0, 255) - g = math.Clamp(g or 255, 0, 255) - b = math.Clamp(b or 255, 0, 255) - - self:SetRed(r) - self:SetGreen(g) - self:SetBlue(b) + self:SetRed(math.Clamp(r or 255, 0, 255)) + self:SetGreen(math.Clamp(g or 255, 0, 255)) + self:SetBlue(math.Clamp(b or 255, 0, 255)) self:SetTexture(texture or "effects/flashlight001") self:SetFOV(fov or 90) self:SetDistance(distance or 1024) diff --git a/lua/wire/stools/lamp.lua b/lua/wire/stools/lamp.lua index 3b62208574..ca2afce540 100644 --- a/lua/wire/stools/lamp.lua +++ b/lua/wire/stools/lamp.lua @@ -133,6 +133,7 @@ function TOOL.BuildCPanel(panel) WireToolHelpers.MakePresetControl(panel, "wire_lamp") WireDermaExts.ModelSelect(panel, "wire_lamp_model", list.Get("LampModels"), 1, true) + panel:CheckBox("Start On", "wire_lamp_on") panel:NumSlider("Rope Length:", "wire_lamp_ropelength", 4, 400, 0) panel:NumSlider("FOV:", "wire_lamp_fov", 10, 170, 2) panel:NumSlider("Distance:", "wire_lamp_distance", 64, 2048, 0) @@ -142,10 +143,6 @@ function TOOL.BuildCPanel(panel) combobox:AddChoice("Rope", "rope") combobox:AddChoice("Weld", "weld") combobox:AddChoice("None", "none") - - local startOn = panel:CheckBox("Start On", "wire_lamp_on") - startOn:SetTooltip("If checked, the lamp will be on when spawned.") - panel:ColorPicker("Color", "wire_lamp_r", "wire_lamp_g", "wire_lamp_b") local matselect = panel:MatSelect("wire_lamp_texture", nil, true, 0.33, 0.33) From c6e1f11916b0b622de6a6fb0bb8c2b32d83378ed Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Thu, 11 Dec 2025 17:49:06 +0300 Subject: [PATCH 14/18] Fix --- lua/entities/gmod_wire_lamp.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/entities/gmod_wire_lamp.lua b/lua/entities/gmod_wire_lamp.lua index 17fcdcd98c..0ef5a7afe2 100644 --- a/lua/entities/gmod_wire_lamp.lua +++ b/lua/entities/gmod_wire_lamp.lua @@ -140,7 +140,7 @@ if CLIENT then flashlight:SetAngles(self:LocalToWorldAngles(light_info.Angle or angle_zero)) flashlight:Update() - self.LastLampMatrix = lampMatrix + self.LastLampMatrix = matrix end end From 97b38806316322b23c39818ae8060523208e8059 Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Thu, 11 Dec 2025 17:58:29 +0300 Subject: [PATCH 15/18] Small resorting --- lua/entities/gmod_wire_lamp.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lua/entities/gmod_wire_lamp.lua b/lua/entities/gmod_wire_lamp.lua index 0ef5a7afe2..e8e263d598 100644 --- a/lua/entities/gmod_wire_lamp.lua +++ b/lua/entities/gmod_wire_lamp.lua @@ -154,7 +154,11 @@ if CLIENT then end function ENT:TriggerInput(name, value) - if name == "Red" then + if name == "On" then + self:SetOn(value ~= 0) + elseif name == "FOV" then + self:SetFOV(value) + elseif name == "Red" then self:SetRed(math.Clamp(value, 0, 255)) elseif name == "Green" then self:SetGreen(math.Clamp(value, 0, 255)) @@ -164,14 +168,10 @@ function ENT:TriggerInput(name, value) self:SetRed(math.Clamp(value.r, 0, 255)) self:SetGreen(math.Clamp(value.g, 0, 255)) self:SetBlue(math.Clamp(value.b, 0, 255)) - elseif name == "FOV" then - self:SetFOV(value) elseif name == "Distance" then self:SetDistance(value) elseif name == "Brightness" then self:SetBrightness(value) - elseif name == "On" then - self:SetOn(value ~= 0) elseif name == "Texture" then if value ~= "" then self:SetTexture(value) @@ -182,14 +182,14 @@ function ENT:TriggerInput(name, value) end function ENT:Setup(r, g, b, texture, fov, distance, brightness, on) + self:SetOn(on and true or false) + self:SetFOV(fov or 90) self:SetRed(math.Clamp(r or 255, 0, 255)) self:SetGreen(math.Clamp(g or 255, 0, 255)) self:SetBlue(math.Clamp(b or 255, 0, 255)) - self:SetTexture(texture or "effects/flashlight001") - self:SetFOV(fov or 90) self:SetDistance(distance or 1024) self:SetBrightness(brightness or 8) - self:SetOn(on and true or false) + self:SetTexture(texture or "effects/flashlight001") end duplicator.RegisterEntityClass("gmod_wire_lamp", WireLib.MakeWireEnt, "Data", "r", "g", "b", "Texture", "FOV", "Dist", "Brightness", "on") From a047e0c6490f8996b2e9b2c64a330e128951ed78 Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Thu, 11 Dec 2025 18:19:01 +0300 Subject: [PATCH 16/18] More cleanups & checks --- lua/entities/gmod_wire_lamp.lua | 57 +++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/lua/entities/gmod_wire_lamp.lua b/lua/entities/gmod_wire_lamp.lua index e8e263d598..74d751fd02 100644 --- a/lua/entities/gmod_wire_lamp.lua +++ b/lua/entities/gmod_wire_lamp.lua @@ -8,18 +8,12 @@ ENT.WireDebugName = "Lamp" function ENT:SetupDataTables() self:NetworkVar("Bool", "On") self:NetworkVar("Int", "FOV") - self:NetworkVar("Int", "Red") - self:NetworkVar("Int", "Green") - self:NetworkVar("Int", "Blue") self:NetworkVar("Int", "Distance") self:NetworkVar("Int", "Brightness") self:NetworkVar("String", "Texture") if CLIENT then self:NetworkVarNotify("FOV", self.OnVarChanged) - self:NetworkVarNotify("Red", self.OnVarChanged) - self:NetworkVarNotify("Green", self.OnVarChanged) - self:NetworkVarNotify("Blue", self.OnVarChanged) self:NetworkVarNotify("Distance", self.OnVarChanged) self:NetworkVarNotify("Brightness", self.OnVarChanged) self:NetworkVarNotify("Texture", self.OnVarChanged) @@ -75,7 +69,7 @@ if CLIENT then render.SetMaterial(light) - local color = Color(self:GetRed(), self:GetGreen(), self:GetBlue()) + local color = self:GetColor() color.a = math.Clamp((1000 - math.Clamp(distance, 32, 800)) * visdot, 0, 100) local size = math.Clamp(distance * visdot * (light_info.Scale or 2), 64, 512) @@ -92,12 +86,6 @@ if CLIENT then if name == "FOV" then flashlight:SetFOV(game.SinglePlayer() and new or math.Clamp(new, 0, 170)) - elseif name == "Red" then - flashlight:SetColor(Color(new, self:GetGreen(), self:GetBlue())) - elseif name == "Green" then - flashlight:SetColor(Color(self:GetRed(), new, self:GetBlue())) - elseif name == "Blue" then - flashlight:SetColor(Color(self:GetRed(), self:GetGreen(), new)) elseif name == "Distance" then flashlight:SetFarZ(game.SinglePlayer() and new or math.Clamp(new, 64, 2048)) elseif name == "Brightness" then @@ -121,7 +109,6 @@ if CLIENT then local singleplayer = game.SinglePlayer() flashlight:SetFOV(singleplayer and self:GetFOV() or math.Clamp(self:GetFOV(), 0, 170)) - flashlight:SetColor(Color(self:GetRed(), self:GetGreen(), self:GetBlue())) flashlight:SetFarZ(singleplayer and self:GetDistance() or math.Clamp(self:GetDistance(), 64, 2048)) flashlight:SetBrightness(singleplayer and self:GetBrightness() or math.Clamp(self:GetBrightness(), 0, 8)) flashlight:SetTexture(self:GetTexture()) @@ -130,17 +117,20 @@ if CLIENT then end local matrix = self:GetWorldTransformMatrix() + local color = self:GetColor() - if self.LastLampMatrix ~= matrix then + if self.LastLampMatrix ~= matrix or self.LastLampColor ~= color then local flashlight = self.Flashlight local light_info = self:GetLightInfo() local lightpos = self:LocalToWorld(light_info.Offset or vector_offset) + flashlight:SetColor(color) flashlight:SetPos(lightpos) flashlight:SetAngles(self:LocalToWorldAngles(light_info.Angle or angle_zero)) flashlight:Update() self.LastLampMatrix = matrix + self.LastLampColor = color end end @@ -149,25 +139,38 @@ if CLIENT then self.Flashlight:Remove() self.Flashlight = nil self.LastLampMatrix = nil + self.LastLampColor = nil end end + + return end function ENT:TriggerInput(name, value) + local color = self:GetColor() + if name == "On" then self:SetOn(value ~= 0) elseif name == "FOV" then self:SetFOV(value) elseif name == "Red" then - self:SetRed(math.Clamp(value, 0, 255)) + local color = self:GetColor() + color.r = value + self:SetColor(color) elseif name == "Green" then - self:SetGreen(math.Clamp(value, 0, 255)) + local color = self:GetColor() + color.g = value + self:SetColor(color) elseif name == "Blue" then - self:SetBlue(math.Clamp(value, 0, 255)) + local color = self:GetColor() + color.b = value + self:SetColor(color) elseif name == "RGB" then - self:SetRed(math.Clamp(value.r, 0, 255)) - self:SetGreen(math.Clamp(value.g, 0, 255)) - self:SetBlue(math.Clamp(value.b, 0, 255)) + local color = self:GetColor() + color.r = value.r + color.g = value.g + color.b = value.b + self:SetColor(color) elseif name == "Distance" then self:SetDistance(value) elseif name == "Brightness" then @@ -181,15 +184,21 @@ function ENT:TriggerInput(name, value) end end +function ENT:PrepareOverlayData() + local color = self:GetColor() + self:SetOverlayText(string.format("Red: %i Green: %i Blue: %i\nFOV: %i Distance: %i Brightness: %i", color.r, color.g, color.b, self:GetFOV(), self:GetDistance(), self:GetBrightness())) +end + function ENT:Setup(r, g, b, texture, fov, distance, brightness, on) self:SetOn(on and true or false) self:SetFOV(fov or 90) - self:SetRed(math.Clamp(r or 255, 0, 255)) - self:SetGreen(math.Clamp(g or 255, 0, 255)) - self:SetBlue(math.Clamp(b or 255, 0, 255)) self:SetDistance(distance or 1024) self:SetBrightness(brightness or 8) self:SetTexture(texture or "effects/flashlight001") + + local color = self:GetColor() + color.r, color.g, color.b = math.Clamp(r or 255, 0, 255), math.Clamp(g or 255, 0, 255), math.Clamp(b or 255, 0, 255) + self:SetColor(color) end duplicator.RegisterEntityClass("gmod_wire_lamp", WireLib.MakeWireEnt, "Data", "r", "g", "b", "Texture", "FOV", "Dist", "Brightness", "on") From ddf4069e6734808e13a601024819c54694222c2c Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Thu, 11 Dec 2025 18:19:56 +0300 Subject: [PATCH 17/18] Reset this value too --- lua/entities/gmod_wire_lamp.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/entities/gmod_wire_lamp.lua b/lua/entities/gmod_wire_lamp.lua index 74d751fd02..64dbcd1b31 100644 --- a/lua/entities/gmod_wire_lamp.lua +++ b/lua/entities/gmod_wire_lamp.lua @@ -95,6 +95,7 @@ if CLIENT then end self.LastLampMatrix = nil + self.LastLampColor = nil end function ENT:Think() From bd657f4cb82260ae14991517276324967df643dc Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Thu, 11 Dec 2025 18:28:22 +0300 Subject: [PATCH 18/18] Final changes --- lua/entities/gmod_wire_lamp.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lua/entities/gmod_wire_lamp.lua b/lua/entities/gmod_wire_lamp.lua index 64dbcd1b31..a582064ca5 100644 --- a/lua/entities/gmod_wire_lamp.lua +++ b/lua/entities/gmod_wire_lamp.lua @@ -106,11 +106,13 @@ if CLIENT then end if not self.Flashlight then + local light_info = self:GetLightInfo() local flashlight = ProjectedTexture() local singleplayer = game.SinglePlayer() - flashlight:SetFOV(singleplayer and self:GetFOV() or math.Clamp(self:GetFOV(), 0, 170)) + flashlight:SetNearZ(light_info.NearZ or 12) flashlight:SetFarZ(singleplayer and self:GetDistance() or math.Clamp(self:GetDistance(), 64, 2048)) + flashlight:SetFOV(singleplayer and self:GetFOV() or math.Clamp(self:GetFOV(), 0, 170)) flashlight:SetBrightness(singleplayer and self:GetBrightness() or math.Clamp(self:GetBrightness(), 0, 8)) flashlight:SetTexture(self:GetTexture())