CW Drifting (Open So

27.00 EUR

๐Ÿ CW Drifting System

THIS IS THE OPEN SOURCE VERSION. ALL CODE IS AVAILABLE TO MODIFY.

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.

Installation

  1. Download
  2. Drop the folder in your resources
  3. Ensure the folder name is "cw_drifting".
  4. Make sure it's started.

๐Ÿ“‘ Table of Contents

๐Ÿ“‹ Features

  • Real-time Drift Detection: Accurately calculates vehicle drift angles based on velocity vs. forward direction
  • Dynamic Multiplier System: Build up multipliers (up to 10x) by maintaining continuous drifts
  • Flexible Scoring Modes: Choose between instant scoring or hold-and-multiply scoring
  • Multiple UI Options:
    • Integration with cw-racingapp
    • OxLib TextUI support for standalone usage
  • Exported Functions: Easy integration with other scripts
  • Configurable Parameters: Customize thresholds, speeds, timers, and scoring values
  • Optional Commands: Enable player commands for toggling and resetting

๐ŸŽฎ How It Works

Drift Detection

  • Minimum drift angle: 15ยฐ (configurable)
  • Minimum speed: 10 MPH (configurable)
  • Continuous angle calculation comparing vehicle velocity to forward direction

Scoring System

  1. Base Score: Earn points based on drift angle (steeper angles = more points)
  2. Multiplier Growth: Hold drifts for 2 seconds to increase multiplier
  3. Multiplier Max: Build up to 10x multiplier (configurable)
  4. Multiplier Reset: Multiplier resets after 3 seconds without drifting

Scoring Modes

  • Hold Until Reset (holdCurrentUntilReset = true): Accumulates drift score and applies multiplier when drift ends
  • Instant Scoring (holdCurrentUntilReset = false): Applies multiplier to each score tick immediately

๐Ÿ”ง Installation

  1. Download or clone this repository into your FiveM resources folder
  2. Add ensure cw_drifting to your server.cfg
  3. Configure settings in config.lua (see Configuration section)
  4. Restart your server or use refresh and ensure cw_drifting

โš™๏ธ Configuration

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
}

Configuration Options Explained

| 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 |

๐Ÿ’ป Commands

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 information

๐Ÿ“ฆ Exports

Client-Side Exports

getDriftScore()

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
  • Returns: Current state (boolean)
-- 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()

๐Ÿ”— Integration Examples

With Racing Scripts

-- 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)

Custom Leaderboards

RegisterNetEvent('drift:saveFinalScore')
AddEventHandler('drift:saveFinalScore', function()
    local score = exports['cw_drifting']:getDriftScore()
    TriggerServerEvent('drift:submitScore', score)
end)

๐ŸŽฏ UI Integration

CW Racing App

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,
}

OxLib TextUI

When oxUi = true, displays a right-side panel showing:

  • Total drift score (formatted with commas)
  • Latest drift score
  • Current multiplier
  • Progress to next multiplier
  • Current drift angle

This needs to be set up manually in the config!

๐Ÿ“Š Drift Calculation Details

The drift angle is calculated by:

  1. Getting the vehicle's velocity vector
  2. Getting the vehicle's forward direction vector
  3. Calculating the angle between these vectors using dot product
  4. Converting to degrees

A drift is registered when:

  • Vehicle speed > minimum speed (default 10 MPH)
  • Drift angle โ‰ฅ threshold (default 15ยฐ)
  • Angle < 120ยฐ (prevents reverse driving from counting)

๐Ÿ› ๏ธ Dependencies

Required

  • None if ran with RacingApp
  • OxLib if ran standalone

Optional

  • ox_lib - For TextUI and notifications (if enabled in config)
  • cw-racingapp - For racing app integration (if enabled in config)

โšก Performance

  • Main thread runs every 100ms when active
  • Minimal performance impact (~0.00-0.01ms)
  • Automatically cleans up when resource stops
  • Only active when toggled on

๐Ÿ“ License

This resource is provided as-is for use in FiveM servers.

๐Ÿค Credits

Created by Coffeelot

๐Ÿ’ก Tips for Best Results

  1. Tuning for Your Server: Adjust driftThreshold and minDriftSpeed based on your vehicle handling
  2. Scoring Balance: Lower scoreIncrement for longer races, higher for drift competitions
  3. Multiplier Tuning: Increase multiplierIncrementTime for more challenging multiplier builds
  4. UI Choice: Use cw-racingapp for racing integration, or oxUi for standalone drift mode

๐Ÿ› Troubleshooting

Drift not detecting:

  • Check minimum speed is being reached
  • Lower driftThreshold if too sensitive
  • Verify vehicle is moving forward (not reversing)

UI not showing:

  • Ensure oxUi or updateRacingApp is enabled
  • Check ox_lib is installed if using oxUi
  • Verify cw-racingapp is running if using racing app integration

Multiplier not increasing:

  • Hold drift continuously for the full multiplierIncrementTime (default 2 seconds)
  • Maintain angle above driftThreshold
  • Keep speed above minDriftSpeed

๐Ÿ“ž Support

For issues, suggestions, or contributions, check out the CW Discord


Enjoy drifting! ๐ŸŽ๏ธ๐Ÿ’จ