├── .gitignore ├── real-brake-lights ├── fxmanifest.lua ├── config.lua ├── server.lua └── client.lua └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/settings.json 2 | real-brake-lights.zip 3 | -------------------------------------------------------------------------------- /real-brake-lights/fxmanifest.lua: -------------------------------------------------------------------------------- 1 | fx_version 'cerulean' 2 | game 'gta5' 3 | 4 | name "real-brake-lights" 5 | description "A simple resource that enables brake lights when the vehicle is stopped" 6 | author "Floh" 7 | version "1.1.0" 8 | 9 | client_scripts { 10 | 'config.lua', 11 | 'client.lua' 12 | } 13 | 14 | server_scripts { 15 | 'server.lua' 16 | } 17 | -------------------------------------------------------------------------------- /real-brake-lights/config.lua: -------------------------------------------------------------------------------- 1 | Config = { 2 | -- the park effect will turn off the brake lights after a random amount of time in seconds between parkTimerMin and parkTimerMax 3 | -- this is to simulate the vehicle being put in park after some time of being stopped 4 | enableParkEffect = true, 5 | parkTimerMin = 15, -- must be less than parkTimerMax (default 15) 6 | parkTimerMax = 60, -- must be greater than parkTimerMin (default 60) 7 | 8 | -- this is the speed at which the brake lights will turn off in MPH 9 | -- good values are beteween 3 - 20 10 | -- lower values will make the brake lights more responsive 11 | -- higher values can make a more realistic effect and reduce gap between braking and stopping 12 | brakeLightThreshold = 8, -- default 8 13 | } -------------------------------------------------------------------------------- /real-brake-lights/server.lua: -------------------------------------------------------------------------------- 1 | -- client tells server if their vehicle should have brake lights 2 | RegisterNetEvent("rbl:setBrakeLights") 3 | AddEventHandler("rbl:setBrakeLights", function(netId, state) 4 | -- print("[RBL] setBrakeLights") 5 | local vehicle = NetworkGetEntityFromNetworkId(netId) 6 | Entity(vehicle).state.rbl_brakelights = state 7 | end) 8 | 9 | RegisterNetEvent("rbl:setBlackout") 10 | AddEventHandler('rbl:setBlackout', function(netid, state) 11 | print("[RBL] Setting blackout " .. tostring(state)) 12 | local vehicle = NetworkGetEntityFromNetworkId(netid) 13 | Entity(vehicle).state.rbl_blackout = state 14 | end) 15 | 16 | RegisterNetEvent("rbl:setParked") 17 | AddEventHandler("rbl:setParked", function(netId, state) 18 | -- print("[RBL] setParked") 19 | local vehicle = NetworkGetEntityFromNetworkId(netId) 20 | Entity(vehicle).state.rbl_parked = state 21 | end) 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![real-brkes](https://user-images.githubusercontent.com/48927090/223524368-d73eca74-cc52-460d-8d56-bae1928046ff.jpg) 2 | 3 | 4 | A simple script that enables brake lights while stopped on player vehicles. 5 | I made this pair with [Ultimate Lighting Controller](https://forum.cfx.re/t/free-ultimate-lighting-controller/4985223)! It works great on it's own too! 6 | 7 | [Join Discord](https://discord.gg/zH3k624aSv) 8 | 9 | 10 | ## FEATURES 11 | - Syncs across vehicles 12 | - Great performance (0.01 - 0.02 both client and server) 13 | - [v1.1.0] ``/blackout`` command to disable brake lights until you move again 14 | - [v1.2.0] Compatible with [ULC](https://github.com/Flohhhhh/ultimate-lighting-controller)! 15 | - [v1.2.0] Turns off brake lights realistically when player exits vehicle or is stationary for a long time to simulate putting the vehicle in park. 16 | 17 | [Video Preview](https://medal.tv/games/gta-v/clips/YtzVDdvY7j4IN/d13371dtHMed?invite=cr-MSxaMXYsMTU4OTMwMTkwLA) 18 | 19 | ## INSTALLATION 20 | - Download ``real-brake-lights.zip`` from [the latest release](https://github.com/Flohhhhh/real-brake-lights/releases/latest/) 21 | - Drag ``real-brake-lights`` to your resources folder 22 | - Add ``ensure real-brake-lights`` to your server.cfg 23 | 24 | ## CREDITS 25 | 26 | [MadsLeander](https://github.com/MadsLeander) for most of the new logic implemented in v1.1.0 27 | -------------------------------------------------------------------------------- /real-brake-lights/client.lua: -------------------------------------------------------------------------------- 1 | local threshold = Config.brakeLightThreshold 2 | local vehicles = {} 3 | local isLoopActive = false 4 | 5 | local function IsTableEmpty(table) 6 | for _ in pairs(table) do return false end 7 | return true 8 | end 9 | 10 | -- loop through list of vehicles and set brake lights 11 | local function brakeLightLoop() 12 | CreateThread(function() 13 | --print("Loop started") 14 | isLoopActive = true 15 | while not IsTableEmpty(vehicles) do 16 | for vehicle, _data in pairs(vehicles) do 17 | local entity = Entity(vehicle) 18 | -- if vehicle exists, driver seat is occupied and vehicle isn't set to blackout, set brake lights 19 | if DoesEntityExist(vehicle) then -- if vehicle exists 20 | --print(entity.state.rbl_blackout) 21 | if entity.state.rbl_blackout == 1 or entity.state.rbl_blackout == nil and not entity.state.rbl_parked then -- if not blackout or parked 22 | --print("Setting brake lights for vehicle") 23 | SetVehicleBrakeLights(vehicle, true) 24 | end 25 | else -- if vehicle doesn't exist, remove it from list 26 | vehicles[vehicle] = nil 27 | end 28 | end 29 | Wait(0) 30 | end 31 | isLoopActive = false 32 | end) 33 | end 34 | 35 | --------------------------- 36 | -- HANDLE OTHER VEHICLES -- 37 | --------------------------- 38 | 39 | -- whenever rbl_brakelights value changes on an entity, add or remove it from the list 40 | AddStateBagChangeHandler('rbl_brakelights', null, function(bagName, key, value) 41 | Wait(0) -- Nedded as GetEntityFromStateBagName sometimes returns 0 on first frame 42 | local vehicle = GetEntityFromStateBagName(bagName) 43 | -- print("state changed for vehicle") 44 | if vehicle == 0 then return end 45 | local brakeLights = value 46 | if brakeLights then 47 | vehicles[vehicle] = true 48 | -- start loop if not already running 49 | if not isLoopActive then 50 | brakeLightLoop() 51 | end 52 | else 53 | vehicles[vehicle] = nil 54 | end 55 | end) 56 | 57 | ----------------- 58 | -- PARK EFFECT -- 59 | ----------------- 60 | 61 | local function parkTimer() 62 | local time = math.random((Config.parkTimerMin * 1000), Config.parkTimerMax * 1000) 63 | local expiration = GetGameTimer() + time 64 | local vehicle = GetVehiclePedIsIn(PlayerPedId(), false) 65 | -- local entity = Entity(vehicle) 66 | 67 | CreateThread(function() 68 | while true do 69 | if (GetEntitySpeed(vehicle) * 2.236936) > 0 then return end 70 | if GetGameTimer() > expiration then 71 | -- print("Setting park state to true") 72 | TriggerServerEvent("rbl:setParked", VehToNet(vehicle), true) 73 | return 74 | end 75 | Wait(500) 76 | end 77 | end) 78 | end 79 | 80 | ----------------------- 81 | -- HANDLE MY VEHICLE -- 82 | ----------------------- 83 | 84 | -- when i enter a vehicle, start a loop to check if i'm driving and if so, check speed and set brake lights 85 | local function onEnteredVehicle(_vehicle) 86 | -- print("onEnteredVehicle") 87 | CreateThread(function() 88 | local ped = PlayerPedId() 89 | local vehicle = _vehicle 90 | local entity = Entity(vehicle) 91 | local brakeLights = false 92 | 93 | while true do 94 | 95 | -- if i'm not in the vehicle turn off its brake lights and return 96 | if GetVehiclePedIsIn(ped, false) ~= vehicle then 97 | TriggerServerEvent("rbl:setParked", VehToNet(vehicle), true) 98 | return 99 | end 100 | 101 | local speed = GetEntitySpeed(vehicle) * 2.236936 -- get speed in MPH 102 | if vehicle == 0 then goto continue end -- if vehicle doesn't exist return 103 | if speed <= threshold and not IsControlPressed(0, 32) then -- if stopped 104 | if not brakeLights then -- if brake lights are not already on, turn them on and start a timer for park state 105 | --print("Enabling for my vehicle") 106 | brakeLights = true 107 | TriggerServerEvent('rbl:setBrakeLights', VehToNet(vehicle), true) 108 | if Config.enableParkEffect and (Config.parkTimerMax >= Config.parkTimerMin) then 109 | parkTimer() 110 | end 111 | end 112 | else -- if moving 113 | if brakeLights then 114 | --print("Disabling for my vehicle") 115 | brakeLights = false 116 | TriggerServerEvent('rbl:setBrakeLights', VehToNet(vehicle), false) 117 | end 118 | if entity.state.rbl_blackout == 0 then 119 | TriggerServerEvent('rbl:setBlackout', VehToNet(vehicle), 1) 120 | end 121 | if entity.state.rbl_parked then 122 | TriggerServerEvent('rbl:setParked', VehToNet(vehicle), false) 123 | end 124 | end 125 | 126 | ::continue:: 127 | Wait(250) 128 | end 129 | end) 130 | end 131 | 132 | AddEventHandler('gameEventTriggered', function(event, args) 133 | if event == "CEventNetworkPlayerEnteredVehicle" then 134 | if args[1] ~= PlayerId() then return end -- if it was not me return 135 | if GetPedInVehicleSeat(args[2], -1) ~= PlayerPedId() then return end -- if i'm not driver return 136 | 137 | local vehicle = args[2] 138 | onEnteredVehicle(vehicle) 139 | end 140 | end) 141 | 142 | ---------------------- 143 | -- BLACKOUT COMMAND -- 144 | ---------------------- 145 | 146 | local function setBlackout(newState) 147 | print("setBlackout: " .. tostring(newState)) 148 | local vehicle = GetVehiclePedIsIn(PlayerPedId(), false) 149 | if newState == 0 then 150 | SetVehicleLights(vehicle, 1) 151 | elseif newState == 1 then 152 | SetVehicleLights(vehicle, 0) 153 | end 154 | end 155 | 156 | RegisterCommand("blackout", function() 157 | local vehicle = GetVehiclePedIsIn(PlayerPedId(), false) 158 | local entity = Entity(vehicle) 159 | local blackout = entity.state.rbl_blackout 160 | print("Blackout current: " .. tostring(blackout)) 161 | local newState 162 | if blackout == 0 then 163 | newState = 1 164 | elseif blackout == 1 or blackout == nil then 165 | newState = 0 166 | end 167 | -- print("Setting blackout to: " .. tostring(newState)) 168 | TriggerServerEvent("rbl:setBlackout", VehToNet(GetVehiclePedIsIn(PlayerPedId())), newState) 169 | -- trigger ULC event for compatibility 170 | TriggerServerEvent("ulc:setBlackout", VehToNet(GetVehiclePedIsIn(PlayerPedId())), newState) 171 | end) 172 | 173 | AddStateBagChangeHandler('rbl_blackout', null, function(bagName, key, value) 174 | Wait(0) -- Nedded as GetEntityFromStateBagName sometimes returns 0 on first frame 175 | local vehicle = GetEntityFromStateBagName(bagName) 176 | if vehicle == 0 then return end 177 | local blackout = value 178 | setBlackout(blackout) 179 | end) 180 | 181 | 182 | 183 | ------------ 184 | -- EXTRAS -- 185 | ------------ 186 | 187 | -- check my vehicle if i'm already in one when script starts 188 | local ped = PlayerPedId() 189 | local vehicle = GetVehiclePedIsIn(ped, false) 190 | if vehicle then 191 | TriggerServerEvent("rbl:setBrakeLights", VehToNet(vehicle), false) 192 | Wait(0) 193 | onEnteredVehicle(vehicle) 194 | end 195 | 196 | --------------------------------------------------------------------------------