[ESX / STANDALONE] ToggleNeons [Free]

Hi,

here’s a simple script that allows vehicle neonlights to be toggled On or Off

-Checks if you have installed neons or not

-Doesn’t mess with vehicleprops

-I made it ESX compatible, should you not use Mythic_notify.

Also, I’m not sure if anyone has already published this, but if that’s the case, you can take this post down.

Preview

Download from github

Github

6 Likes

Just wondering if it is synced :slight_smile:

Its just flipping neons on/off which I hope should be synced

Pretty useful!

Yeah, literally says in title.
I don’t seem to have had issues on my server not syncing so i guess it should. :thinking:
I’ll get on to do some testing today

its not synced with players

Few things:

  • You don’t need need any of the ESX stuff.There is 0 esx code here aside from the notifications. If you’re going to include them, wrap the esx code in a Config and do a Config for notifications too.
  • None of this runs in a loop so theres no need for a thread. Use the register key mapping native.
  • You are only checking if 1 neon is enabled. IsVehicleNeonLightEnabled(vehicle, 1) you should check for all of them.
  • You can also use SetVehicleNeonLightEnabled to enable and disable specific neon indexes. (For commands like neonFront or neonBack.) This is usually how people have done it in the past.
  • You dont check if the ped is the driver so any passenger can adjust their neon.

Below accomplishes the keybind + chat command with pretty much less than 20 lines of code and no threads.

-- Keymappings
RegisterKeyMapping("toggleNeon", "Enable/Disable Neon", 'keyboard', Config.neonKey)

-- Commands
RegisterCommand("toggleNeon", function()
    local ped = PlayerPedId()
    local vehicle = GetVehiclePedIsIn(ped, false)
    local driver  = GetPedInVehicleSeat(vehicle, -1)
    local neonEnabled = IsVehicleNeonLightEnabled(vehicle, 0), IsVehicleNeonLightEnabled(vehicle, 1), IsVehicleNeonLightEnabled(vehicle, 2), IsVehicleNeonLightEnabled(vehicle, 3)

    if IsPedInVehicle(ped,vehicle, true) and driver == ped then
        if neonEnabled then 
            toggleNeon(false)
        else
            toggleNeon(true)
        end
    end
end)

function toggleNeon(bool)
    local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
    local activeNeon = {}
    for i = 0,3 do
        activeNeon[i] = SetVehicleNeonLightEnabled(vehicle, i, bool)
    end
end
1 Like

Oh damn, that’s actually cool way to make this. Also I had it check earlier for all neons, but i made this for my server and i don’t have the option to install / enable specific neons on vehicles, so checking one neon was enough for me.
Tbh I haven’t used RegisterKeyMapping before but definitely going to take a look.

Also when using SetVehicleNeonLightEnabled -native some funky stuff happens should you end up storing the vehicle in garage when lights are off. Basically when you use that native and store the vehicle, it saves neons as false in vehicleprops. Thus after taking it out of garage it has neons off and you won’t be able to enable them again, cause it’s checking if the lights are enabled.

And I’m aware it doesn’t need ESX stuff for anything else than the notification.

Thanks for the tips tho^^

I think my code above would probably work even with garage :thinking: but your garage system should store the state of neon or at the very least enable it when it comes out.

If your using an ESX framework, by default it saves your cars properties when you store or retrieve it, and if you use the Bennys script when you upgrade it.

@Slerbamonsteri is correct. Unless you write some logic clientside to store the fact the car had neons, then change the property to enabled before storage, the light will drop off each time. Turning the neons on/off are ok, but ultimately its a gimmick.

You can rig it to save the neon being turned off, but you’ll still end up with community members complaining they stored their car with Neons off, and it comes out with Neons on :slight_smile:

Nice release bro