# Connections & Total distance V1.00 01-09-2017 Initial release # ################################################################################################################################# CatchEvent OnLapperStart() OnLapperStart_Connections_Distance(); EndCatchEvent CatchEvent OnConnect( $userName ) # Player event OnConnect_Connections_Distance(); EndCatchEvent CatchEvent OnDisConnect( $userName, $reason ) OnDisConnect_Connections_Distance( $userName, $reason ); EndCatchEvent Sub OnLapperStart_Connections_Distance() ### Declare global variable(s) ### GlobalVar $players_connected; ### End ### ### Give global variable(s) a value to start with ### $players_connected=0; ### End ### EndSub Sub OnConnect_Connections_Distance() ### When player connects, raise the number of connected players by 1 and update the button displaying the total number of connected players ### IF ( GetCurrentPlayerVar( "IsHost" ) != "") THEN $players_connected=$players_connected+1; Players_connected( $KeyFlags ); ENDIF ### End ### ### Search in storedvalue.dbs for saved value(s) for this user ### SetCurrentPlayerVar( "total_distance_driven",GetUserStoredValue( "total_distance_driven" ) ); ### End ### ### Set default value(s) if no values are loaded ### IF ( GetCurrentPlayerVar( "total_distance_driven" ) == "") THEN SetCurrentPlayerVar( "total_distance_driven",0); ENDIF ### End ### ### Display button showing the total distance driven ### Total_distance_driven( $KeyFlags ); ### End ### EndSub Sub OnDisConnect_Connections_Distance( $userName, $reason ) ### When player disconnects, lower the number of connected players by 1 and update the button displaying the total number of connected players ### $players_connected=$players_connected-1; Players_connected( $KeyFlags ); ### End ### EndSub Sub Players_connected ( $KeyFlags ) ### Display button showing number of connected players ### openGlobalButton( "players_connected",50,1,100,5,1,-1,36,"^7Players connected: ". $players_connected ); ### End ### EndSub Sub Total_distance_driven ( $KeyFlags ) ### Display button showing total distance driven ### ### Start private delayed command and go to Sub 'Save_total_distance_driven' after 30 seconds ### openPrivButton( "total_distance_driven",50,7,100,5,1,-1,36,"^7Total distance (meters): ". GetCurrentPlayerVar( "total_distance_driven" ) ); IF ( GetCurrentPlayerVar( "IsHost" ) != "") THEN PrivDelayedCommand( "savedist_" . GetCurrentPlayerVar( "UserName" ),30, Save_total_distance_driven ); ENDIF ### End ### EndSub Sub Save_total_distance_driven( $userName ) ### Calculate total distance driven by gathering PlayerVar 'total_distance_driven' and adding total meters driven since last save ### ### Update PlayerVar 'total_distance_driven' ### ### Set PlayerVar 'TotDistMeter' back to zero ### ### Save total distance driven into the database as a User Stored Variable ### ### Update button showing the total distance driven ### $total_distance_driven = GetCurrentPlayerVar( "total_distance_driven" ) + GetCurrentPlayerVar( "TotDistMeter" ); SetCurrentPlayerVar( "total_distance_driven",$total_distance_driven ); SetCurrentPlayerVar( "TotDistMeter",0 ); SetUserStoredValue( "total_distance_driven", $total_distance_driven ); Total_distance_driven( $KeyFlags ); ### End ### EndSub