RLS Studios
ProjectsPatreonCommunityDocsAbout
Join Patreon
BeamNG Modding Docs

Guides

Reference

Server CommandsGE UtilitiesGame Engine MainNavigation GraphScreenshot CaptureServerServer ConnectionSpawnpoint ManagerSimulation TimeVehicle SpawningSuspension Frequency Tester
Gameplay AchievementGameplay CityDiscoverForce FieldGarage ModeMarker InteractionParking SystemGameplay Playmode MarkersGameplay PoliceGameplay RallyGameplay Rally LoopGameplay Raw POIsGameplay Skidpad TestSpeed Trap LeaderboardsSpeed Traps and CamerasGameplay StatisticsTaxi Ride SystemTraffic SystemVehicle PerformanceWalking
Rally Audio ManagerRally Camera Path PlayerRally ClientRally Cut CaptureRally EnumsRally Extension HelperRally GeometryRally ManagerRecce ManagerRecce AppRecce SettingsRally Settings ManagerSnap-to-RoadTraffic Exclusion ZonesRally UtilityRally Vehicle CaptureRally Vehicle Tracker
Rally Loop PenaltiesRally AttemptsRally Event LogRally Loop ManagerRoad Section Penalty KeeperRally Schedule UtilitiesSpeeding DetectorStaged Countdown TestStaged Countdown Utilities

UI

Resources

BeamNG Game Engine Lua Cheat SheetGE Developer RecipesMCP Server Setup

// RLS.STUDIOS=true

Premium Mods for BeamNG.drive. Career systems, custom vehicles, and immersive gameplay experiences.

Index

HomeProjectsPatreon

Socials

DiscordPatreon (RLS)Patreon (Vehicles)

© 2026 RLS Studios. All rights reserved.

Modding since 2024

API ReferenceGE Extensionsgameplayrallyloop

Speeding Detector

Class-based speed monitoring system for rally road sections. Samples vehicle speed into a ring buffer, computes a rolling average, and applies stochastic speeding penalties with configurable probabili

Class-based speed monitoring system for rally road sections. Samples vehicle speed into a ring buffer, computes a rolling average, and applies stochastic speeding penalties with configurable probability scaling. Supports strict mode for service park areas.


Constructor

local SpeedingDetector = require('gameplay/rally/loop/speedingDetector')
local detector = SpeedingDetector(manager)

Public API

MethodSignatureReturnsDescription
init(manager)nilInitializes ring buffer, timers, and thresholds
update(dtSim, limitKph, strictMode?)nilMain tick: samples speed, checks for penalties
getCurrentSpeedKph()number|nilReturns player vehicle speed in km/h
addSample(sample)nilWrites speed sample to ring buffer
getAverageSpeed()number|nilReturns average of buffered samples
stochasticPenalty(maxSpeedOver, maxProbability)triggered, probabilityRolls for penalty based on speed over limit

Internals

Configuration

ParameterNormal ModeStrict ModeDescription
maxSpeedOver30 kph3 kphSpeed over limit for max probability
maxProbability0.2 (20%)0.7 (70%)Max penalty probability
bufferSize55Ring buffer sample count
sampleRate1.0s1.0sSeconds between samples
penaltyRateLimit60.0s60.0sMinimum seconds between penalties

Stochastic Penalty Model

probability = min(speedOver / maxSpeedOver * maxProbability, maxProbability)
triggered = math.random() < probability

Linear scaling from 0% at the limit to maxProbability at maxSpeedOver km/h over. In normal mode: 15 km/h over → 10% chance. In strict mode: 1.5 km/h over → 35% chance.

Ring Buffer

Pre-allocated array with wrapping write index. No memory allocations during sampling:

self.data[self.writeIndex] = sample
self.writeIndex = (self.writeIndex % self.bufferSize) + 1

Penalty Data Structure

{
  averageSpeed = number,
  instantSpeed = number,
  speedLimit = number,
  speedOver = number,
  probability = number,
  strictMode = boolean
}

Debug ImGui Window

drawDebug() renders a full debug panel showing: current/average speed, penalty probability, rate limit timer, sample buffer contents, and strict mode indicator. Called optionally from update().


How It Works

  1. update() is called each frame by the loop manager (only during road sections)
  2. Every sampleRate seconds, reads vehicle speed and adds to ring buffer
  3. After adding a sample, if rate limit has elapsed, runs stochastic penalty check
  4. If penalty triggers, records penalty data and notifies manager via manager:recordSpeedingPenalty()
  5. Strict mode (service parks) uses much tighter thresholds (3 kph over, 70% max probability)

Usage Example

local SpeedingDetector = require('gameplay/rally/loop/speedingDetector')
local detector = SpeedingDetector(loopManager)

-- Each frame during road sections
local strictMode = isInServicePark
detector:update(dtSim, speedLimitKph, strictMode)

See Also

  • Rally Loop Penalties - Related reference
  • Rally Attempts - Related reference
  • Rally Event Log - Related reference
  • Gameplay Systems Guide - Guide

Rally Schedule Utilities

Pure utility functions for rally loop scheduling and time calculations. Provides minute-boundary rounding, slot size conversion, and time comparison helpers.

Staged Countdown Test

Class-based test mode implementation for the staged countdown system. Simulates rally epoch timing and scheduled event scheduling without requiring a full rally loop manager. Used for testing countdow

On this page

ConstructorPublic APIInternalsConfigurationStochastic Penalty ModelRing BufferPenalty Data StructureDebug ImGui WindowHow It WorksUsage ExampleSee Also