Nice mod. I'll put that into our Lapper installs.
Couple of things:
1) Use GetStoredNum to return a numeric, not a string otherwise you need to do a string to num conversion for compare
- thats where your script error came from, trying to minus a string from a number - the following would have fixed it:
BUT...
2) Don't do the ToMph conversion before the pseed compare as this will round down the result to 2 decimal places and is inaccurate
3) Do not use commas in a storevalue key as the SQL parser will incorrectly interpret them
4) Move the notification from the top left as game messages obscure it
Try the code below, replacing all of the Speedtrap# commands with the templates below (makes it easier to maintain) and the Language defs:
Couple of things:
1) Use GetStoredNum to return a numeric, not a string otherwise you need to do a string to num conversion for compare
- thats where your script error came from, trying to minus a string from a number - the following would have fixed it:
<?php
$OldTopSpeed = GetUserStoredValue( $userName, "OldTopSpeed" );
$STdiff = ToNum($OldTopSpeed) - $TopSpeed;
?>
2) Don't do the ToMph conversion before the pseed compare as this will round down the result to 2 decimal places and is inaccurate
3) Do not use commas in a storevalue key as the SQL parser will incorrectly interpret them
4) Move the notification from the top left as game messages obscure it
Try the code below, replacing all of the Speedtrap# commands with the templates below (makes it easier to maintain) and the Language defs:
<?php
Sub DoSpeedTrap( $num )
$userName = GetCurrentPlayerVar( "UserName" );
$car = GetCurrentPlayerVar("Car");
$track = getLapperVar("ShortTrackName");
$TopSpeed = ToNum( GetCurrentPlayerVar( "InstantSpeed" ));
$OldTopSpeed = GetUserStoredNum ( $userName, "ST" . $num . "TopSpeed-" . $track . "-" . $car);
IF ( $OldTopSpeed < 0 ) # Have not had a valid Speedtrap time before
THEN
openPrivButton( "st_text",1,16,20,5,3,4,80, langEngine ( "%{main_st_none}%" ,ToMph($TopSpeed) ) );
SetUserStoredNum ( $userName, "ST" . $num . "TopSpeed-" . $track . "-" . $car, $TopSpeed);
ELSE
IF ( $TopSpeed > $OldTopSpeed)
THEN
openPrivButton( "st_text",1,16,30,5,3,4,80, langEngine ( "%{main_st_faster}%" , ToMph($TopSpeed ), ToMph($TopSpeed - $OldTopSpeed) ) );
SetUserStoredNum ( $userName, "ST" . $num . "TopSpeed-" . $track . "-" . $car, $TopSpeed);
ELSE
openPrivButton( "st_text",1,16,30,5,3,4,80, langEngine ( "%{main_st_slower}%" ,ToMph($TopSpeed), ToMph($OldTopSpeed - $TopSpeed) ) );
ENDIF
ENDIF
EndSub
Sub SpeedTrap1( $userName )
DoSpeedTrap( 1 );
EndSub
Sub SpeedTrap2( $userName )
DoSpeedTrap( 2 );
EndSub
Sub SpeedTrap3( $userName )
DoSpeedTrap( 3 );
EndSub
Sub SpeedTrap4( $userName )
DoSpeedTrap( 4 );
EndSub
Sub SpeedTrap5( $userName )
DoSpeedTrap( 5 );
EndSub
Sub SpeedTrap6( $userName )
DoSpeedTrap( 6 );
EndSub
Lang "EN"
main_st_faster = "^0Radar Trap: {0} mph (^2+{1}^0)";
main_st_slower = "^0Radar Trap: {0} mph (^1-{1}^0)";
main_st_none = "^0Radar Trap: {0} mph";
EndLang
?>