rendered paste bodyTOOL.Category = "Render"TOOL.Name = "#Dynamic Light"TOOL.Command = nilTOOL.ConfigName = ""TOOL.ClientConVar["r"] = "255"TOOL.ClientConVar["g"] = "255"TOOL.ClientConVar["b"] = "255"TOOL.ClientConVar["a"] = "255"TOOL.ClientConVar["fx"] = "0"TOOL.ClientConVar["distance"] = "50"TOOL.ClientConVar["brightness"] = "5"TOOL.ClientConVar["key"] = "5"TOOL.ClientConVar["toggle"] = "1"TOOL.ClientConVar["starton"] = "1"cleanup.Register( "dynlight" )if SERVER then CreateConVar( "sbox_maxdynlights", 5 ) function dynlight_toggle( ply, ent ) if not ent:IsValid() then return end ent:Fire("toggle","","0") end numpad.Register( "dynlighttoggle", dynlight_toggle ) function makedynlightfix( trace, r, g, b, a, fx, distance, brightness ) local dynlightfix = ents.Create( "light_dynamic" ) dynlightfix:SetPos( trace.HitPos ) dynlightfix:SetKeyValue( "_light", r .. " " .. g .. " " .. b .. " " .. a ) dynlightfix:SetKeyValue( "style", fx ) dynlightfix:SetKeyValue( "distance", distance ) dynlightfix:SetKeyValue( "brightness", brightness ) dynlightfix:Spawn() dynlightfix:Fire("toggle","","0") dynlightfix:Remove() end function makedynlight( ply, trace, Ang, r, g, b, a, fx, distance, brightness, key ) local dynlightp = ents.Create( "prop_physics" ) dynlightp:SetPos( trace.HitPos ) dynlightp:SetModel( "models/items/combine_rifle_ammo01.mdl" ) dynlightp:SetKeyValue( "disableshadows", "1" ) dynlightp:Spawn() local dynlight = ents.Create( "light_dynamic" ) dynlight:SetPos( trace.HitPos ) local dynlightpos = dynlight:GetPos()+Vector( 0, 0, 7 ) dynlight:SetPos( dynlightpos ) dynlight:SetKeyValue( "_light", r .. " " .. g .. " " .. b .. " " .. a ) dynlight:SetKeyValue( "style", fx ) dynlight:SetKeyValue( "distance", distance ) dynlight:SetKeyValue( "brightness", brightness ) dynlight:SetParent( dynlightp ) dynlight:Spawn() dynlightp:SetAngles( Ang ) dynlightp:CallOnRemove( "dynlightfix", makedynlightfix, trace, r, g, b, a, fx, distance, brightness ) if ( trace.Entity:IsValid() ) then const = constraint.Weld( dynlightp, trace.Entity,0, trace.PhysicsBone, 0, systemmanager ) nocollide = constraint.NoCollide( dynlightp, trace.Entity, 0, trace.PhysicsBone ) trace.Entity:DeleteOnRemove( dynlightp ) end numpad.OnDown( ply, key, "dynlighttoggle", dynlight ) undo.Create( "DynamicLight" ) undo.AddEntity( dynlight ) undo.AddEntity( dynlightp ) undo.SetPlayer( ply ) undo.Finish() cleanup.Add( ply, "dynlights", dynlight ) cleanup.Add( ply, "dynlights", dynlightp ) ply:AddCount( "dynlights", dynlight ) ply:AddCleanup( "dynlight", dynlight ) ply:AddCleanup( "dynlight", dynlightp ) return true end function makedynlight_notoggle( ply, trace, Ang, r, g, b, a, fx, distance, brightness, key ) local dynlightp = ents.Create( "prop_physics" ) dynlightp:SetPos( trace.HitPos ) dynlightp:SetModel( "models/items/combine_rifle_ammo01.mdl" ) dynlightp:SetKeyValue( "disableshadows", "1" ) dynlightp:Spawn() local dynlight = ents.Create( "light_dynamic" ) dynlight:SetPos( trace.HitPos ) local dynlightpos = dynlight:GetPos()+Vector( 0, 0, 7 ) dynlight:SetPos( dynlightpos ) dynlight:SetKeyValue( "_light", r .. " " .. g .. " " .. b .. " " .. a ) dynlight:SetKeyValue( "style", fx ) dynlight:SetKeyValue( "distance", distance ) dynlight:SetKeyValue( "brightness", brightness ) dynlight:SetParent( dynlightp ) dynlight:Spawn() dynlightp:SetAngles( Ang ) if ( trace.Entity:IsValid() ) then const = constraint.Weld(dynlightp, trace.Entity,0, trace.PhysicsBone, 0, systemmanager ) nocollide = constraint.NoCollide( dynlightp, trace.Entity, 0, trace.PhysicsBone ) trace.Entity:DeleteOnRemove( dynlightp ) end numpad.OnDown( ply, key, "dynlighttoggle", dynlight ) numpad.OnUp( ply, key, "dynlighttoggle", dynlight ) undo.Create( "DynamicLight" ) undo.AddEntity( dynlight ) undo.AddEntity( dynlightp ) undo.SetPlayer( ply ) undo.Finish() cleanup.Add( ply, "dynlights", dynlight ) cleanup.Add( ply, "dynlights", dynlightp ) ply:AddCount( "dynlights", dynlight ) ply:AddCleanup( "dynlight", dynlight ) ply:AddCleanup( "dynlight", dynlightp ) return true end function makedynlight_nostarton( ply, trace, Ang, r, g, b, a, fx, distance, brightness, key ) local dynlightp = ents.Create( "prop_physics" ) dynlightp:SetPos( trace.HitPos ) dynlightp:SetModel( "models/items/combine_rifle_ammo01.mdl" ) dynlightp:SetKeyValue( "disableshadows", "1" ) dynlightp:Spawn() local dynlight = ents.Create( "light_dynamic" ) dynlight:SetPos( trace.HitPos ) local dynlightpos = dynlight:GetPos()+Vector( 0, 0, 7 ) dynlight:SetPos( dynlightpos ) dynlight:SetKeyValue( "_light", r .. " " .. g .. " " .. b .. " " .. a ) dynlight:SetKeyValue( "style", fx ) dynlight:SetKeyValue( "distance", distance ) dynlight:SetKeyValue( "brightness", brightness ) dynlight:SetParent( dynlightp ) dynlight:Spawn() dynlight:Fire("toggle","","0") dynlightp:SetAngles( Ang ) if ( trace.Entity:IsValid() ) then const = constraint.Weld(dynlightp, trace.Entity,0, trace.PhysicsBone, 0, systemmanager ) nocollide = constraint.NoCollide( dynlightp, trace.Entity, 0, trace.PhysicsBone ) trace.Entity:DeleteOnRemove( dynlightp ) end numpad.OnDown( ply, key, "dynlighttoggle", dynlight ) undo.Create( "DynamicLight" ) undo.AddEntity( dynlight ) undo.AddEntity( dynlightp ) undo.SetPlayer( ply ) undo.Finish() cleanup.Add( ply, "dynlights", dynlight ) cleanup.Add( ply, "dynlights", dynlightp ) ply:AddCount( "dynlights", dynlight ) ply:AddCleanup( "dynlight", dynlight ) ply:AddCleanup( "dynlight", dynlightp ) return true end function makedynlight_notoggle_nostarton( ply, trace, Ang, r, g, b, a, fx, distance, brightness, key ) local dynlightp = ents.Create( "prop_physics" ) dynlightp:SetPos( trace.HitPos ) dynlightp:SetModel( "models/items/combine_rifle_ammo01.mdl" ) dynlightp:SetKeyValue( "disableshadows", "1" ) dynlightp:Spawn() local dynlight = ents.Create( "light_dynamic" ) dynlight:SetPos( trace.HitPos ) local dynlightpos = dynlight:GetPos()+Vector( 0, 0, 7 ) dynlight:SetPos( dynlightpos ) dynlight:SetKeyValue( "_light", r .. " " .. g .. " " .. b .. " " .. a ) dynlight:SetKeyValue( "style", fx ) dynlight:SetKeyValue( "distance", distance ) dynlight:SetKeyValue( "brightness", brightness ) dynlight:SetParent( dynlightp ) dynlight:Spawn() dynlight:Fire("toggle","","0") dynlightp:SetAngles( Ang ) if ( trace.Entity:IsValid() ) then const = constraint.Weld(dynlightp, trace.Entity,0, trace.PhysicsBone, 0, systemmanager ) nocollide = constraint.NoCollide( dynlightp, trace.Entity, 0, trace.PhysicsBone ) trace.Entity:DeleteOnRemove( dynlightp ) end numpad.OnDown( ply, key, "dynlighttoggle", dynlight ) numpad.OnUp( ply, key, "dynlighttoggle", dynlight ) undo.Create( "DynamicLight" ) undo.AddEntity( dynlight ) undo.AddEntity( dynlightp ) undo.SetPlayer( ply ) undo.Finish() cleanup.Add( ply, "dynlights", dynlight ) cleanup.Add( ply, "dynlights", dynlightp ) ply:AddCount( "dynlights", dynlight ) ply:AddCleanup( "dynlight", dynlight ) ply:AddCleanup( "dynlight", dynlightp ) return true endend if ( CLIENT ) then language.Add( "Tool_dynlight_name", "Dynamic Light" ) language.Add( "Tool_dynlight_desc", "Creates lights that dynamically illuminate an area around them" ) language.Add( "Tool_dynlight_0", "Left click somewhere to spawn a dynamic light" ) language.Add( "Tool_dynlight_col", "The colour and brightness setting for the dynamic light" ) language.Add( "Tool_dynlight_distance", "The maximum distance around the dynamic light that is allowed to be illuminated" ) language.Add( "Tool_dynlight_brightness", "How bright the light is" ) language.Add( "Tool_dynlight_toggle", "Whether if holding down a number pad key keeps the light on and off or if pressing a number pad key once will turn it on and off" ) language.Add( "Tool_dynlight_starton", "Whether if the light will be turned on or not when it is spawned" ) language.Add( "Undone_DynamicLight", "Undone Dynamic Light" ) language.Add( "Cleanup_dynlight", "Dynamic Lights" ) language.Add( "Cleaned_dynlight", "Cleaned up all Dynamic Lights" ) language.Add( "SBoxLimit_dynlights", "You've hit the Dynamic Light limit!" ) endfunction TOOL:LeftClick( trace ) if ( !self:GetSWEP():CheckLimit( "dynlights" ) ) then return false end if trace.Entity && (trace.Entity:IsPlayer() ) then return false end local ply = self:GetOwner() local r = self:GetClientInfo( "r" ) local g = self:GetClientInfo( "g" ) local b = self:GetClientInfo( "b" ) local a = self:GetClientInfo( "a" ) local fx = self:GetClientInfo( "fx" ) local distance = self:GetClientInfo( "distance" ) local brightness = self:GetClientInfo( "brightness" ) local key = self:GetClientInfo( "key" ) local toggle = self:GetClientInfo( "toggle" ) local starton = self:GetClientInfo( "starton" ) local aworldgeometry = self:GetClientInfo( "aworldgeometry" ) local amodelgeometry = self:GetClientInfo( "amodelgeometry" ) local Ang = trace.HitNormal:Angle() Ang.pitch = Ang.pitch + 90 if starton == "1" && toggle == "1" then makedynlight( ply, trace, Ang, r, g, b, a, fx, distance, brightness, key ) end if starton == "1" && toggle == "0" then makedynlight_notoggle( ply, trace, Ang, r, g, b, a, fx, distance, brightness, key ) end if starton == "0" && toggle == "1" then makedynlight_nostarton( ply, trace, Ang, r, g, b, a, fx, distance, brightness, key ) end if starton == "0" && toggle == "0" then makedynlight_notoggle_nostarton( ply, trace, Ang, r, g, b, a, fx, distance, brightness, key ) endendfunction TOOL:RightClick( trace ) local ply = self:GetOwner() local r = self:GetClientInfo( "r" ) local g = self:GetClientInfo( "g" ) local b = self:GetClientInfo( "b" ) local a = self:GetClientInfo( "a" ) local fx = self:GetClientInfo( "fx" ) local distance = self:GetClientInfo( "distance" ) local brightness = self:GetClientInfo( "brightness" ) makedynlightfix( r, g, b, a, fx, distance, brightness )endfunction TOOL.BuildCPanel( cp ) cp:AddControl( "Header", { Text = "#Tool_dynlight_name", Description = "#Tool_dynlight_desc" } ) local params = { Label = "#Presets", MenuButton = 1, Folder = "dynlight", Options = {}, CVars = {} } params.Options.default = { dynlight_r = 255, dynlight_g = 255, dynlight_b = 255, dynlight_a = 255, dynlight_fx = 0, dynlight_distance = 50, dynlight_brightness = 5, dynlight_toggle = 1, dynlight_starton = 1, } table.insert( params.CVars, "dynlight_r" ) table.insert( params.CVars, "dynlight_g" ) table.insert( params.CVars, "dynlight_b" ) table.insert( params.CVars, "dynlight_a" ) table.insert( params.CVars, "dynlight_fx" ) table.insert( params.CVars, "dynlight_distance" ) table.insert( params.CVars, "dynlight_brightness" ) table.insert( params.CVars, "dynlight_toggle" ) table.insert( params.CVars, "dynlight_starton" ) cp:AddControl( "ComboBox", params ) cp:AddControl( "Color", { Label = "#Tool_dynlight_col", Red = "dynlight_r", Green = "dynlight_g", Blue = "dynlight_b", Alpha = "dynlight_a", Multiplier = "255" } ) cp:AddControl( "Slider", { Label = "#Light Radius", Description = "#Tool_dynlight_distance", Type = "Float", Min = 0, Max = 1000, Command = "dynlight_distance" } ) cp:AddControl( "Slider", { Label = "#Brightness Multiplier", Description = "#Tool_dynlight_brightness", Type = "Integer", Min = 0, Max = 10, Command = "dynlight_brightness" } ) local params = {Label = "Render FX", MenuButton = "0", Options = {}} params.Options["Normal"] = {dynlight_fx = "0"} params.Options["Fluorescent Flicker"] = {dynlight_fx = "10"} params.Options["Slow, Strong Pulse"] = {dynlight_fx = "2"} params.Options["Slow Pulse"] = {dynlight_fx = "11"} params.Options["Gentle Pulse"] = {dynlight_fx = "5"} params.Options["Flicker A"] = {dynlight_fx = "1"} params.Options["Flicker B"] = {dynlight_fx = "6"} params.Options["Candle A"] = {dynlight_fx = "3"} params.Options["Candle B"] = {dynlight_fx = "7"} params.Options["Candle C"] = {dynlight_fx = "8"} params.Options["Fast Strobe"] = {dynlight_fx = "4"} params.Options["Slow Strobe"] = {dynlight_fx = "9"} cp:AddControl( "ComboBox", params ) cp:AddControl( "Numpad", { Label = "#Light On/Off", Command = "dynlight_key", ButtonSize = 22 } ) cp:AddControl( "Checkbox", { Label = "#Toggle", Description = "#Tool_dynlight_toggle", Command = "dynlight_toggle" } ) cp:AddControl( "Checkbox", { Label = "#Start On", Description = "#Tool_dynlight_starton", Command = "dynlight_starton" } )endfunction TOOL:UpdateGhostDynlight( ent, player ) if ( !ent ) then return end if ( !ent:IsValid() ) then return end local tr = utilx.GetPlayerTrace( player, player:GetCursorAimVector() ) local trace = util.TraceLine( tr ) if (!trace.Hit || trace.Entity:IsPlayer() ) then ent:SetNoDraw( true ) return end local Ang = trace.HitNormal:Angle() Ang.pitch = Ang.pitch + 90 ent:SetAngles( Ang ) local min = ent:OBBMins() ent:SetPos( trace.HitPos - trace.HitNormal * min.z ) ent:SetNoDraw( false )endfunction TOOL:Think() if ( !self.GhostEntity || !self.GhostEntity:IsValid() || self.GhostEntity:GetModel() !="models/items/combine_rifle_ammo01.mdl" ) then self:MakeGhostEntity( "models/items/combine_rifle_ammo01.mdl", Vector(0,0,0), Angle(0,0,0) ) end self:UpdateGhostDynlight( self.GhostEntity, self:GetOwner() ) end