A drifting scoring system for FiveM that tracks drift angles, calculates scores with multipliers, and provides real-time feedback through customizable UI options.
This script only handles the scoring, and not races/leaderboards etc. It's mainly meant to be used as an extension to CW Racingapp for it's Drift update, but will work standalone with Ox lib - check Config. Built to be able to be implemented in other scripts also. This readme explains exports and implementations examples.
cw-racingapp
holdCurrentUntilReset = true): Accumulates drift score and applies multiplier when drift endsholdCurrentUntilReset = false): Applies multiplier to each score tick immediatelyensure cw_drifting to your server.cfg
config.lua (see Configuration section)refresh and ensure cw_drifting
Edit config.lua to customize the drift system:
Config = {
-- Scoring Algorithm Settings
holdCurrentUntilReset = true, -- Apply multiplier at drift end vs per tick
multiplierMax = 10, -- Maximum multiplier value
multiplierTimer = 3000, -- ms without drift before multiplier resets
driftThreshold = 15, -- Minimum angle to count as drift
minDriftSpeed = 10.0, -- Minimum speed to detect drifting
multiplierIncrementTime = 2000, -- ms of continuous drifting to increase multiplier
scoreIncrement = 10, -- Base score per drift tick
-- Feature Toggles
updateRacingApp = true, -- Enable racing app integration
enableCommands = false, -- Enable /drift commands
oxUi = false, -- Enable oxlib TextUI
oxNotify = false, -- Enable oxlib notifications
}
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| holdCurrentUntilReset | boolean | true | When true, multiplier applies to entire drift session when it ends. When false, multiplier applies to each tick. |
| multiplierMax | number | 10 | Maximum multiplier achievable |
| multiplierTimer | number | 3000 | Milliseconds without drifting before multiplier resets |
| driftThreshold | number | 15 | Minimum drift angle in degrees to register as drifting |
| minDriftSpeed | number | 10.0 | Minimum speed in MPH to detect drifting |
| multiplierIncrementTime | number | 2000 | Milliseconds of continuous drifting needed to increase multiplier |
| scoreIncrement | number | 10 | Base points awarded per drift calculation tick |
| updateRacingApp | boolean | true | Send drift data to cw-racingapp |
| enableCommands | boolean | false | Enable player commands |
| oxUi | boolean | false | Show drift stats using ox_lib TextUI |
| oxNotify | boolean | false | Show notifications using ox_lib |
Enable commands by setting enableCommands = true in config.lua:
/drift or /drift toggle - Enable/disable the drift system/drift reset - Reset your drift score to 0/drifthelp - Display help informationgetDriftScore()Returns the total drift score.
local score = exports['cw_drifting']:getDriftScore()
print("Current drift score: " .. score)
toggleDriftSystem(startSystem)Toggle or set the drift system state.
startSystem (optional): true to enable, false to disable, nil to toggle-- Toggle
local isActive = exports['cw_drifting']:toggleDriftSystem()
-- Explicitly enable
exports['cw_drifting']:toggleDriftSystem(true)
-- Explicitly disable
exports['cw_drifting']:toggleDriftSystem(false)
resetDriftSystem()Resets all drift scores and multipliers.
exports['cw_drifting']:resetDriftSystem()
pauseDriftScoring()Temporarily pauses drift score accumulation (useful for race checkpoints, etc.).
exports['cw_drifting']:pauseDriftScoring()
forceScore()Forces the current drift score to be added to total (only relevant when holdCurrentUntilReset = true).
exports['cw_drifting']:forceScore()
setTotalDriftScore(score)Manually set the total drift score.
exports['cw_drifting']:setTotalDriftScore(5000)
driftSystemIsActive()Check if the drift system is currently active.
local isActive = exports['cw_drifting']:driftSystemIsActive()
-- Start drift tracking when race begins
exports['cw_drifting']:toggleDriftSystem(true)
exports['cw_drifting']:resetDriftSystem()
-- Get final score when race ends
local finalScore = exports['cw_drifting']:getDriftScore()
exports['cw_drifting']:toggleDriftSystem(false)
RegisterNetEvent('drift:saveFinalScore')
AddEventHandler('drift:saveFinalScore', function()
local score = exports['cw_drifting']:getDriftScore()
TriggerServerEvent('drift:submitScore', score)
end)
When updateRacingApp = true, the script sends drift data to cw-racingapp with the following structure:
{
score = totalDriftScore,
multiplier = currentMultiplier,
latestDriftScore = latestDriftScore,
isDrifting = isDrifting,
driftAngle = lastAngle,
scoringIsPaused = scoringIsPaused,
multiplierPercent = multiplierPercent,
}
When oxUi = true, displays a right-side panel showing:
This needs to be set up manually in the config!
The drift angle is calculated by:
A drift is registered when:
This resource is provided as-is for use in FiveM servers.
Created by Coffeelot
driftThreshold and minDriftSpeed based on your vehicle handlingscoreIncrement for longer races, higher for drift competitionsmultiplierIncrementTime for more challenging multiplier buildscw-racingapp for racing integration, or oxUi for standalone drift modeDrift not detecting:
driftThreshold if too sensitiveUI not showing:
oxUi or updateRacingApp is enabledMultiplier not increasing:
multiplierIncrementTime (default 2 seconds)driftThreshold
minDriftSpeed
For issues, suggestions, or contributions, check out the CW Discord
Enjoy drifting! ๐๏ธ๐จ