# Author: Yisc[NL] # # Needed Lapper version: 7.0.4.9 or above # # # # Delete Laptime and Driftscore records - V1.00 09-09-2017 - Initial release # # Delete Laptime and Driftscore records - V1.01 18-10-2017 - Added option to delete all records for selected user at once # # - Reworked the GUI # # - Added option to show all records for the current track (admins only) # # - Added option to add a filter to Car-field (RMB to open filter, LMB to close filter) # # Delete Laptime and Driftscore records - V1.02 19-10-2017 - Added option to sort data using the Username (LMB to filter A/Z , Z/A , RMB to stop sorting) # # - Swapped the mouse buttons to open the filter for Car-field (LMB to open filter, RMB to close) # # Delete Laptime and Driftscore records - V1.03 20-10-2017 - Reworked the way number of records is tracked and which Subs are used when # # - Added option to delete single record when filter + sorting is active # # - Prev / Next buttons are now closed after every deleted record, to make sure the right ones come back on GUI redraw # # - Fixed a bug where page stayed empty after the last record of current page was deleted # # - Fixed a bug where Car-filter button stayed on screen when switching back from All users to Single user # # - Fixed a bug in Sub 'del_rec_while_show_all_users' where array_pos was only read as 2 characters, changed that to 5 # # - "Car:" and "Username:" don't have a subroutine when 'Show records of' is set to 'Single user' # # Delete Laptime and Driftscore records - V1.04 20-10-2017 - Moved trackcode to titlebar and added trackname long # # - Moved all buttons up, since buttons for track were no longer needed # # - Added button to delete all cars when having set a filter on carname # # - Fixed a bug where buttons could stay on screen, when switching from single user to all users and repeat that switch # ################################################################################################################################################################################################# CatchEvent OnLapperStart() OnLapperStart_DelRecGui(); EndCatchEvent CatchEvent OnMSO( $userName, $text ) # Player event $idxOfFirtsSpace = indexOf( $text, " "); IF( $idxOfFirtsSpace == -1 ) THEN $command = $text; $argv = ""; ELSE $command = subStr( $text,0,$idxOfFirtsSpace ); $argv = trim( subStr( $text,$idxOfFirtsSpace ) ); ENDIF SWITCH( $command ) CASE "!delrec": del_rec_gui (0,0); BREAK; ENDSWITCH EndCatchEvent Sub OnLapperStart_DelRecGui() ### Declare array with carnames ### GlobalVar $car_names; $car_names[1,1] = "UF1"; $car_names[1,2] = "XFG"; $car_names[1,3] = "XRG"; $car_names[1,4] = "LX4"; $car_names[1,5] = "LX6"; $car_names[1,6] = "RB4"; $car_names[1,7] = "FXO"; $car_names[1,8] = "XRT"; $car_names[1,9] = "RAC"; $car_names[1,10] = "FZ5"; $car_names[1,11] = "UFR"; $car_names[1,12] = "XFR"; $car_names[1,13] = "FXR"; $car_names[1,14] = "XRR"; $car_names[1,15] = "FZR"; $car_names[1,16] = "MRT"; $car_names[1,17] = "FBM"; $car_names[1,18] = "FOX"; $car_names[1,19] = "FO8"; $car_names[1,20] = "BF1"; ### End ### ### Declare global variable(s) and give them a value ### GlobalVar $del_record_version; GlobalVar $trackname; GlobalVar $delete_array; GlobalVar $all_users_counter; GlobalVar $username_array; GlobalVar $cname_array; GlobalVar $nickname_array; GlobalVar $datepb_array; GlobalVar $colpb_array; GlobalVar $total_usr_data_array; GlobalVar $start_value_page; GlobalVar $end_value_page; $del_record_version="V1.04"; $all_users_counter=0; ### End ### EndSub Sub del_rec_gui ( $KeyFlags,$id ) ### Check if CurrenPlayerVar 'del_record_mode' has a value ### ### If not, give it 'laptimes' as value ### ### Give 'show_records_of' value 'user' ### IF ( GetCurrentPlayerVar( "del_record_mode" ) == "" ) THEN SetCurrentPlayerVar( "del_record_mode", "laptimes" ); SetCurrentPlayerVar( "show_records_of", "user" ); ENDIF ### End ### ### Set variable $userName and read file admin.txt ### $userName = GetCurrentPlayerVar( "UserName" ); UserGroupFromFile( "admin", "./admin.txt" ); ### End ### ### Set initial values for left/right and top/bottom coordinates ### $left_right_del_rec = 1; $top_bottom_del_rec = 30; ### End ### ### Get the trackname of the currently loaded track ### $trackname_short = GetLapperVar ( "ShortTrackName" ); $trackname_long = GetLapperVar ( "LongTrackName" ); ### End ### ### Display screen ### openPrivButton( "del_rec_bg",$left_right_del_rec,$top_bottom_del_rec,142,157,5,-1,16,""); openPrivButton( "del_rec_title",$left_right_del_rec+1,$top_bottom_del_rec+1,140,5,5,-1,32,"^7Delete Laptime and Driftscore records (Track: " . $trackname_short . " - " . $trackname_long . ") - " . $del_record_version ); #openPrivButton( "del_rec_tracktitle",$left_right_del_rec+1,$top_bottom_del_rec+6,25,5,5,-1,96,"^7Track: " ); #openPrivButton( "del_rec_track",$left_right_del_rec+26,$top_bottom_del_rec+6,35,5,5,-1,32,"^7" . $trackname_short ); openPrivButton( "del_rec_mode_title",$left_right_del_rec+1,$top_bottom_del_rec+6,25,5,5,-1,96,"^7Show records for: " ); IF ( GetCurrentPlayerVar( "del_record_mode" ) == "laptimes" ) THEN openPrivButton( "del_rec_mode_laps",$left_right_del_rec+26,$top_bottom_del_rec+6,35,5,5,-1,32,"^2Laptimes" ); openPrivButton( "del_rec_mode_drift",$left_right_del_rec+61,$top_bottom_del_rec+6,35,5,5,-1,32,"^3Driftscores" , change_del_rec_mode ); ELSE openPrivButton( "del_rec_mode_laps",$left_right_del_rec+26,$top_bottom_del_rec+6,35,5,5,-1,32,"^3Laptimes" , change_del_rec_mode ); openPrivButton( "del_rec_mode_drift",$left_right_del_rec+61,$top_bottom_del_rec+6,35,5,5,-1,32,"^2Driftscores" ); ENDIF openPrivButton( "del_rec_of_title",$left_right_del_rec+1,$top_bottom_del_rec+11,25,5,5,-1,96,"^7Show records of: " ); IF ( GetCurrentPlayerVar( "show_records_of" ) == "user" ) THEN ### Check if CurrenPlayerVar 'selected_username' has a value and if not, give it the current UserName as value ### IF ( GetCurrentPlayerVar( "selected_username" ) == "" ) THEN SetCurrentPlayerVar( "selected_username", GetCurrentPlayerVar ( "UserName" ) ); ENDIF ### End ### openPrivButton( "del_rec_single_user_title",$left_right_del_rec+26,$top_bottom_del_rec+11,35,5,5,-1,32,"^2Single user" , change_show_records_of ); ### If user DOESN'T belongs to group 'admin', then only show button from single user without option to change username ### IF( UserInGroup( "admin", $userName ) != 1 ) THEN openPrivButton( "del_rec_user",$left_right_del_rec+26,$top_bottom_del_rec+16,35,5,5,-1,32,"^7" . GetCurrentPlayerVar( "selected_username" ) ); ELSE ### If user belongs to group 'admin', then show button to select all users and for single user with option to change username ### openPrivButton( "del_rec_all_users_title",$left_right_del_rec+61,$top_bottom_del_rec+11,35,5,5,-1,32,"^3All users" , change_show_records_of ); openPrivTextButton( "del_rec_user",$left_right_del_rec+26,$top_bottom_del_rec+16,35,5,5,32,"^3Set username to display records for","^3" . GetCurrentPlayerVar( "selected_username" ) , 30 , set_username ); ### End### ENDIF ### End ### ELSE openPrivButton( "del_rec_single_user_title",$left_right_del_rec+26,$top_bottom_del_rec+11,35,5,5,-1,32,"^3Single user" , change_show_records_of ); ### If user belongs to group 'admin', then show button to select all users ### IF( UserInGroup( "admin", $userName ) == 1 ) THEN openPrivButton( "del_rec_all_users_title",$left_right_del_rec+61,$top_bottom_del_rec+11,35,5,5,-1,32,"^2All users" , change_show_records_of ); ENDIF ### End ### ENDIF IF ( GetCurrentPlayerVar( "show_records_of" ) == "user" ) THEN openPrivButton( "del_rec_title_car",$left_right_del_rec+1,$top_bottom_del_rec+26,15,5,5,-1,32,"^7Car:" ); ELSE openPrivButton( "del_rec_title_car",$left_right_del_rec+1,$top_bottom_del_rec+26,15,5,5,-1,32,"^7Car:" , set_filter ); ENDIF openPrivButton( "del_rec_bg_username",$left_right_del_rec+16,$top_bottom_del_rec+26,35,5,5,-1,32,"" ); IF ( GetCurrentPlayerVar( "show_records_of" ) == "user" ) THEN openPrivButton( "del_rec_title_username",$left_right_del_rec+16,$top_bottom_del_rec+26,25,5,5,-1,0,"^7Username:" ); ELSE openPrivButton( "del_rec_title_username",$left_right_del_rec+16,$top_bottom_del_rec+26,25,5,5,-1,0,"^7Username:" , set_sorting ); ENDIF openPrivButton( "del_rec_title_nickname",$left_right_del_rec+51,$top_bottom_del_rec+26,35,5,5,-1,32,"^7Nickname:" ); openPrivButton( "del_rec_title_date",$left_right_del_rec+86,$top_bottom_del_rec+26,20,5,5,-1,32,"^7Date:" ); IF ( GetCurrentPlayerVar ( "filter" ) != "" ) THEN openPrivTextButton( "del_rec_car_filter",$left_right_del_rec+1,$top_bottom_del_rec+31,15,5,5,32,"^3Set carname to filter on","^3" . GetCurrentPlayerVar ( "filter" ) , 3 , set_filter_value ); ENDIF IF ( GetCurrentPlayerVar ( "sorting" ) != "" && GetCurrentPlayerVar ( "sorting" ) == "ASC" ) THEN openPrivButton( "sorting_asc",$left_right_del_rec+41,$top_bottom_del_rec+26,5,5,5,-1,16,"^6ASC" ); openPrivButton( "sorting_desc",$left_right_del_rec+46,$top_bottom_del_rec+26,5,5,5,-1,0,"^7DESC" ); ELSE IF ( GetCurrentPlayerVar ( "sorting" ) != "" && GetCurrentPlayerVar ( "sorting" ) == "DESC" ) THEN openPrivButton( "sorting_asc",$left_right_del_rec+41,$top_bottom_del_rec+26,5,5,5,-1,0,"^7ASC" ); openPrivButton( "sorting_desc",$left_right_del_rec+46,$top_bottom_del_rec+26,5,5,5,-1,16,"^6DESC" ); ENDIF ENDIF IF ( GetCurrentPlayerVar( "del_record_mode" ) == "laptimes" ) THEN openPrivButton( "del_rec_title_time",$left_right_del_rec+106,$top_bottom_del_rec+26,15,5,5,-1,32,"^7Laptime:" ); ELSE openPrivButton( "del_rec_title_score",$left_right_del_rec+106,$top_bottom_del_rec+26,15,5,5,-1,32,"^7Score:" ); ENDIF ### End ### ### Set new value for top/bottom coordinates ### $top_bottom_del_rec = 66; ### End ### IF ( $start_value_page == "" || $all_users_counter == 20 ) THEN $start_value_page=0; ENDIF IF ( $end_value_page == "" || $all_users_counter == 20 ) THEN $end_value_page=19; ENDIF IF ( GetCurrentPlayerVar( "show_records_of" ) == "all_users" && GetCurrentPlayerVar ( "sorting" ) != "" && GetCurrentPlayerVar ( "filter" ) == "" ) THEN $Sortedarray = Sort( $total_usr_data_array , GetCurrentPlayerVar ( "sorting" ) ); FOR( $i = $start_value_page; $i <= $end_value_page; $i = $i + 1 ) $data_fields = SplitToArray ( $Sortedarray[$i] , "*" ); IF ( $data_fields[3] != "" ) THEN openPrivButton( "del_rec_title_car_" . $i,$left_right_del_rec+1,$top_bottom_del_rec,15,5,5,-1,32,"^7" . $data_fields[3] ); openPrivButton( "del_rec_title_username_" . $i,$left_right_del_rec+16,$top_bottom_del_rec,35,5,5,-1,32,"^7" . $data_fields[0] ); openPrivButton( "del_rec_title_nickname_" . $i,$left_right_del_rec+51,$top_bottom_del_rec,35,5,5,-1,32,"^7" . $data_fields[2] ); openPrivButton( "del_rec_title_date_" . $i,$left_right_del_rec+86,$top_bottom_del_rec,20,5,5,-1,32,"^7" . $data_fields[4] ); openPrivButton( "del_rec_title_time_" . $i,$left_right_del_rec+106,$top_bottom_del_rec,15,5,5,-1,32,"^7" . $data_fields[5] ); openPrivButton( "del_rec_title_delete_" . $data_fields[1],$left_right_del_rec+121,$top_bottom_del_rec,20,5,5,-1,32,"^3Delete record" , del_rec_while_show_all_users ); $top_bottom_del_rec = $top_bottom_del_rec + 5; ENDIF ENDFOR ENDIF ### Show records for all users, based on the start and end value for the page ### IF ( GetCurrentPlayerVar( "show_records_of" ) == "all_users" ) THEN FOR( $i = $start_value_page; $i <= $end_value_page; $i = $i + 1 ) IF ( $cname_array[1,$i] != "" ) THEN IF ( GetCurrentPlayerVar ( "sorting" ) != "" && GetCurrentPlayerVar ( "filter" ) != "" ) THEN $Sortedarray = Sort( $username_array , GetCurrentPlayerVar ( "sorting" ) ); $new_array=$username_array; FOREACH ( $val2 IN $new_array ) IF ( $Sortedarray[$i] == $val2["value"] ) THEN $array_pos = ToNum ( Replace( $val2["key"],"new_array,1,","" ) ); openPrivButton( "del_rec_title_car_" . $i,$left_right_del_rec+1,$top_bottom_del_rec,15,5,5,-1,32,"^7" . $cname_array[1,$array_pos] ); openPrivButton( "del_rec_title_username_" . $i,$left_right_del_rec+16,$top_bottom_del_rec,35,5,5,-1,32,"^7" . $Sortedarray[$i] ); openPrivButton( "del_rec_title_nickname_" . $i,$left_right_del_rec+51,$top_bottom_del_rec,35,5,5,-1,32,"^7" . $nickname_array[1,$array_pos] ); openPrivButton( "del_rec_title_date_" . $i,$left_right_del_rec+86,$top_bottom_del_rec,20,5,5,-1,32,"^7" . $datepb_array[1,$array_pos] ); openPrivButton( "del_rec_title_time_" . $i,$left_right_del_rec+106,$top_bottom_del_rec,15,5,5,-1,32,"^7" . $colpb_array[1,$array_pos] ); openPrivButton( "del_rec_title_delete_" . $array_pos,$left_right_del_rec+121,$top_bottom_del_rec,20,5,5,-1,32,"^3Delete record" , del_rec_while_show_all_users ); $top_bottom_del_rec = $top_bottom_del_rec + 5; ENDIF ENDFOREACH ENDIF IF ( GetCurrentPlayerVar ( "sorting" ) == "" ) THEN openPrivButton( "del_rec_title_car_" . $i,$left_right_del_rec+1,$top_bottom_del_rec,15,5,5,-1,32,"^7" . $cname_array[1,$i] ); openPrivButton( "del_rec_title_username_" . $i,$left_right_del_rec+16,$top_bottom_del_rec,35,5,5,-1,32,"^7" . $username_array[1,$i] ); openPrivButton( "del_rec_title_nickname_" . $i,$left_right_del_rec+51,$top_bottom_del_rec,35,5,5,-1,32,"^7" . $nickname_array[1,$i] ); openPrivButton( "del_rec_title_date_" . $i,$left_right_del_rec+86,$top_bottom_del_rec,20,5,5,-1,32,"^7" . $datepb_array[1,$i] ); openPrivButton( "del_rec_title_time_" . $i,$left_right_del_rec+106,$top_bottom_del_rec,15,5,5,-1,32,"^7" . $colpb_array[1,$i] ); openPrivButton( "del_rec_title_delete_" . $i,$left_right_del_rec+121,$top_bottom_del_rec,20,5,5,-1,32,"^3Delete record" , del_rec_while_show_all_users ); $top_bottom_del_rec = $top_bottom_del_rec + 5; ENDIF ENDIF ENDFOR ENDIF #### End ### IF ( GetCurrentPlayerVar( "show_records_of" ) == "user" ) THEN ### Delete content of array $delete_array ### unset($delete_array); ### End ### ### Store value used for !top, before running script with every possible car ### $store_def_TopCar = getConfigVar( DefaultTopCar ); ### End ### ### Loop through every car in array $car_names and set DefaultTopCar to the currently listed car FOR( $i = 1; $i <= 20; $i = $i + 1 ) setConfigVar( DefaultTopCar, $car_names[1,$i] ); IF ( GetCurrentPlayerVar( "del_record_mode" ) == "laptimes" ) THEN ### Get the current Top list for selected car. Count the number of values in array $list, loop through the array to get the best time for each car for the specified username and display car/nickname/time on screen ### $list = GetListTop( getConfigVar( DefaultTopCar ), 0, 0 ); $count_array = arrayCount( $list ); FOR( $j = 0; $j < $count_array; $j = $j + 1) ### If selected username is found, grab the laptime for that user+car, convert it to a readable value and display everything on screen ### IF ( $list[$j,"UserName"] == GetCurrentPlayerVar( "selected_username" ) ) THEN IF ($list[$j,"PbLapTime"] > 3599000) THEN $colpb = ((3600000 - $list[$j,"PbLapTime"]) / 10) . "/" . GetConfigVar( "LapTimeUsedForPb" ) + langEngine( "%{built_lapsdone}%" ); ELSE $colpb = NumToMSH( $list[$j,"PbLapTime"] ); ENDIF openPrivButton( "del_rec_title_car_".$i,$left_right_del_rec+1,$top_bottom_del_rec,15,5,5,-1,32,"^7" . $list[$j,"CName"] ); openPrivButton( "del_rec_title_username_".$i,$left_right_del_rec+16,$top_bottom_del_rec,35,5,5,-1,32,"^7" . $list[$j,"UserName"] ); openPrivButton( "del_rec_title_nickname_".$i,$left_right_del_rec+51,$top_bottom_del_rec,35,5,5,-1,32,"^7" . $list[$j,"NickName"] ); openPrivButton( "del_rec_title_date_".$i,$left_right_del_rec+86,$top_bottom_del_rec,20,5,5,-1,32,"^7" . $list[$j,"DatePb"] ); openPrivButton( "del_rec_title_time_".$i,$left_right_del_rec+106,$top_bottom_del_rec,15,5,5,-1,32,"^7" . $colpb ); openPrivButton( "del_rec_title_delete_".$i,$left_right_del_rec+121,$top_bottom_del_rec,20,5,5,-1,32,"^3Delete record" , delete_record ); $delete_array[1,$i] = "" . $car_names[1,$i]; $top_bottom_del_rec = $top_bottom_del_rec + 5; ENDIF ### End ### ENDFOR ### End ### ENDIF IF ( GetCurrentPlayerVar( "del_record_mode" ) == "driftscores" ) THEN ### Get the current TopDriftList for selected car. Count the number of values in array $list, loop through the array to get the best time for each car for the specified username and display car/nickname/score on screen ### $list = getlisttopdrift( getConfigVar( DefaultTopCar ), 0, 0 ); $count_array = arrayCount( $list ); FOR( $j = 0; $j < $count_array; $j = $j + 1) IF ( $list[$j,"UserName"] == GetCurrentPlayerVar( "selected_username" ) ) THEN openPrivButton( "del_rec_title_car_".$i,$left_right_del_rec+1,$top_bottom_del_rec,15,5,5,-1,32,"^7" . $list[$j,"CName"] ); openPrivButton( "del_rec_title_username_".$i,$left_right_del_rec+16,$top_bottom_del_rec,35,5,5,-1,32,"^7" . $list[$j,"UserName"] ); openPrivButton( "del_rec_title_nickname_".$i,$left_right_del_rec+51,$top_bottom_del_rec,35,5,5,-1,32,"^7" . $list[$j,"NickName"] ); openPrivButton( "del_rec_title_date_".$i,$left_right_del_rec+86,$top_bottom_del_rec,20,5,5,-1,32,"^7" . $list[$j,"DatePb"] ); openPrivButton( "del_rec_title_time_".$i,$left_right_del_rec+106,$top_bottom_del_rec,15,5,5,-1,32,"^7" . $list[$j,"DriftPoints"] ); openPrivButton( "del_rec_title_delete_".$i,$left_right_del_rec+121,$top_bottom_del_rec,20,5,5,-1,32,"^3Delete record" , delete_record ); $delete_array[1,$i] = "" . $car_names[1,$i]; $top_bottom_del_rec = $top_bottom_del_rec + 5; ENDIF ENDFOR ENDIF ### End ### ENDFOR ### End ### ### Restore value used for DefaultTopCar ### setConfigVar( DefaultTopCar, $store_def_TopCar ); ### End ### ENDIF ### End ### ### Set new value for top/bottom coordinate. Display button to close the screen ### $top_bottom_del_rec = 171; IF ( GetCurrentPlayerVar( "show_records_of" ) == "user" ) THEN openPrivButton( "del_rec_del_all_for_user",$left_right_del_rec+1,$top_bottom_del_rec+5,140,5,5,-1,32,"^1Delete ^7all records (" . GetCurrentPlayerVar( "del_record_mode" ) . ") for ^3" . GetCurrentPlayerVar( "selected_username" ) . " ^7on track ^3" . $trackname_short , del_all_recs_user ); ENDIF IF ( GetCurrentPlayerVar( "show_records_of" ) == "all_users" && GetCurrentPlayerVar ( "filter" ) != "" ) THEN openPrivButton( "del_rec_del_all_car",$left_right_del_rec+1,$top_bottom_del_rec+5,140,5,5,-1,32,"^1Delete ^7all records for car ^3" . GetCurrentPlayerVar ( "filter" ) . " ^7on track ^3" . $trackname_short , del_all_recs_car ); ENDIF IF ( GetCurrentPlayerVar( "show_records_of" ) == "all_users" && ToNum ( $all_users_counter ) > 20 ) THEN ### Give $display_start_value the value of $start_value_page and raise it by 20 ### ### Give $display_end_value the value of $end_value_page and raise it by 20 ### $display_start_value = $start_value_page + 21; $display_end_value = $end_value_page + 21; ### End ### ### Give $display_prev_start_value the value of $start_value_page and lower it by 20 ### ### Give $display_prev_end_value the value of $end_value_page and lower it by 20 ### $display_prev_start_value = $start_value_page - 19; $display_prev_end_value = $end_value_page - 19; ### End ### IF ( $display_prev_start_value < 0 && $display_prev_end_value <= 0 ) THEN openPrivButton( "prev_page_all_users",$left_right_del_rec+1,$top_bottom_del_rec,70,5,5,-1,32,"" ); ELSE openPrivButton( "prev_page_all_users",$left_right_del_rec+1,$top_bottom_del_rec,70,5,5,-1,32,"^3Previous page (" . $display_prev_start_value . "-" . $display_prev_end_value . ")" , prev_page_recs_all_users ); ENDIF IF ( $display_start_value > $all_users_counter && $display_end_value > $all_users_counter ) THEN $display_start_value = $start_value_page; $display_end_value = $all_users_counter; openPrivButton( "next_page_all_users",$left_right_del_rec+71,$top_bottom_del_rec,70,5,5,-1,32,"" ); ELSE IF ( $display_end_value > $all_users_counter ) THEN $display_end_value = $all_users_counter; openPrivButton( "next_page_all_users",$left_right_del_rec+71,$top_bottom_del_rec,70,5,5,-1,32,"^3Next page (" . $display_start_value . "-" . $display_end_value . ")" , next_page_recs_all_users ); ELSE openPrivButton( "next_page_all_users",$left_right_del_rec+71,$top_bottom_del_rec,70,5,5,-1,32,"^3Next page (" . $display_start_value . "-" . $display_end_value . ")" , next_page_recs_all_users ); ENDIF ENDIF ENDIF openPrivButton( "del_rec_gui_close",$left_right_del_rec+1,$top_bottom_del_rec+10,140,5,5,-1,32,"^3Close", del_rec_gui_close ); ### End ### EndSub Sub change_del_rec_mode ( $KeyFlags,$id ) IF ( GetCurrentPlayerVar( "del_record_mode" ) == "laptimes") THEN SetCurrentPlayerVar( "del_record_mode", "driftscores" ); closePrivButton ("del_rec_title_time"); ELSE SetCurrentPlayerVar( "del_record_mode", "laptimes" ); closePrivButton ("del_rec_title_score"); ENDIF ### Execute sub routine 'del_rec_info_close' ### del_rec_info_close ( $KeyFlags,$id ); ### End ### IF ( GetCurrentPlayerVar ( "show_records_of" ) == "all_users" ) THEN get_records_from_db(); ENDIF ### Re-open the delete record GUI ### del_rec_gui ( $KeyFlags,$id ); ### End ### EndSub Sub change_show_records_of ( $KeyFlags,$id ) IF ( GetCurrentPlayerVar( "show_records_of" ) == "user" ) THEN SetCurrentPlayerVar( "show_records_of", "all_users" ); closePrivButton( "del_rec_user" ); closePrivButton( "del_rec_del_all_for_user" ); ELSE SetCurrentPlayerVar( "show_records_of", "user" ); SetCurrentPlayerVar ( "filter" , "" ); closePrivButton( "del_rec_car_filter" ); SetCurrentPlayerVar ( "sorting" , "" ); closePrivButton( "sorting_asc" ); closePrivButton( "sorting_desc" ); closePrivButton( "next_page_all_users" ); closePrivButton( "prev_page_all_users" ); ENDIF ### Execute sub routine 'del_rec_info_close' ### del_rec_info_close ( $KeyFlags,$id ); ### End ### IF ( GetCurrentPlayerVar ( "show_records_of" ) == "all_users" ) THEN get_records_from_db(); ENDIF ### Re-open the delete record GUI ### del_rec_gui ( $KeyFlags,$id ); ### End ### EndSub Sub set_username ($selected_username_value,$text) ### Read entered text and store it in a CurrentPlayerVar ### SetCurrentPlayerVar( "selected_username",ToLower( $text ) ); ### End ### ### Execute sub routine 'del_rec_info_close' ### del_rec_info_close ( $KeyFlags,$id ); ### End ### ### Re-open the delete record GUI ### del_rec_gui ( $KeyFlags,$id ); ### End ### Endsub Sub get_records_from_db() ### Set $all_users_counter to 0 ### $all_users_counter = 0; ### End ### ### Clear all arrays ### unset($cname_array); unset($username_array); unset($nickname_array); unset($datepb_array); unset($colpb_array); unset($total_usr_data_array); ### End ### ### Store value used for !top, before running script with every possible car ### $store_def_TopCar = getConfigVar( DefaultTopCar ); ### End ### FOR( $i = 1; $i <= 20; $i = $i + 1) setConfigVar( DefaultTopCar, $car_names[1,$i] ); IF ( GetCurrentPlayerVar( "del_record_mode" ) == "laptimes" ) THEN ### Get the current Top list for selected car. Count the number of values in array $list, loop through the array to get all the records if UserName ISN'T empty ### $list = GetListTop( getConfigVar( DefaultTopCar ), 0, 0 ); $count_array = arrayCount( $list ); FOR( $j = 0; $j < $count_array; $j = $j + 1) ### If username ISN'T empty, grab the laptime for that user+car and convert it to a readable value ### IF ( $list[$j,"UserName"] != "" ) THEN IF ($list[$j,"PbLapTime"] > 3599000) THEN $colpb = ((3600000 - $list[$j,"PbLapTime"]) / 10) . "/" . GetConfigVar( "LapTimeUsedForPb" ) + langEngine( "%{built_lapsdone}%" ); ELSE $colpb = NumToMSH( $list[$j,"PbLapTime"] ); ENDIF IF ( GetCurrentPlayerVar ( "filter" ) != "" ) THEN IF ( $list[$j,"CName"] == GetCurrentPlayerVar ( "filter" ) ) THEN $cname_array[1,$all_users_counter] = "" . $list[$j,"CName"]; $username_array[1,$all_users_counter] = "" . $list[$j,"UserName"]; $nickname_array[1,$all_users_counter] = "" .$list[$j,"NickName"]; $datepb_array[1,$all_users_counter] = "" . $list[$j,"DatePb"]; $colpb_array[1,$all_users_counter] = "" . $colpb; $all_users_counter = $all_users_counter + 1; ENDIF ENDIF IF ( GetCurrentPlayerVar ( "filter" ) == "" && GetCurrentPlayerVar ( "sorting" ) != "" ) THEN $cname_array[1,$all_users_counter] = "" . $list[$j,"CName"]; $username_array[1,$all_users_counter] = "" . $list[$j,"UserName"]; $total_usr_data_array[1,$all_users_counter] = "" . $list[$j,"UserName"] . "*" . $all_users_counter . "*" . $list[$j,"NickName"] . "*" . $list[$j,"CName"] . "*" . $list[$j,"DatePb"] . "*" . $colpb; $all_users_counter = $all_users_counter + 1; ENDIF IF ( GetCurrentPlayerVar ( "filter" ) == "" && GetCurrentPlayerVar ( "sorting" ) == "" ) THEN $cname_array[1,$all_users_counter] = "" . $list[$j,"CName"]; $username_array[1,$all_users_counter] = "" . $list[$j,"UserName"]; $nickname_array[1,$all_users_counter] = "" .$list[$j,"NickName"]; $datepb_array[1,$all_users_counter] = "" . $list[$j,"DatePb"]; $colpb_array[1,$all_users_counter] = "" . $colpb; $all_users_counter = $all_users_counter + 1; ENDIF ENDIF ### End ### ENDFOR ### End ### ENDIF IF ( GetCurrentPlayerVar( "del_record_mode" ) == "driftscores" ) THEN ### Get the current TopDriftList for selected car. Count the number of values in array $list, loop through the array to get all the records if UserName ISN'T empty ### $list = getlisttopdrift( getConfigVar( DefaultTopCar ), 0, 0 ); $count_array = arrayCount( $list ); FOR( $j = 0; $j < $count_array; $j = $j + 1) IF ( $list[$j,"UserName"] != "" ) THEN IF ( GetCurrentPlayerVar ( "filter" ) != "" ) THEN IF ( $list[$j,"CName"] == GetCurrentPlayerVar ( "filter" ) ) THEN $cname_array[1,$all_users_counter] = "" . $list[$j,"CName"]; $username_array[1,$all_users_counter] = "" . $list[$j,"UserName"]; $nickname_array[1,$all_users_counter] = "" .$list[$j,"NickName"]; $datepb_array[1,$all_users_counter] = "" . $list[$j,"DatePb"]; $colpb_array[1,$all_users_counter] = "" . $list[$j,"DriftPoints"]; $all_users_counter = $all_users_counter + 1; ENDIF ENDIF IF ( GetCurrentPlayerVar ( "filter" ) == "" && GetCurrentPlayerVar ( "sorting" ) != "" ) THEN $cname_array[1,$all_users_counter] = "" . $list[$j,"CName"]; $username_array[1,$all_users_counter] = "" . $list[$j,"UserName"]; $total_usr_data_array[1,$all_users_counter] = "" . $list[$j,"UserName"] . "*" . $all_users_counter . "*" . $list[$j,"NickName"] . "*" . $list[$j,"CName"] . "*" . $list[$j,"DatePb"] . "*" . $list[$j,"DriftPoints"]; $all_users_counter = $all_users_counter + 1; ENDIF IF ( GetCurrentPlayerVar ( "filter" ) == "" && GetCurrentPlayerVar ( "sorting" ) == "" ) THEN $cname_array[1,$all_users_counter] = "" . $list[$j,"CName"]; $username_array[1,$all_users_counter] = "" . $list[$j,"UserName"]; $nickname_array[1,$all_users_counter] = "" .$list[$j,"NickName"]; $datepb_array[1,$all_users_counter] = "" . $list[$j,"DatePb"]; $colpb_array[1,$all_users_counter] = "" . $list[$j,"DriftPoints"]; $all_users_counter = $all_users_counter + 1; ENDIF ENDIF ENDFOR ### End ### ENDIF ENDFOR ### Restore value used for DefaultTopCar ### setConfigVar( DefaultTopCar, $store_def_TopCar ); ### End ### EndSub Sub next_page_recs_all_users ( $KeyFlags,$id ) $start_value_page = $start_value_page + 20; $end_value_page = $end_value_page + 20; del_rec_info_close( $KeyFlags,$id ); ### Re-open the delete record GUI ### del_rec_gui ( $KeyFlags,$id ); ### End ### EndSub Sub prev_page_recs_all_users ( $KeyFlags,$id ) $start_value_page = $start_value_page - 20; $end_value_page = $end_value_page - 20; del_rec_info_close( $KeyFlags,$id ); ### Re-open the delete record GUI ### del_rec_gui ( $KeyFlags,$id ); ### End ### EndSub Sub del_rec_info_close ( $KeyFlags,$id ) ### If $all_users_counter is below 20, set it to 20 to be able to close the maximum of 20 records a single user can have on screen ### IF ( $all_users_counter < 20 ) THEN $all_users_counter=20; ENDIF ### End ### ### Loop through all the records and close corresponding buttons ### FOR ( $i = 0; $i <= $all_users_counter; $i = $i + 1 ) closePrivButton("del_rec_title_car_".$i); closePrivButton("del_rec_title_username_" . $i); closePrivButton("del_rec_title_nickname_" . $i); closePrivButton("del_rec_title_date_" . $i); closePrivButton("del_rec_title_time_" . $i); closePrivButton("del_rec_title_score_" . $i); closePrivButton("del_rec_title_delete_" . $i); ENDFOR ### EndSub Sub del_rec_gui_close( $KeyFlags,$id ) closePrivButton( "del_rec_bg" ); closePrivButton( "del_rec_title" ); closePrivButton( "del_rec_tracktitle" ); closePrivButton( "del_rec_track" ); closePrivButton( "del_rec_mode_title" ); closePrivButton( "del_rec_mode_laps" ); closePrivButton( "del_rec_mode_drift" ); closePrivButton( "del_rec_of_title" ); closePrivButton( "del_rec_single_user_title" ); closePrivButton( "del_rec_all_users_title" ); closePrivButton( "del_rec_title_car" ); IF ( $id == "del_rec_gui_close" ) THEN closePrivButton( "del_rec_car_filter" ); closePrivButton ( "sorting_asc" ); closePrivButton ( "sorting_desc" ); ENDIF closePrivButton( "del_rec_bg_username" ); closePrivButton( "del_rec_title_username" ); closePrivButton( "del_rec_title_nickname" ); closePrivButton( "del_rec_title_date" ); closePrivButton( "del_rec_title_time" ); closePrivButton( "del_rec_title_score" ); closePrivButton( "del_rec_usertitle" ); closePrivButton( "del_rec_user" ); closePrivButton( "del_rec_show_all_users" ); ### Execute sub routine 'del_rec_info_close' ### del_rec_info_close ( $KeyFlags,$id ); ### End ### closePrivButton( "del_rec_del_all_for_user" ); closePrivButton ( "del_rec_del_all_car" ); closePrivButton( "next_page_all_users" ); closePrivButton( "prev_page_all_users" ); closePrivButton( "del_rec_gui_close" ); ### Set 'selected_username' to a blanc value ### SetCurrentPlayerVar( "selected_username", "" ); ### End ### IF ( $id == "del_rec_gui_close" ) THEN SetCurrentPlayerVar( "del_record_mode" , "laptimes" ); SetCurrentPlayerVar( "show_records_of" , "user" ); SetCurrentPlayerVar( "filter", "" ); SetCurrentPlayerVar( "sorting", "" ); ENDIF EndSub Sub delete_record ( $KeyFlags,$id ) ### Retrieve car number by reading string 'del_rec_title_delete_[nbr]' starting at position 21 and then read 2 characters ### ### Delete the record for the selected username and the selected car ### ### Close the whole GUI and then open it again ### $car_number = ToNum( subStr( $id, 21, 2 ) ); IF ( GetCurrentPlayerVar( "del_record_mode" ) == "laptimes" ) THEN deletelaptimerecords( GetCurrentPlayerVar( "selected_username" ),$car_names[1,$car_number] ); ENDIF IF ( GetCurrentPlayerVar( "del_record_mode" ) == "driftscores" ) THEN deletedriftrecords( GetCurrentPlayerVar( "selected_username" ),$car_names[1,$car_number] ); ENDIF ### Execute sub routine 'del_rec_info_close' ### del_rec_gui_close( $KeyFlags,$id ); ### End ### ### Re-open the delete record GUI ### del_rec_gui ( $KeyFlags,$id ); ### End ### EndSub Sub del_rec_while_show_all_users ( $KeyFlags,$id ) $array_pos = ToNum( subStr( $id, 21, 5 ) ); IF ( GetCurrentPlayerVar( "del_record_mode" ) == "laptimes" ) THEN deletelaptimerecords( $username_array[1,$array_pos] , $cname_array[1,$array_pos] ); ENDIF IF ( GetCurrentPlayerVar( "del_record_mode" ) == "driftscores" ) THEN deletedriftrecords( $username_array[1,$array_pos] , $cname_array[1,$array_pos] ); ENDIF closePrivButton( "next_page_all_users" ); closePrivButton( "prev_page_all_users" ); ### Execute sub routine 'del_rec_info_close' ### del_rec_info_close ( $KeyFlags,$id ); ### End ### ### Execute sub routine 'get_records_from_db' ### get_records_from_db(); ### End ### ### Re-open the delete record GUI ### del_rec_gui ( $KeyFlags,$id ); ### End ### EndSub Sub del_all_recs_user ( $KeyFlags,$id ) ### Put values from array '$delete_array' into a new array ### ### Loop through the array and delete the laptimerecords/driftrecords for the carnames found in the array ### $new_array = $delete_array; FOREACH( $val IN $new_array ) IF ( GetCurrentPlayerVar( "del_record_mode" ) == "laptimes" ) THEN deletelaptimerecords( GetCurrentPlayerVar( "selected_username" ) , $val["value" ] ); ELSE deletedriftrecords( GetCurrentPlayerVar( "selected_username" ) , $val["value" ] ); ENDIF ENDFOREACH ### End ### ### Execute sub routine 'del_rec_info_close' ### del_rec_gui_close( $KeyFlags,$id ); ### End ### ### Re-open the delete record GUI ### del_rec_gui ( $KeyFlags,$id ); ### End ### EndSub Sub del_all_recs_car ( $KeyFlags,$id ) $trackcode="-"; IF ( GetCurrentPlayerVar( "del_record_mode" ) == "laptimes" ) THEN deletelaptimerecords( $trackcode , GetCurrentPlayerVar ( "filter" ) ); ELSE deletedriftrecords( $trackcode , GetCurrentPlayerVar ( "filter" ) ); ENDIF ### Execute sub routine 'del_rec_info_close' ### del_rec_info_close ( $KeyFlags,$id ); ### End ### ### Execute sub routine 'get_records_from_db' ### get_records_from_db(); ### End ### ### Re-open the delete record GUI ### del_rec_gui ( $KeyFlags,$id ); ### End ### EndSub Sub set_filter ( $KeyFlags,$id ) ### Set initial values for left/right and top/bottom coordinates ### $left_right_del_rec = 1; $top_bottom_del_rec = 30; ### End ### IF ( $KeyFlags == 1 && GetCurrentPlayerVar( "show_records_of" ) == "all_users" ) THEN openPrivTextButton( "del_rec_car_filter",$left_right_del_rec+1,$top_bottom_del_rec+31,15,5,5,32,"^3Set carname to filter on","^3Set" , 3 , set_filter_value ); ENDIF IF ( $KeyFlags == 2 && GetCurrentPlayerVar( "show_records_of" ) == "all_users" ) THEN SetCurrentPlayerVar ( "filter" , "" ); closePrivButton ( "del_rec_car_filter" ); SetCurrentPlayerVar ( "sorting" , "" ); closePrivButton ( "sorting_asc" ); closePrivButton ( "sorting_desc" ); closePrivButton ( "del_rec_del_all_car" ); ### Execute sub routine 'del_rec_info_close' ### del_rec_gui_close( $KeyFlags,$id ); ### End ### ### Execute sub routine 'get_records_from_db' ### get_records_from_db(); ### End ### ### Re-open the delete record GUI ### del_rec_gui ( $KeyFlags,$id ); ### End ### ENDIF EndSub Sub set_filter_value ( $id,$text ) ### Set initial values for left/right and top/bottom coordinates ### $left_right_del_rec = 1; $top_bottom_del_rec = 30; ### End ### SetCurrentPlayerVar ( "car_check" , "not okay" ); IF ( $text != "" ) THEN $new_array = $car_names; FOREACH ( $val IN $new_array ) IF ( ToUpper ( $text ) == $val["value"] ) THEN SetCurrentPlayerVar ( "car_check" , "okay" ); SetCurrentPlayerVar ( "filter" , ToUpper ( $text ) ); openPrivTextButton( "del_rec_car_filter",$left_right_del_rec+1,$top_bottom_del_rec+31,15,5,5,32,"^3Set carname to filter on","^3" . GetCurrentPlayerVar ( "filter" ) , 3 , set_filter_value ); $start_value_page=0; $end_value_page=19; ### Execute sub routine 'del_rec_info_close' ### del_rec_gui_close( $KeyFlags,$id ); ### End ### ### Execute sub routine 'get_records_from_db' ### get_records_from_db(); ### End ### ### Re-open the delete record GUI ### del_rec_gui ( $KeyFlags,$id ); ### End ### BREAK; ENDIF ENDFOREACH IF ( GetCurrentPlayerVar ( "car_check" ) == "not okay" ) THEN PrivMsg ( "^1WARNING: ^7Given carname isn't a valid value" ); ENDIF ENDIF EndSub Sub set_sorting ( $KeyFlags,$id ) ### Set initial values for left/right and top/bottom coordinates ### $left_right_del_rec = 1; $top_bottom_del_rec = 30; ### End ### IF ( $KeyFlags == 1 ) THEN IF ( GetCurrentPlayerVar ( "sorting" ) == "" || GetCurrentPlayerVar ( "sorting" ) == "DESC" ) THEN SetCurrentPlayerVar ( "sorting" , "ASC" ); ELSE SetCurrentPlayerVar ( "sorting" , "DESC" ); ENDIF ENDIF IF ( $KeyFlags == 2 && GetCurrentPlayerVar ( "sorting" ) != "" ) THEN SetCurrentPlayerVar ( "sorting" , "" ); closePrivButton ( "sorting_asc" ); closePrivButton ( "sorting_desc" ); ENDIF ### Execute sub routine 'del_rec_info_close' ### del_rec_gui_close( $KeyFlags,$id ); ### End ### ### Execute sub routine 'get_records_from_db' ### get_records_from_db(); ### End ### ### Re-open the delete record GUI ### del_rec_gui ( $KeyFlags,$id ); ### End ### EndSub