Explanation
--car spawn --['polvette'] = {
byPerfomance = {
--Performance Scoor manualy setup-- performance = 699,
class = {
--Car class and top speedLimit-- ['A+ '] = 195,
}
}
},
local QBCore = exports['qb-core']:GetCoreObject()
local function getFieldFromHandling(vehicle, field)
return GetVehicleHandlingFloat(vehicle, 'CHandlingData', field)
end
local function getVehicleFromVehList(hash)
for _, v in pairs(QBCore.Shared.Vehicles) do
if hash == v.hash then
return v.name, v.brand
end
end
end
function getVehicleInfo(vehicle)
local model = GetEntityModel(vehicle)
local vehicleModel, vehicleBrand = '',''
local fInitialDriveMaxFlatVel = getFieldFromHandling(vehicle, "fInitialDriveMaxFlatVel")
local fInitialDriveForce = getFieldFromHandling(vehicle, "fInitialDriveForce")
local fClutchChangeRateScaleUpShift = getFieldFromHandling(vehicle, "fClutchChangeRateScaleUpShift")
local nInitialDriveGears = getFieldFromHandling(vehicle, "nInitialDriveGears")
local fDriveBiasFront = getFieldFromHandling(vehicle, "fDriveBiasFront")
local fInitialDragCoeff = getFieldFromHandling(vehicle, "fInitialDragCoeff")
local fTractionCurveMax = getFieldFromHandling(vehicle, "fTractionCurveMax")
local fTractionCurveMin = getFieldFromHandling(vehicle, "fTractionCurveMin")
local fLowSpeedTractionLossMult = getFieldFromHandling(vehicle, "fLowSpeedTractionLossMult")
local fTractionBiasFront = getFieldFromHandling(vehicle, "fTractionBiasFront")
local fTractionLossMult = getFieldFromHandling(vehicle, "fTractionLossMult")
local fSuspensionReboundDamp = getFieldFromHandling(vehicle, "fSuspensionReboundDamp")
local fSuspensionCompDamp = getFieldFromHandling(vehicle, "fSuspensionCompDamp")
local fAntiRollBarForce = getFieldFromHandling(vehicle, "fAntiRollBarForce")
local fBrakeForce = getFieldFromHandling(vehicle, "fBrakeForce")
local fBrakeBiasFront = getFieldFromHandling(vehicle, "fBrakeBiasFront")
local fHandBrakeForce = getFieldFromHandling(vehicle, "fHandBrakeForce")
local drivetrain = 0.0
if fDriveBiasFront > 0.5 then
--fwd
drivetrain = 1.0-fDriveBiasFront
else
--rwd
drivetrain = fDriveBiasFront
end
local score = {
accel = 0.0,
speed = 0.0,
handling = 0.0,
braking = 0.0,
drivetrain = 0.0,
}
score.drivetrain = drivetrain
local force = fInitialDriveForce
if fInitialDriveForce > 0 and fInitialDriveForce < 1 then
force = (force + drivetrain*0.15) * 1.4
end
-- SPEED --
local speedScore = ((fInitialDriveMaxFlatVel / fInitialDragCoeff) * (fTractionCurveMax + fTractionCurveMin)) / 40
score.speed = speedScore
-- ACCELERATION --
local accelScore = (fInitialDriveMaxFlatVel * force + (fClutchChangeRateScaleUpShift*0.7)) / 10
score.accel = accelScore
-- HANDLING --
local lowSpeedTraction = 1.0
if fLowSpeedTractionLossMult >= 1.0 then
lowSpeedTraction = lowSpeedTraction + (fLowSpeedTractionLossMult-lowSpeedTraction)*0.15
else
lowSpeedTraction = lowSpeedTraction - (lowSpeedTraction - fLowSpeedTractionLossMult)*0.15
end
local handlingScore = (fTractionCurveMax + (fSuspensionReboundDamp+fSuspensionCompDamp+fAntiRollBarForce)/3) + (fTractionCurveMin/lowSpeedTraction-fTractionBiasFront*3) + drivetrain
score.handling = handlingScore
-- BRAKING --
local brakingScore = ((fBrakeBiasFront) + fBrakeForce + fHandBrakeForce) * 4
score.braking = brakingScore
if Config.Debug then
print('====='..vehicleModel..'=====')
print('accel', accelScore)
print('speed', speedScore)
print('handling', handlingScore)
print('braking', brakingScore)
print('drivetrain', drivetrain)
end
-- Balance --
local balance = Config.Balance
local peformanceScore = math.floor(((accelScore * balance.acceleration) + (speedScore*balance.speed) + (handlingScore*balance.handling) + (brakingScore*balance.braking)) * balance.ratingMultiplier )
if Config.Debug then
print('PerfRating: ', peformanceScore)
end
-- Get class --
local class = "D"
local vehicleClass = GetVehicleClass(vehicle)
if vehicleClass ~= 8 then
if peformanceScore > 900 then
class = "X "
elseif peformanceScore > 775 then
class = "S+ "
elseif peformanceScore > 700 then
class = "S "
elseif peformanceScore > 650 then
class = "A+ "
elseif peformanceScore > 600 then
class = "A"
elseif peformanceScore > 550 then
class = "B+ "
elseif peformanceScore > 500 then
class = "B "
elseif peformanceScore > 450 then
class = "C+ "
elseif peformanceScore > 400 then
class = "C "
elseif peformanceScore > 350 then
class = "D+ "
elseif peformanceScore > 300 then
class = "D "
end
else
if peformanceScore > 500 then
class = "M+ "
elseif peformanceScore > 300 or peformanceScore < 301 then
class = "M "
end
end
return score, class, peformanceScore, vehicleModel, vehicleBrand
end
RegisterNetEvent('cw-performance:client:checkClient', function()
local veh = GetVehiclePedIsIn(PlayerPedId())
local info, class, perfRating = getVehicleInfo(veh)
return info, class, perfRating
end)
RegisterNetEvent('cw-performance:client:CheckPerformance', function()
local veh = GetVehiclePedIsIn(PlayerPedId())
if veh == 0 then
QBCore.Functions.Notify("Not in a vehicle", 'error')
else
local info, class, perfRating = getVehicleInfo(veh)
QBCore.Functions.Notify("This car is "..class..perfRating, 'success')
end
end)
exports("checkPerformance", function(veh)
local info, class, perfRating = getVehicleInfo(veh)
return info, class, perfRating
end)
local lastVehicle = nil
Citizen.CreateThread(function()
while true do
Citizen.Wait(10)
local vehicle = GetVehiclePedIsIn(PlayerPedId(-1), false)
if DoesEntityExist(vehicle) and GetPedInVehicleSeat(vehicle, -1) == PlayerPedId() and lastVehicle ~= vehicle then
lastVehicle = vehicle
local info, class, perfRating = exports['cw-performance']:checkPerformance(vehicle)
local vehicleModel = GetEntityModel(vehicle)
if Config.VehiclesAllowMaxSpeed[vehicleModel] then
if perfRating == Config.VehiclesAllowMaxSpeed[vehicleModel].byPerfomance.performance then
SetVehicleMaxSpeed(vehicle, Config.VehiclesAllowMaxSpeed[vehicleModel].byPerfomance.class[class] / 2.23694)
else
SetVehicleMaxSpeed(vehicle, Config.MaxSpeed[class] / 2.23694)
end
else
SetVehicleMaxSpeed(vehicle, Config.MaxSpeed[class] / 2.23694)
end
end
Contact Details
dimitriuk
What should we add?
Config
Config = {}
Config.Debug = true Config.UseCommand = true -- Enables checkscore command
Config.Balance = { acceleration = 4, speed = 3, handling = 2, braking = 1, ratingMultiplier = 10 }
Config.MaxSpeed = { ['D '] = 80, ['D+ '] = 90, ['C '] = 100, ['C+ '] = 120, ['B '] = 140, ['B+ '] = 155, ['A '] = 165, ['A+ '] = 175, ['S '] = 185, ['S+ '] = 195, ['X '] = 220, ['M '] = 130, ['M+ '] = 160, }
Config.VehiclesAllowMaxSpeed = { ['polvette'] = { byPerfomance = { performance = 699, class = { ['A+ '] = 195, } } }, ['rdhgt3'] = { byPerfomance = { performance = 800, class = { ['A+ '] = 195, } } } }
ADD:
Config.VehiclesAllowMaxSpeed = { ['polvette'] = { byPerfomance = { performance = 699, class = { ['A+ '] = 195, } } }, ['rdhgt3'] = { byPerfomance = { performance = 800, class = { ['A+ '] = 195, } } } }
Explanation --car spawn --['polvette'] = { byPerfomance = { --Performance Scoor manualy setup-- performance = 699, class = { --Car class and top speedLimit-- ['A+ '] = 195, } } },
local QBCore = exports['qb-core']:GetCoreObject()
local function getFieldFromHandling(vehicle, field) return GetVehicleHandlingFloat(vehicle, 'CHandlingData', field) end
local function getVehicleFromVehList(hash) for _, v in pairs(QBCore.Shared.Vehicles) do if hash == v.hash then return v.name, v.brand end end end
function getVehicleInfo(vehicle) local model = GetEntityModel(vehicle) local vehicleModel, vehicleBrand = '',''
end
RegisterNetEvent('cw-performance:client:checkClient', function() local veh = GetVehiclePedIsIn(PlayerPedId())
end)
RegisterNetEvent('cw-performance:client:CheckPerformance', function() local veh = GetVehiclePedIsIn(PlayerPedId())
end)
exports("checkPerformance", function(veh) local info, class, perfRating = getVehicleInfo(veh)
end)
local lastVehicle = nil
Citizen.CreateThread(function() while true do Citizen.Wait(10) local vehicle = GetVehiclePedIsIn(PlayerPedId(-1), false) if DoesEntityExist(vehicle) and GetPedInVehicleSeat(vehicle, -1) == PlayerPedId() and lastVehicle ~= vehicle then lastVehicle = vehicle local info, class, perfRating = exports['cw-performance']:checkPerformance(vehicle) local vehicleModel = GetEntityModel(vehicle)
end end)
Relevant Parties
Vehicle Performance