When the race starts, do this:
<?php
CatchEvent OnRaceStart( $NumP ) # Lapper event
SetStoredValue ( "RacePB", "0;NULL");
EndCatchEvent
?>
Store the users PBs each lap similar to this (note that thgis is for one of my addons, so will require you to muck about with var names, initial settings etc):
<?php
CatchEvent OnLap( $userName ) # Player event
# Update the PB if the current lap is faster than the PB
$EventLapPB = GetUserStoredValue ("EventLapPB");
$CurrLapTime = GetCurrentPlayerVar ("LapTime");
IF ( ToNum($EventLapPB) < 1 || ToNum($CurrLapTime) < ToNum($EventLapPB) )
THEN
SetUserStoredValue ( "EventLapPB", $CurrLapTime);
ENDIF
EndCatchEvent
?>
As part of the OnResult function, do something like this:
<?php
CatchEvent OnResult( $userName,$flagConfirm ) # Player event
$EventLapPB = GetUserStoredValue ("EventLapPB");
$RacePB = GetStoredValue ( "RacePB");
$BestTime = split( $RacePB,";",0 );
IF ( ToNum($EventLapPB) < ToNum($BestTime) )
SetStoredValue ( "RacePB", $EventLapPB . ";" . $userName);
ENDIF
EndCatchEvent
?>
Now the stored var RacePB will contain the PB and username, seperated with a semi-colon. Now you can query that to display the fastest time when doing a race restart or other event.
NB: As mentioned, this code is hacky since I'm at work and don't have much time, but thats essentially the eway I'm doing it.