Skip to content

Commit

Permalink
Update 0.6.2 - Added the possibility to increase or decrese the emerg…
Browse files Browse the repository at this point in the history
…ency vehicles traction offroad.
  • Loading branch information
Muhaddil committed Oct 2, 2024
1 parent 9486386 commit 839a0fc
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 31 deletions.
70 changes: 40 additions & 30 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ if Config.EnableCarPhysics then
local veh = GetVehiclePedIsIn(playerPed, false)
local groundHash = GetGroundHash(veh)

-- DebugPrint(groundHash)
DebugPrint(groundHash)

local sandHashes = {
1635937914, -1885547121, -1595148316, 510490462,
Expand Down Expand Up @@ -763,69 +763,79 @@ if Config.EnableCarPhysics then
function applyGripAndSlideEffects(vehicle, terrain)
local driveType = isFourWheelDrive(vehicle)
local hasOffroadTyres = hasOffroadTires(vehicle)

local isEmergency = isEmergencyVehicle(vehicle)
local tractionBonus = isEmergency and Config.TractionBonus or 0

if vehicle ~= lastVehicle then
originalTractionCurveMin = nil
originalTractionLossMult = nil
originalLowSpeedTractionLossMult = nil
lastVehicle = vehicle
end

if originalTractionCurveMin == nil or originalTractionLossMult == nil or originalLowSpeedTractionLossMult == nil then
originalTractionCurveMin = GetVehicleHandlingFloat(vehicle, "CHandlingData", "fTractionCurveMin")
originalTractionLossMult = GetVehicleHandlingFloat(vehicle, "CHandlingData", "fTractionLossMult")
originalLowSpeedTractionLossMult = GetVehicleHandlingFloat(vehicle, "CHandlingData", "fLowSpeedTractionLossMult")
end

if terrain == "sand" then
if not driveType then
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fLowSpeedTractionLossMult", 1.5)
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fLowSpeedTractionLossMult", 1.5 - tractionBonus)
else
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fLowSpeedTractionLossMult", 1.0)
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fLowSpeedTractionLossMult", 1.0 - tractionBonus)
end

if not hasOffroadTyres then
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fTractionLossMult", 2.0)
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fTractionCurveMin", 0.8)
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fTractionLossMult", 2.0 - tractionBonus)
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fTractionCurveMin", 0.8 + tractionBonus)
else
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fTractionLossMult", 0.8)
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fTractionCurveMin", 1.2)
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fTractionLossMult", 0.8 - tractionBonus)
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fTractionCurveMin", 1.2 + tractionBonus)
end
elseif terrain == "mountain" then
if not driveType then
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fLowSpeedTractionLossMult", 1.5)
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fLowSpeedTractionLossMult", 1.5 - tractionBonus)
else
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fLowSpeedTractionLossMult", 1.0)
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fLowSpeedTractionLossMult", 1.0 - tractionBonus)
end

if not hasOffroadTyres then
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fTractionLossMult", 1.8)
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fTractionCurveMin", 0.7)
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fTractionLossMult", 1.8 - tractionBonus)
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fTractionCurveMin", 0.7 + tractionBonus)
else
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fTractionLossMult", 1.0)
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fTractionCurveMin", 1.1)
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fTractionLossMult", 1.0 - tractionBonus)
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fTractionCurveMin", 1.1 + tractionBonus)
end
else
if hasOffroadTyres then
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fTractionLossMult", 1.2)
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fTractionCurveMin", 0.8)
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fTractionLossMult", 1.2 - tractionBonus)
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fTractionCurveMin", 0.8 + tractionBonus)
else
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fTractionLossMult", originalTractionLossMult)
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fTractionCurveMin", originalTractionCurveMin)
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fLowSpeedTractionLossMult",
originalLowSpeedTractionLossMult)
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fTractionLossMult", originalTractionLossMult - tractionBonus)
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fTractionCurveMin", originalTractionCurveMin + tractionBonus)
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fLowSpeedTractionLossMult", originalLowSpeedTractionLossMult - tractionBonus)
end
end
end


function isEmergencyVehicle(vehicle)
local emergencyClasses = {
[18] = true
}

local vehicleClass = GetVehicleClass(vehicle)
return emergencyClasses[vehicleClass] ~= nil
end

function limitSpeed(vehicle, terrain)
local maxSpeedKmH = Config.MaxSpeed
local maxSpeedMs = maxSpeedKmH / 3.6
local currentSpeedMs = GetEntitySpeed(vehicle)

-- DebugPrint("Current Speed: " .. currentSpeedMs .. " m/s")
-- DebugPrint("Max Speed: " .. maxSpeedMs .. " m/s")
-- DebugPrint("Speed Limit Active: " .. tostring(speedLimitActive))
DebugPrint("Current Speed: " .. currentSpeedMs .. " m/s")
DebugPrint("Max Speed: " .. maxSpeedMs .. " m/s")
DebugPrint("Speed Limit Active: " .. tostring(speedLimitActive))

if terrain == "sand" or terrain == "mountain" then
if currentSpeedMs > maxSpeedMs then
Expand All @@ -836,7 +846,7 @@ if Config.EnableCarPhysics then
local newSpeedMs = currentSpeedMs - (speedDifference * reductionFactor)
SetVehicleForwardSpeed(vehicle, newSpeedMs)

-- DebugPrint("New Speed: " .. newSpeedMs .. " m/s")
DebugPrint("New Speed: " .. newSpeedMs .. " m/s")

if currentSpeedMs - newSpeedMs < 1 then
SetEntityMaxSpeed(vehicle, maxSpeedMs)
Expand Down Expand Up @@ -875,7 +885,7 @@ if Config.EnableCarPhysics then
if veh ~= 0 then
timeout = 500
local terrain = isOnSandOrMountain()
-- DebugPrint(terrain)
DebugPrint(terrain)
applyTerrainEffects(veh, terrain)

local vehicleClass = GetVehicleClass(veh)
Expand Down
1 change: 1 addition & 0 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Config.MaxSpeed = 25 -- In KM/hours
Config.CarPhysicsTimeout = 1500 -- 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

-- 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.1-beta'
version 'v0.6.2-beta'

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

0 comments on commit 839a0fc

Please sign in to comment.