Skip to content

Commit

Permalink
Update 0.7.0 - Introduced a new braking system: if excessive braking …
Browse files Browse the repository at this point in the history
…occurs, the brakes will temporarily become non-functional.
  • Loading branch information
Muhaddil committed Oct 19, 2024
1 parent 5569548 commit 5742f3c
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 10 deletions.
86 changes: 77 additions & 9 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ local checkInterval2 = Config.CheckIntervalEngineDamage
local previousSpeed = 0
local speedLimitActive = false
local originalZ = nil
local brakeTemperature = 0
local maxBrakeTemperature = Config.MaxBrakeTemp
local isBrakeOverheated = false
local coolingRate = Config.CoolingRate
local checkInterval3 = 1500
local originalBrakeForce = nil
local originalHandbrakeForce = nil


function DebugPrint(...)
Expand Down Expand Up @@ -910,6 +917,53 @@ if Config.EnableCarPhysics then
return normalVehicleClasses[vehicleClass] ~= nil
end

local function manageBrakeTemperature(vehicle)
if vehicle ~= lastVehicle then
originalBrakeForce = GetVehicleHandlingFloat(vehicle, "CHandlingData", "fBrakeForce")
originalHandbrakeForce = GetVehicleHandlingFloat(vehicle, "CHandlingData", "fHandBrakeForce")
print(originalBrakeForce, originalHandbrakeForce)
lastVehicle = vehicle
brakeTemperature = 0
end

local speed = GetEntitySpeed(vehicle) * 3.6

if speed > 5 then
local brakePressure = GetVehicleWheelBrakePressure(vehicle, 0)

if brakePressure > 0.1 then
brakeTemperature = brakeTemperature + Config.BrakeTemperaturaGain
end
print(brakeTemperature)

if brakeTemperature >= maxBrakeTemperature then
isBrakeOverheated = true
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fBrakeForce", 0.0)
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fHandBrakeForce", 0.0)
SetVehicleBrakeLights(vehicle, false)
brakeTemperature = brakeTemperature - coolingRate * 5
else
if isBrakeOverheated then
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fBrakeForce", originalBrakeForce)
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fHandBrakeForce", originalHandbrakeForce)
brakeTemperature = brakeTemperature - coolingRate * 5
isBrakeOverheated = false
end

if brakeTemperature > 0 and brakeTemperature < maxBrakeTemperature then
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fBrakeForce", originalBrakeForce)
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fHandBrakeForce", originalHandbrakeForce)
isBrakeOverheated = false
brakeTemperature = brakeTemperature - coolingRate
end
end
else
if brakeTemperature > 0 then
brakeTemperature = math.max(0, brakeTemperature - coolingRate)
end
end
end

Citizen.CreateThread(function()
while true do
local timeout = Config.CarPhysicsTimeout
Expand All @@ -935,38 +989,52 @@ if Config.EnableCarPhysics then
end
end)


Citizen.CreateThread(function()
while true do
checkInterval3 = 5000

local playerPed = GetPlayerPed(-1)
local vehicle = GetVehiclePedIsIn(playerPed, false)

if vehicle and IsVehicleOnAllWheels(vehicle) then
manageBrakeTemperature(vehicle)
checkInterval3 = 500
end
Citizen.Wait(checkInterval3)
end
end)

Citizen.CreateThread(function()
while true do
local timeout = Config.CarPhysicsTimeout
local playerPed = PlayerPedId()
local veh = GetVehiclePedIsIn(playerPed, false)

if veh ~= 0 then
timeout = 500
local terrain = isOnSandOrMountain()
DebugPrint(terrain)
applyTerrainEffects(veh, terrain)

local vehicleClass = GetVehicleClass(veh)
local hasOffroadTyres = hasOffroadTires(veh)

if isNormalCar(vehicleClass) and not hasOffroadTyres then
limitSpeed(veh, terrain)
end

-- if terrain == "sand" or terrain == "mountain" then
-- local multiplier = getTerrainEffectMultiplier(vehicleClass, terrain, hasOffroadTyres)
-- SetVehicleEngineTorqueMultiplier(veh, multiplier)
-- else
-- SetVehicleEngineTorqueMultiplier(veh, 1.0)
-- end
end

Citizen.Wait(timeout)
end
end)

function getTerrainEffectMultiplier(vehicleClass, terrain, hasOffroadTyres)
local multiplier = 1.0

Expand All @@ -989,5 +1057,5 @@ if Config.EnableCarPhysics then
end

return multiplier
end
end
end
end
3 changes: 3 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ Config.CarPhysicsTimeout = 2500 -- In milliseconds
Config.CarSinking = false -- Works but it's as little bit buggy, not a great implementation
Config.reductionFactor = 0.1 -- How fast the vehicles brake on sand/grass
Config.TractionBonus = 0.2 -- Additional traction boost for emergency vehicles, improving grip on rough terrains like sand or grass
Config.BrakeTemperaturaGain = 35 -- How much heat is applied to the brakes every 1.5 seconds
Config.MaxBrakeTemp = 500 -- The max temperatura the brakes can handle before giving out
Config.CoolingRate = 1 -- How fast the brakes cool down

-- Types of breakdowns
Config.BreakdownTypes = {
Expand Down
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ lua54 'yes'

author 'Muhaddil'
description 'Mileage-based vehicle breakdown system for ESX&QBCore'
version 'v0.6.3-beta'
version 'v0.7.0-beta'

shared_script 'config.lua'
client_script 'client.lua'
Expand Down

0 comments on commit 5742f3c

Please sign in to comment.