@@ -8,18 +8,12 @@ ENT.WireDebugName = "Lamp"
88function ENT :SetupDataTables ()
99 self :NetworkVar (" Bool" , " On" )
1010 self :NetworkVar (" Int" , " FOV" )
11- self :NetworkVar (" Int" , " Red" )
12- self :NetworkVar (" Int" , " Green" )
13- self :NetworkVar (" Int" , " Blue" )
1411 self :NetworkVar (" Int" , " Distance" )
1512 self :NetworkVar (" Int" , " Brightness" )
1613 self :NetworkVar (" String" , " Texture" )
1714
1815 if CLIENT then
1916 self :NetworkVarNotify (" FOV" , self .OnVarChanged )
20- self :NetworkVarNotify (" Red" , self .OnVarChanged )
21- self :NetworkVarNotify (" Green" , self .OnVarChanged )
22- self :NetworkVarNotify (" Blue" , self .OnVarChanged )
2317 self :NetworkVarNotify (" Distance" , self .OnVarChanged )
2418 self :NetworkVarNotify (" Brightness" , self .OnVarChanged )
2519 self :NetworkVarNotify (" Texture" , self .OnVarChanged )
@@ -75,7 +69,7 @@ if CLIENT then
7569
7670 render .SetMaterial (light )
7771
78- local color = Color ( self :GetRed (), self : GetGreen (), self : GetBlue () )
72+ local color = self :GetColor ( )
7973 color .a = math .Clamp ((1000 - math .Clamp (distance , 32 , 800 )) * visdot , 0 , 100 )
8074
8175 local size = math .Clamp (distance * visdot * (light_info .Scale or 2 ), 64 , 512 )
@@ -92,12 +86,6 @@ if CLIENT then
9286
9387 if name == " FOV" then
9488 flashlight :SetFOV (game .SinglePlayer () and new or math .Clamp (new , 0 , 170 ))
95- elseif name == " Red" then
96- flashlight :SetColor (Color (new , self :GetGreen (), self :GetBlue ()))
97- elseif name == " Green" then
98- flashlight :SetColor (Color (self :GetRed (), new , self :GetBlue ()))
99- elseif name == " Blue" then
100- flashlight :SetColor (Color (self :GetRed (), self :GetGreen (), new ))
10189 elseif name == " Distance" then
10290 flashlight :SetFarZ (game .SinglePlayer () and new or math .Clamp (new , 64 , 2048 ))
10391 elseif name == " Brightness" then
@@ -121,7 +109,6 @@ if CLIENT then
121109 local singleplayer = game .SinglePlayer ()
122110
123111 flashlight :SetFOV (singleplayer and self :GetFOV () or math .Clamp (self :GetFOV (), 0 , 170 ))
124- flashlight :SetColor (Color (self :GetRed (), self :GetGreen (), self :GetBlue ()))
125112 flashlight :SetFarZ (singleplayer and self :GetDistance () or math .Clamp (self :GetDistance (), 64 , 2048 ))
126113 flashlight :SetBrightness (singleplayer and self :GetBrightness () or math .Clamp (self :GetBrightness (), 0 , 8 ))
127114 flashlight :SetTexture (self :GetTexture ())
@@ -130,17 +117,20 @@ if CLIENT then
130117 end
131118
132119 local matrix = self :GetWorldTransformMatrix ()
120+ local color = self :GetColor ()
133121
134- if self .LastLampMatrix ~= matrix then
122+ if self .LastLampMatrix ~= matrix or self . LastLampColor ~= color then
135123 local flashlight = self .Flashlight
136124 local light_info = self :GetLightInfo ()
137125 local lightpos = self :LocalToWorld (light_info .Offset or vector_offset )
138126
127+ flashlight :SetColor (color )
139128 flashlight :SetPos (lightpos )
140129 flashlight :SetAngles (self :LocalToWorldAngles (light_info .Angle or angle_zero ))
141130 flashlight :Update ()
142131
143132 self .LastLampMatrix = matrix
133+ self .LastLampColor = color
144134 end
145135 end
146136
@@ -149,25 +139,38 @@ if CLIENT then
149139 self .Flashlight :Remove ()
150140 self .Flashlight = nil
151141 self .LastLampMatrix = nil
142+ self .LastLampColor = nil
152143 end
153144 end
145+
146+ return
154147end
155148
156149function ENT :TriggerInput (name , value )
150+ local color = self :GetColor ()
151+
157152 if name == " On" then
158153 self :SetOn (value ~= 0 )
159154 elseif name == " FOV" then
160155 self :SetFOV (value )
161156 elseif name == " Red" then
162- self :SetRed (math .Clamp (value , 0 , 255 ))
157+ local color = self :GetColor ()
158+ color .r = value
159+ self :SetColor (color )
163160 elseif name == " Green" then
164- self :SetGreen (math .Clamp (value , 0 , 255 ))
161+ local color = self :GetColor ()
162+ color .g = value
163+ self :SetColor (color )
165164 elseif name == " Blue" then
166- self :SetBlue (math .Clamp (value , 0 , 255 ))
165+ local color = self :GetColor ()
166+ color .b = value
167+ self :SetColor (color )
167168 elseif name == " RGB" then
168- self :SetRed (math .Clamp (value .r , 0 , 255 ))
169- self :SetGreen (math .Clamp (value .g , 0 , 255 ))
170- self :SetBlue (math .Clamp (value .b , 0 , 255 ))
169+ local color = self :GetColor ()
170+ color .r = value .r
171+ color .g = value .g
172+ color .b = value .b
173+ self :SetColor (color )
171174 elseif name == " Distance" then
172175 self :SetDistance (value )
173176 elseif name == " Brightness" then
@@ -181,15 +184,21 @@ function ENT:TriggerInput(name, value)
181184 end
182185end
183186
187+ function ENT :PrepareOverlayData ()
188+ local color = self :GetColor ()
189+ self :SetOverlayText (string.format (" Red: %i Green: %i Blue: %i\n FOV: %i Distance: %i Brightness: %i" , color .r , color .g , color .b , self :GetFOV (), self :GetDistance (), self :GetBrightness ()))
190+ end
191+
184192function ENT :Setup (r , g , b , texture , fov , distance , brightness , on )
185193 self :SetOn (on and true or false )
186194 self :SetFOV (fov or 90 )
187- self :SetRed (math .Clamp (r or 255 , 0 , 255 ))
188- self :SetGreen (math .Clamp (g or 255 , 0 , 255 ))
189- self :SetBlue (math .Clamp (b or 255 , 0 , 255 ))
190195 self :SetDistance (distance or 1024 )
191196 self :SetBrightness (brightness or 8 )
192197 self :SetTexture (texture or " effects/flashlight001" )
198+
199+ local color = self :GetColor ()
200+ 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 )
201+ self :SetColor (color )
193202end
194203
195204duplicator .RegisterEntityClass (" gmod_wire_lamp" , WireLib .MakeWireEnt , " Data" , " r" , " g" , " b" , " Texture" , " FOV" , " Dist" , " Brightness" , " on" )
0 commit comments