local font = "electronic_highway_sign" local fontSize = vec2(48, 97) local textColor = rgbm(1, 1, 1, 1) local bestTimes = {} local deltaTimes = {} local isRace = false local displayedCarCount = 6 local displayDuration = 3.0 local displayTimers = {} local lastLapCount = {} local updateInterval = 5.0 local updateTimer = 0 -- for best lap:mm:ss.mmm local function formatBestTime(ms) if ms > 0 then local minutes = math.floor(ms / 60000) local seconds = math.floor((ms / 1000) % 60) local millis = math.floor(ms % 1000) return string.format("%d:%02d.%03d", minutes, seconds, millis) else -- return "0:00.000" return "--.---" end end -- for race : mm:ss.mmm local function formatDeltaTimeLong(ms) if (ms==nil) then return "--.---" end local minutes = math.floor(ms / 60000) local seconds = math.floor((ms / 1000) % 60) local millis = math.floor(ms % 1000) return string.format("%d:%02d.%03d", minutes, seconds, millis) end local function formatDeltaTimeShort(timestamp) if (timestamp==nil) then return "--.---" end return string.format("%02.3f", timestamp/1000.0) end local sim = ac.getSim() function script.update(dt) isRace = sim.raceSessionType == 3 and sim.isSessionStarted updateTimer = updateTimer - dt if isRace and updateTimer <= 0 then updateTimer = updateInterval deltaTimes = {} deltaTimes[1] = 0 local cumulativeGap = 0 for i = 1, displayedCarCount do local car = ac.getCar.leaderboard(i) local prevCar = ac.getCar.leaderboard(i - 1) if car and prevCar then if car.isInPit or car.isInPitlane or car.isRetired then -- deltaTimes[i] = "pit" deltaTimes[i] = "PIT" cumulativeGap = -1 else local gap = ac.getGapBetweenCars(car.index, prevCar.index) if math.abs(gap) < 60*10 and cumulativeGap >= 0 then cumulativeGap = cumulativeGap + gap -- deltaTimes[i] = formatDeltaTime(cumulativeGap * 1000) if math.abs(cumulativeGap) > 120 then deltaTimes[i] = ">2MINUTE" elseif math.abs(cumulativeGap) > 60 then deltaTimes[i] = formatDeltaTimeLong(cumulativeGap * 1000) else deltaTimes[i] = formatDeltaTimeShort(cumulativeGap * 1000) end else deltaTimes[i] = "-" cumulativeGap = -1 end end end end end if isRace then for i = 1, displayedCarCount do local car = ac.getCar.leaderboard(i) if car then local yOffset = (i - 1) * 80 display.text { pos = vec2(0, yOffset), letter = fontSize, text = deltaTimes[i], -- alignment = 1, font = font, spacing = -9, color = textColor } end end else -- not race for i = 1, displayedCarCount do local car = ac.getCar.leaderboard(i) if car then local lapTime = car.bestLapTimeMs if lapTime > 0 then bestTimes[car.index] = lapTime end display.text { pos = vec2(0, -78 + i * 80), letter = fontSize, text = formatBestTime(bestTimes[car.index] or 0), font = font, spacing = -9, color = textColor } end end end end