Skip to content

Add the function to add a lightbar (CLIENT)#253

Closed
Vitroze wants to merge 3 commits intoStyledStrike:mainfrom
Vitroze:manual_lightbar
Closed

Add the function to add a lightbar (CLIENT)#253
Vitroze wants to merge 3 commits intoStyledStrike:mainfrom
Vitroze:manual_lightbar

Conversation

@Vitroze
Copy link
Contributor

@Vitroze Vitroze commented Jan 28, 2026

Hello,
With this feature, developers will be able to add a lightbar to their vehicle without it necessarily being included. I decided to put this feature and entity on the client side because it is not useful to the server. This entity is only used to modify client bodygroups like a real flashing light.

To create the lightbar, you must create it on the client side:

    function ENT:OnPostInitialize()
        self:CreateLightbar( "models/tdmcars/emergency/equipment/code3_mx7000.mdl", Vector( 0, 0, 55 ), Angle( 0, 0, 0 ) )
    end

To modify the target entity when changing the body group, you will need to add the value to the target table:

0 or nil is the vehicle entity, and 1 up to the number of lightbars you want the entity to create.

ID is managed automatically in the CreateLightbar function. The first function called will have ID 1, then the second will have ID 2, and so on.

Example:

    ENT.SirenLights = {
        -- Top-right (blue) lights
        { offset = Vector( -6, -21, 41 ), time = 0, color = Glide.DEFAULT_SIREN_COLOR_B },
        { offset = Vector( -6, -21, 41 ), time = 0.25, color = Glide.DEFAULT_SIREN_COLOR_B },
        { offset = Vector( -6, -11, 41 ), time = 0, color = Glide.DEFAULT_SIREN_COLOR_B },
        { offset = Vector( -6, -11, 41 ), time = 0.25, color = Glide.DEFAULT_SIREN_COLOR_B },

        -- Top-left (red) lights
        { offset = Vector( -6, 21, 41 ), time = 0.5, color = Glide.DEFAULT_SIREN_COLOR_A },
        { offset = Vector( -6, 21, 41 ), time = 0.75, color = Glide.DEFAULT_SIREN_COLOR_A },
        { offset = Vector( -6, 11, 41 ), time = 0.5, color = Glide.DEFAULT_SIREN_COLOR_A },
        { offset = Vector( -6, 11, 41 ), time = 0.75, color = Glide.DEFAULT_SIREN_COLOR_A },

        -- Top bodygroups
        { bodygroup = 30, time = 0, duration = 0.5, target = 1 }, -- 0|nil = Vehicle entity, 1 - ... = Lightbar models
        { bodygroup = 31, time = 0.5, duration = 0.5, target = 1 },
        { bodygroup = 32, time = 0, duration = 0.5, target = 1 },
        { bodygroup = 27, time = 0.5, duration = 0.5, target = 1 },
        { bodygroup = 28, time = 0, duration = 0.5, target = 1 },
        { bodygroup = 29, time = 0.5, duration = 0.5, target = 1 },

        -- Front bodygroups
        { bodygroup = 26, time = 0, duration = 0.5 },
        { bodygroup = 25, time = 0.5, duration = 0.5 },

        -- Front-right sprites
        { offset = Vector( 114, -10, 5 ), dir = Vector( 1, 0, 0 ), time = 0, color = Glide.DEFAULT_SIREN_COLOR_B, lightRadius = 0 },
        { offset = Vector( 114, -10, 5 ), dir = Vector( 1, 0, 0 ), time = 0.25, color = Glide.DEFAULT_SIREN_COLOR_B, lightRadius = 0 },

        -- Front-left sprites
        { offset = Vector( 114, 10, 5 ), dir = Vector( 1, 0, 0 ), time = 0.5, color = Glide.DEFAULT_SIREN_COLOR_A, lightRadius = 0 },
        { offset = Vector( 114, 10, 5 ), dir = Vector( 1, 0, 0 ), time = 0.75, color = Glide.DEFAULT_SIREN_COLOR_A, lightRadius = 0 }
    }

    function ENT:OnCreateEngineStream( stream )
        stream:LoadPreset( "police_cruiser" )
    end

    function ENT:OnPostInitialize()
        -- ID : 1
        self:CreateLightbar( "models/tdmcars/emergency/equipment/code3_mx7000.mdl", Vector( 0, 0, 55 ), Angle( 0, 0, 0 ) )
    end

@Vitroze Vitroze changed the title Add lightbar Creation of the function to add a lightbar (CLIENT) Jan 28, 2026
@Vitroze Vitroze mentioned this pull request Jan 28, 2026
@Vitroze
Copy link
Contributor Author

Vitroze commented Jan 28, 2026

If this PR is accepted, I will update it to make it compatible.

@Vitroze Vitroze changed the title Creation of the function to add a lightbar (CLIENT) Add the function to add a lightbar (CLIENT) Jan 28, 2026
@StyledStrike
Copy link
Owner

StyledStrike commented Jan 29, 2026

Things should only be created on the client-side when the local player is near the vehicle, and the vehicle is on the player's potential visible set (aka. not dormant). Because of that, I cannot add this pull request as it is due to a few issues:

  • Vehicles can become invalid when they become dormant, or if the client needs to perform a full update (after losing connection for a few seconds for example). These conditions can call ENT:OnRemove even while the vehicle itself has not been truly removed yet. And since the lightbars are only created once, they might be removed on one of those conditions, and not exist when the vehicle returns into the player's view.
  • On base_glide_car, you're calling BaseClass.OnRemove( self ) without passing the fullUpdate parameter, causing the rfMisc RangedFeature (and so sounds, lights, animations, etc) to always be removed when the player performs a full update.

To manage these client-side, "is-the-vehicle-is-actually-active" conditions, the RangedFeature system was created for Glide. Vehicles use it to figure out when they are "active" (which means not dormant and within the range of the vehicle's ENT.MaxFeaturesDistance), then call functions like ENT:OnActivateMisc and ENT:OnDeactivateMisc - which is where the lightbars should've been created/removed.

With all of that said...

There's a elephant in the room: I want to add a more generic prop attachment system, with proper integrations to all light states (turn signals, brake, sirens, etc), so that's really why I'm closing this pull request for now.

@Vitroze
Copy link
Contributor Author

Vitroze commented Jan 29, 2026

I can put it on the server side, which will resolve the main issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants