# Author: Yisc[NL] # # Lapper version needed: 6.0.1.4 or above # # # # Limit amount of rejoins - V1.00 14-09-2017 -Initial release # ######################################################################################################################################### CatchEvent OnLapperStart() OnLapperStart_Limit_Rejoins(); EndCatchEvent CatchEvent OnMSO( $userName, $text ) # Player event $idxOfFirtsSpace = indexOf( $text, " "); $userName = GetCurrentPlayerVar("UserName"); UserGroupFromFile( "admin", "./admin.txt" ); IF( $idxOfFirtsSpace == -1 ) THEN $command = $text; $argv = ""; ELSE $command = subStr( $text,0,$idxOfFirtsSpace ); $argv = trim( subStr( $text,$idxOfFirtsSpace ) ); ENDIF SWITCH( $command ) CASE "!cfg_limit_rejoin": CASE "!cfglr": IF( UserInGroup( "admin", $userName ) == 1 ) THEN Config_Limit_Rejoin( $KeyFlags ); ELSE PrivMsg( "^1You are not allowed to do that"); ENDIF BREAK; ENDSWITCH EndCatchEvent CatchEvent OnNewPlayerJoin( $userName ) # Player event OnNewPlayerJoin_Limit_Rejoins(); EndCatchEvent CatchEvent OnRaceStart( $NumP ) # Lapper event DelayedCommand( 5, ORS_Limit_Rejoins ); EndCatchEvent Sub ORS_Limit_Rejoins() OnRaceStart_Limit_Rejoins(); EndSub CatchEvent OnResult( $userName,$flagConfirm ) # Player event OnResult_Limit_Rejoins( $userName,$flagConfirm ); EndCatchEvent Sub OnLapperStart_Limit_Rejoins() ### Declare global variable(s) and give them a value ### GlobalVar $allowed_number_rejoins; GlobalVar $version_rejoin_limit; GlobalVar $race_status; $allowed_number_rejoins = GetStoredValue( "Allowed_number_rejoins" ); $version_rejoin_limit="V1.00"; $race_status="off"; ### End ### EndSub Sub OnNewPlayerJoin_Limit_Rejoins() ### When player joins track set PlaverVar 'race_status' to the value of GlobalVar $race_status ### ### When player joins track set PlaverVar 'nbr_rejoins_allowed' to value retrieved from database (this to stop people from disconnecting, connecting and then have a new number of allowed rejoins) ### ### If no value could be retrieved from database, set it to the number of allowed rejoins set by an admin using !cfglr ### ### If 'race_status' is "on" and player rejoins track, lower the number of rejoins_allowed by 1 and store new value into the database ### ### In case 'nbr_rejoins_allowed' goes below 0, spectate player when joining track and notify player why the spectate has happened ### ### In case 'nbr_rejoins_allowed' is greater than or equal to 0, notify player how many rejoins they have left ### SetCurrentPlayerVar( "race_status" , $race_status ); SetCurrentPlayerVar( "nbr_rejoins_allowed",GetUserStoredNum( "nbr_rejoins_allowed" ) ); IF ( GetCurrentPlayerVar( "nbr_rejoins_allowed" ) == "" ) THEN SetCurrentPlayerVar( "nbr_rejoins_allowed", $allowed_number_rejoins ); SetUserStoredNum( "nbr_rejoins_allowed", GetCurrentPlayerVar( "nbr_rejoins_allowed" ) ); ENDIF IF ( GetCurrentPlayerVar( "race_status" ) == "on" ) THEN SetCurrentPlayerVar( "nbr_rejoins_allowed" , GetCurrentPlayerVar( "nbr_rejoins_allowed" ) - 1 ); SetUserStoredNum( "nbr_rejoins_allowed", GetCurrentPlayerVar( "nbr_rejoins_allowed" ) ); IF ( ToNum ( GetCurrentPlayerVar( "nbr_rejoins_allowed" ) ) < 0 ) THEN cmdLFS ("/spec " . GetCurrentPlayerVar ( "UserName" ) ); PrivMsg ( "^1WARNING: ^7You have used all number of rejoins for this race" ); ELSE IF ( ToNum ( GetCurrentPlayerVar( "nbr_rejoins_allowed" ) ) > 0 ) THEN PrivMsg ( "^7INFO: You have ^2" . GetCurrentPlayerVar( "nbr_rejoins_allowed" ) . "^7 allowed rejoin(s) remaining" ); ELSE PrivMsg ( "^7INFO: You have ^1" . GetCurrentPlayerVar( "nbr_rejoins_allowed" ) . "^7 allowed rejoins remaining" ); ENDIF ENDIF ENDIF ### End ### EndSub Sub OnRaceStart_Limit_Rejoins() # Lapper event ### Gather list of currently connected players ### ### Count the number of values in array $mList ### ### Set $plynum to 0 ### ### Loop through values in array $mList and set 'race_status' to "on" and number of rejoins_allowed to X for every player ### ### Raise $plyNum at the end of each loop ### $mList = GetListOfPlayers("N"); $mCount = arrayCount( $mList ); $plyNum=0; WHILE ($plyNum < $mCount) $uName = $mList[$plyNum]; SetPlayerVar( $uName,"race_status","on" ); SetUserStoredvalue( $uName,"nbr_rejoins_allowed", $allowed_number_rejoins ); $plyNum=$plyNum+1; ENDWHILE ### End ### ### Set GlobalVar $race_status to "on" and notify players about that ### $race_status = "on"; GlobalMsg ( "^7INFO: race status has now been set to 'on'" ); ### End ### EndSub Sub OnResult_Limit_Rejoins( $userName,$flagConfirm ) ### IF result is confirmed, set 'race_status' to "off" ### IF( ( $flagConfirm & 2 ) == CONF_CONFIRMED ) THEN SetCurrentPlayerVar( "race_status","off" ); ENDIF ### End ### ### Executed delayed command after 180 second (3 minutes) to go and change value $race_status ### ### A 3 minute window after the first player finished, should be enough for all players to finish ### DelayedCommand( 180, change_race_status ); ### End ### EndSub Sub change_race_status() ### Set GlobalVar $race_status to "off" and notify players about that ### $race_status = "off"; GlobalMsg ( "^7INFO: race status has now been set to 'off'" ); ### End ### EndSub Sub Config_Limit_Rejoin( $KeyFlags ) ### Set initial values for left/right and top/bottom coordinates ### $left_right_rejoin_limit = 69; $top_bottom_rejoin_limit = 80; ### End ### ### Draw the Rejoin Limit GUI ### openPrivButton( "rejoin_limit_gui_bg",$left_right_rejoin_limit,$top_bottom_rejoin_limit,62,40,5,-1,16,""); openPrivButton( "rejoin_limit_title",$left_right_rejoin_limit+1,$top_bottom_rejoin_limit+1,60,5,5,-1,32,"^7Set rejoin limit - " . $version_rejoin_limit ); openPrivButton( "rejoin_limit_text",$left_right_rejoin_limit+1,$top_bottom_rejoin_limit+17,30,5,5,-1,32,"^7Allow number of rejoins:" ); IF ( $allowed_number_rejoins == "" ) THEN openPrivTextButton( "rejoin_limit_value",$left_right_rejoin_limit+31,$top_bottom_rejoin_limit+17,30,5,5,32,"^3Set number of allowed rejoins","^3Click to set value",2,rejoin_limit_set_value ); ELSE openPrivTextButton( "rejoin_limit_value",$left_right_rejoin_limit+31,$top_bottom_rejoin_limit+17,30,5,5,32,"^3Set number of allowed rejoins","^3".$allowed_number_rejoins,2,rejoin_limit_set_value ); ENDIF openPrivButton( "rejoin_limit_close",$left_right_rejoin_limit+1,$top_bottom_rejoin_limit+34,60,5,5,-1,32,"^3Close GUI",rejoin_limit_close ); ### End ### EndSub Sub rejoin_limit_set_value ($id,$text) IF ( IsNum ( $text) == 1 ) THEN $allowed_number_rejoins=$text; SetStoredValue( "Allowed_number_rejoins", $allowed_number_rejoins ); Config_Limit_Rejoin( $KeyFlags ); ELSE PrivMsg ( "^1WARNING: ^7Given value isn't a number" ); ENDIF EndSub Sub rejoin_limit_close ( $KeyFlags,$id ) closePrivButton( "rejoin_limit_gui_bg&rejoin_limit_title&rejoin_limit_text&rejoin_limit_value&rejoin_limit_close" ); EndSub