# Author: Yisc[NL] # # # # Author initial script: Tim NL # # Credits to: Bass Driver (for making the code to display a toplist) # # # # Lapper version needed: 7.0.4.10 or above # # # # Points system V1.00 15-09-2009 -Initial release # # Points system V1.01 08-05-2020 -Script converted into a module # # -Added code to calculate the number of players that is on track when race starts # # -topUser is a discontinued function, added code (made my Bass-Driver) to replace that # # -nearUser is a discontinued function, added code (made by Bass-Driver) to replace that # # Points system V1.02 12-05-2020 -Added code to give extra points to the player that drove the fastest lap of the race # # -Removed several lines of closeGlobalButton, since the button ID's that were closed were not in use # # Points system V1.03 21-05-2020 -Removed "$ps_max_points=10" from OnLapperStart as it no longer has a purpose # # -Made the display of points earned dynamic # # -Added option (only for admins) to delete all points related records from the database # ######################################################################################################################################################################### CatchEvent OnLapperStart() OnLapperStart_Points_system(); 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 "!point": show_points( 0,0 ); BREAK; CASE "!rank": show_points( 0,1 ); BREAK; CASE "!delpoints": IF ( UserIsAdmin( $userName ) == 1 ) THEN Delete_Points_Confirm(0,0); ENDIF BREAK ENDSWITCH EndCatchEvent CatchEvent OnRaceStart( $NumP ) # Lapper event DelayedCommand( 5, ORS_Points_system ); EndCatchEvent Sub ORS_Points_system() OnRaceStart_Points_system(); EndSub CatchEvent OnQualStart( $NumP ) # Lapper event DelayedCommand( 5, OQS_Points_system ); EndCatchEvent Sub OQS_Points_system() OnQualStart_Points_system(); EndSub CatchEvent OnResult( $userName,$flagConfirm ) # Player event SetCurrentPlayerVar( "ps_race_points",(($ps_max_points+1) - GetCurrentPlayerVar( "FinishedPos" ) ) ); SetCurrentPlayerVar( "ps_points_total",getUserStoredValue( "ps_points_total" ) ); IF( GetCurrentPlayerVar( "ps_points_total" ) == "" ) THEN SetCurrentPlayerVar( "ps_points_total","0" ); ENDIF IF( ToNum(GetCurrentPlayerVar( "ps_race_points" )) < 1 ) THEN SetCurrentPlayerVar( "ps_race_points",0 ); ENDIF SWITCH( GetCurrentPlayerVar("FinishedPos") ) CASE 1: IF(( $flagConfirm == 2 )||( $flagConfirm == 18 )||( $flagConfirm == 34 )) THEN openGlobalButton( "point900",$point_L,$point_T-4,40,4,4,-1,96,"^7 Race on ^3" . GetLapperVar("LongDate") . " @ " . GetLapperVar("LongTime") ); openGlobalButton( "point910",$point_L+40,$point_T-4,6,4,4,-1,96,"^7points" ); openGlobalButton( "point001",$point_L,$point_T,40,4,4,-1,96,"^7 1 : " . GetCurrentPlayerVar("NickName") ); openGlobalButton( "point101",$point_L+40,$point_T,6,4,4,-1,32,"^3" . GetCurrentPlayerVar( "ps_race_points" ) ); ENDIF BREAK; CASE 2: IF(( $flagConfirm == 2 )||( $flagConfirm == 18 )||( $flagConfirm == 34 )) THEN openGlobalButton( "point002",$point_L,$point_T,40,4,4,-1,96,"^7 2 : " . GetCurrentPlayerVar("NickName") ); openGlobalButton( "point102",$point_L+40,$point_T,6,4,4,-1,32,"^3" . GetCurrentPlayerVar( "ps_race_points" ) ); ENDIF BREAK; CASE 3: IF(( $flagConfirm == 2 )||( $flagConfirm == 18 )||( $flagConfirm == 34 )) THEN openGlobalButton( "point003",$point_L,$point_T,40,4,4,-1,96,"^7 3 : " . GetCurrentPlayerVar("NickName") ); openGlobalButton( "point103",$point_L+40,$point_T,6,4,4,-1,32,"^3" . GetCurrentPlayerVar( "ps_race_points" ) ); ENDIF BREAK; CASE 4: IF(( $flagConfirm == 2 )||( $flagConfirm == 18 )||( $flagConfirm == 34 )) THEN openGlobalButton( "point004",$point_L,$point_T,40,4,4,-1,96,"^7 4 : " . GetCurrentPlayerVar("NickName") ); openGlobalButton( "point104",$point_L+40,$point_T,6,4,4,-1,32,"^3" . GetCurrentPlayerVar( "ps_race_points" ) ); ENDIF BREAK; CASE 5: IF(( $flagConfirm == 2 )||( $flagConfirm == 18 )||( $flagConfirm == 34 )) THEN openGlobalButton( "point005",$point_L,$point_T,40,4,4,-1,96,"^7 5 : " . GetCurrentPlayerVar("NickName") ); openGlobalButton( "point105",$point_L+40,$point_T,6,4,4,-1,32,"^3" . GetCurrentPlayerVar( "ps_race_points" ) ); ENDIF BREAK; CASE 6: IF(( $flagConfirm == 2 )||( $flagConfirm == 18 )||( $flagConfirm == 34 )) THEN openGlobalButton( "point006",$point_L,$point_T,40,4,4,-1,96,"^7 6 : " . GetCurrentPlayerVar("NickName") ); openGlobalButton( "point106",$point_L+40,$point_T,6,4,4,-1,32,"^3" . GetCurrentPlayerVar( "ps_race_points" ) ); ENDIF BREAK; CASE 7: IF(( $flagConfirm == 2 )||( $flagConfirm == 18 )||( $flagConfirm == 34 )) THEN openGlobalButton( "point007",$point_L,$point_T,40,4,4,-1,96,"^7 7 : " . GetCurrentPlayerVar("NickName") ); openGlobalButton( "point107",$point_L+40,$point_T,6,4,4,-1,32,"^3" . GetCurrentPlayerVar( "ps_race_points" ) ); ENDIF BREAK; CASE 8: IF(( $flagConfirm == 2 )||( $flagConfirm == 18 )||( $flagConfirm == 34 )) THEN openGlobalButton( "point008",$point_L,$point_T,40,4,4,-1,96,"^7 8 : " . GetCurrentPlayerVar("NickName") ); openGlobalButton( "point108",$point_L+40,$point_T,6,4,4,-1,32,"^3" . GetCurrentPlayerVar( "ps_race_points" ) ); ENDIF BREAK; CASE 9: IF(( $flagConfirm == 2 )||( $flagConfirm == 18 )||( $flagConfirm == 34 )) THEN openGlobalButton( "point009",$point_L,$point_T,40,4,4,-1,96,"^7 9 : " . GetCurrentPlayerVar("NickName") ); openGlobalButton( "point109",$point_L+40,$point_T,6,4,4,-1,32,"^3" . GetCurrentPlayerVar( "ps_race_points" ) ); ENDIF BREAK; CASE 10: IF(( $flagConfirm == 2 )||( $flagConfirm == 18 )||( $flagConfirm == 34 )) THEN openGlobalButton( "point010",$point_L,$point_T,40,4,4,-1,96,"^710 : " . GetCurrentPlayerVar("NickName") ); openGlobalButton( "point110",$point_L+40,$point_T,6,4,4,-1,32,"^3" . GetCurrentPlayerVar( "ps_race_points" ) ); ENDIF BREAK; CASE 11: IF(( $flagConfirm == 2 )||( $flagConfirm == 18 )||( $flagConfirm == 34 )) THEN openGlobalButton( "point011",$point_L,$point_T,40,4,4,-1,96,"^711 : " . GetCurrentPlayerVar("NickName") ); openGlobalButton( "point111",$point_L+40,$point_T,6,4,4,-1,32,"^3" . GetCurrentPlayerVar( "ps_race_points" ) ); ENDIF BREAK; CASE 12: IF(( $flagConfirm == 2 )||( $flagConfirm == 18 )||( $flagConfirm == 34 )) THEN openGlobalButton( "point012",$point_L,$point_T,40,4,4,-1,96,"^712 : " . GetCurrentPlayerVar("NickName") ); openGlobalButton( "point112",$point_L+40,$point_T,6,4,4,-1,32,"^3" . GetCurrentPlayerVar( "ps_race_points" ) ); ENDIF BREAK; DEFAULT: BREAK; ENDSWITCH ### Raise value of $point_L by 4 each time this event is used ### $point_T = $point_T +4; ### End ### ### Check wether current players best laptime is better than best laptime on record ### IF ( GetCurrentPlayerVar( "RacePBTime" ) < $ps_fastest_lap_time ) THEN $ps_fastest_lap_time = GetCurrentPlayerVar( "RacePBTime" ); $ps_fastest_lap_username = GetCurrentPlayerVar("UserName"); ENDIF ### End ### SetCurrentPlayerVar( "ps_points_total",ToNum(GetCurrentPlayerVar( "ps_points_total" ))+ GetCurrentPlayerVar( "ps_race_points" ) ); setUserStoredValue( "ps_points_total", GetCurrentPlayerVar( "ps_points_total" ) ); DelayedCommand( 10, Fastest_lap ); EndCatchEvent Sub Fastest_lap() ### Display nickname of player that drove the fastest lap of the race ### openGlobalButton( "point013",$point_L,$point_T,40,4,4,-1,96,"^7Fastest lap : " . GetPlayerVar($ps_fastest_lap_username,"NickName") ); openGlobalButton( "point113",$point_L+40,$point_T,6,4,4,-1,32,"^315" ); ### End ### ### Store the points for driving the fastest lap of the race ### SetPlayerVar( $ps_fastest_lap_username,"ps_points_total",ToNum(GetPlayerVar( $ps_fastest_lap_username,"ps_points_total" ))+ 15 ); setUserStoredValue( $ps_fastest_lap_username,"ps_points_total", GetPlayerVar( $ps_fastest_lap_username,"ps_points_total" ) ); ### End ### EndSub Sub OnLapperStart_Points_system() GlobalVar $point_L ; GlobalVar $point_T ; GlobalVar $ps_max_points; GlobalVar $ps_fastest_lap_time; GlobalVar $ps_fastest_lap_username; $point_L = 75; $point_T = 5; EndSub Sub OnRaceStart_Points_system() $mList = GetListOfPlayers("N"); $mCount = arrayCount( $mList ); $plyNum=0; $players_on_track=0; WHILE ($plyNum < $mCount) $uName = $mList[$plyNum]; $plyNum=$plyNum+1; IF ( GetPlayerVar( $uName,"OnTrack" ) == 1 ) THEN $players_on_track=$players_on_track+1; ENDIF ENDWHILE $ps_max_points=$players_on_track; cmdLFS( "/msg ^3Max. points to score this race (^2 " . $ps_max_points . " ^3)" ); closeGlobalButton("point900&point910&point920&point001&point002&point003&point004&point005&point006&point007&point008&point009&point010&point011&point012&point013"); closeGlobalButton("point101&point102&point103&point104&point105&point106&point107&point108&point109&point110&point111&point112&point113"); ### Reset fastest lap time and username that drove that time ### $ps_fastest_lap_time=999999999; $ps_fastest_lap_username=""; ### End ### ### Reset value of $point_T to its initial value ### $point_T = 5; ### End ### EndSub Sub OnQualStart_Points_system() closeGlobalButton("point900&point910&point920&point001&point002&point003&point004&point005&point006&point007&point008&point009&point010&point011&point012&point013"); closeGlobalButton("point101&point102&point103&point104&point105&point106&point107&point108&point109&point110&point111&point112&point113"); EndSub Sub show_points( $KeyFlags,$id ) ### Check if $id is empty and if so, give it value 0 (this means $flagnear = FALSE) ### IF ($id == "" ) THEN $id = 0; ENDIF ### End ### $list = getlisttopuser( "ps_points_total", "DESC", $id, 0 ); $currUName = getCurrentPlayerVar( "UserName" ); $Points_system_but_close = ""; $initTop = 40; #Startheight $P_H = 5; #Height of button $P_T = $initTop + ($P_H); ###Background/Title/CloseButton### openPrivButton("points_system_bgd",64,$initTop-7,58,120,10,-1,16,"^0"); openPrivButton("points_system_title",65,$initTop-6,56,6,10,-1,32,"^7List of: Points"); openPrivButton("points_system_close",65,$initTop+105,56,6,10,-1,32,"^7Close List",Close_points_system_top); ###First Row### openPrivButton("points_system_colpos", 65, $P_T-5, 7, $P_H, $P_H, -1, 32, "Pos"); openPrivButton("points_system_colnickname", 72, $P_T-5, 30, $P_H, $P_H, -1, 32, "Nickname"); openPrivButton("points_system_coluservalue", 102, $P_T-5, 19, $P_H, $P_H, -1, 32, "Total points"); #Playervar for Closing buttons $Points_system_but_close = "&points_system_colpos&points_system_colnickname&points_system_coluservalue"; SetPlayerVar($currUName, Points_system_close, $Points_system_but_close); ### List ### FOR ( $i = 0; $i < 20; $i = $i + 1) IF ( $list[$i,"NickName"] == "") THEN $colpos = ""; $colnickname = ""; $colvalue = ""; ELSE $colusername = $list[$i,"UserName"]; $colnickname = $list[$i,"NickName"]; IF ($id == 0) THEN $colpos = $list[$i,"Pos"] + 1; ELSE $colpos = $list[$i,"Pos"]; ENDIF $colvalue = $list[$i,"Value"]; ENDIF ### IF player in list is equal with current player , make button light $bStyle = ISB_DARK; IF( ToLower( $currUName ) == ToLower( $colusername ) ) THEN $bStyle = ISB_LIGHT; ENDIF openPrivButton("points_system_colpos_".$i,65, $P_T, 7, $P_H, $P_H, -1, $bStyle | ISB_C2 | ISB_C4 , $colpos); openPrivButton("points_system_colnickname_".$i, 72, $P_T, 30, $P_H, $P_H, -1, $bStyle | ISB_LEFT, $colnickname); openPrivButton("points_system_coluservalue_".$i, 102, $P_T, 19, $P_H, $P_H, -1, $bStyle, "^7" .$colvalue . ""); $P_T = $P_T + 5; $Points_system_but_close = $Points_system_but_close . "&points_system_colpos_".$i."&points_system_colnickname_".$i."&points_system_coluservalue_".$i; SetPlayerVar($currUName, Points_system_close, $Points_system_but_close); ENDFOR EndSub Sub Close_points_system_top($KeyFlags,$id ) closePrivButton("points_system_bgd&points_system_title&points_system_close"); closePrivButton(Getcurrentplayervar("Points_system_close")); EndSub Sub Delete_Points_Confirm($keyflags,$id) ### Open buttons for a confirmation screen ### openPrivButton( "delete_points_request",75,75,50,5,5,-1,32,"^3Do you want to delete all points?" ); openPrivButton( "delete_points_yes",75,80,25,5,5,-1,32,"^2Yes",Delete_Points ); openPrivButton( "delete_points_no",100,80,25,5,5,-1,32,"^1No",Delete_Points_Close ); ### End ### EndSub Sub Delete_Points($keyflags,$id) ### Retrieve all records from the database is descending order ### $points_list = getlisttopuser( "ps_points_total", "DESC", 0, 0 ); ### End ### ### Set counter ($i) to 0 , walk through array $points_list using a WHILE loop , delete records ### $i=0; WHILE( $points_list[$i] != "" ) DeleteUserStoredValue( $points_list[$i,"UserName"],"ps_points_total" ); $i = $i +1; ENDWHILE ### End ### ### Show a message that all records have been deleted ### PrivMsg ( "^7INFO: All records have been deleted" ); ### End ### ### Close all buttons of the confirmation screen ### closePrivButton("delete_points_request&delete_points_yes&delete_points_no"); ### End ### EndSub Sub Delete_Points_Close($keyflags,$id) ### Close all buttons of the confirmation screen ### closePrivButton("delete_points_request&delete_points_yes&delete_points_no"); ### End ### EndSub