############################################################################# # Race Duration for LFS Lapper by Krayy ############################################################################# # This mod allows a server admin to set a race duration for either a set number # of minutes or an approximate number of Kms. # This allows a greater level of granularity in race timings. ############################################################################# # # Syntax: # !kms # This will set the race duration to the number of laps that is equal to # the specified distance divided by track length, rounded up. # # !mins [] # This command will cause a race to set its last lap as the lap after # The specific has expired. The optional second parameter allows # you to set the number of extra laps at the end of the race # e.g. "!mins 10 3" will set a rcae to run for 10 mins then add 3 laps # to the lap counter # ############################################################################# # Ver 1.0.1 - 25 Mar 2011 Initial release ############################################################################# const RD_NONE 0; const RD_KMS 1; const RD_MINS 2; CatchEvent OnLapperStart() GlobalVar $rdDuration; $rdDuration = 0; GlobalVar $rdDurationType; $rdDurationType = RD_NONE; GlobalVar $isTimedRace; $isTimedRace = 0; GlobalVar $raceTimerActive; $raceTimerActive = 0; GlobalVar $rdLapCounter; $rdLapCounter = 0; GlobalVar $rdLapsToAdd; $rdLapsToAdd = 1; EndCatchEvent CatchEvent OnMSO( $userName, $text ) # Player event $idxOfFirstSpace = indexOf( $text, " "); IF( $idxOfFirstSpace == -1 ) THEN $command = $text; $argv = ""; ELSE $command = subStr( $text,0,$idxOfFirstSpace ); $argv = trim( subStr( $text,$idxOfFirstSpace ) ); ENDIF SWITCH( $command ) CASE "!mins": IF ( UserIsAdmin( $userName ) == 1 ) THEN SetRaceMins($argv); ELSE privMsg( langEngine( "%{main_notadmin}%" ) ); ENDIF BREAK; CASE "!kms": IF ( UserIsAdmin( $userName ) == 1 ) THEN SetRaceKms($argv); ELSE privMsg( langEngine( "%{main_notadmin}%" ) ); ENDIF BREAK; ENDSWITCH EndCatchEvent Sub SetRaceKms($argv) $myArgs = SplitTOArray( $argv , " " ); IF ( $myArgs[0] == "" ) THEN $isTimedRace = 0; $rdDuration = 0; $raceTimerActive = 0; globalMsg ( langEngine ( "%{raceDuration_Clear}%" ) ); return(); ENDIF $isTimedRace = 0; $rdDuration = 0; $raceTimerActive = 0; # DEBUG("GetLengthTrack is : " . GetLengthTrack(getLapperVar( "ShortTrackName" )) ); IF ( IsNum($myArgs[0]) == true ) THEN $rdDurationType = RD_KMS; $rdDuration = (round( $myArgs[0] / GetLengthTrack(getLapperVar( "ShortTrackName" )) , 0 ) + 1); globalMsg ( langEngine ( "%{raceDuration_SetKms}%", $myArgs[0], $rdDuration ) ) ; cmdLFS ("/laps " . $rdDuration); ELSE privMsg ( langEngine ( "%{raceDuration_NotNum}%", $myArgs[0] ) ); ENDIF EndSub Sub SetRaceMins($argv) $myArgs = SplitTOArray( $argv , " " ); IF ( $myArgs[0] == "" ) THEN $isTimedRace = 0; $rdDuration = 0; $raceTimerActive = 0; globalMsg ( langEngine ( "%{raceDuration_Clear}%" ) ); return(); ENDIF IF ( $myArgs[1] == "" ) THEN $rdLapsToAdd = 1; ELSE IF ( IsNum($myArgs[1]) == true ) THEN $rdLapsToAdd = $myArgs[1]; ELSE privMsg ( langEngine ( "%{raceDuration_NotNum}%", $myArgs[1] ) ); return(); ENDIF ENDIF IF ( IsNum($myArgs[0]) == true ) THEN $rdDurationType = RD_MINS; $isTimedRace = 1; $raceTimerActive = 1; $rdDuration = ($myArgs[0] * 60) + 10; globalMsg ( langEngine ( "%{raceDuration_SetMins}%", $myArgs[0], $rdLapsToAdd ) ) ; cmdLFS ("/hours 48"); ELSE $isTimedRace = 0; $rdDuration = 0; $raceTimerActive = 0; privMsg ( langEngine ( "%{raceDuration_NotNum}%", $myArgs[0] ) ); ENDIF EndSub CatchEvent OnRaceStart ( $NumP ) # Lapper event IF ( $isTimedRace > 0 ) THEN $rdLapCounter = 1; DelayedCommand ( 5, SendRaceTimerMessage ); DelayedCommand ( "raceTimer", $rdDuration, RaceTimerComplete); ENDIF EndCatchEvent CatchEvent OnLap( $userName ) # Player event IF ( $raceTimerActive > 0 ) THEN IF ( ToNum(GetCurrentPlayerVar("Pos")) == 1 ) # Get the lead lap number if applicable THEN $rdLapCounter = $rdLapCounter + 1; DEBUG ("Racer pos is " . GetCurrentPlayerVar("Pos")); DEBUG ("$rdLapCounter now set to " . $rdLapCounter ); ENDIF ENDIF EndCatchEvent Sub RaceTimerComplete () $raceMsLeft = 0; $numLaps = $rdLapCounter + $rdLapsToAdd; $raceTimerActive = 0; globalRcm ( langEngine ( "%{raceDuration_EndMins}%", $numLaps )); globalMsg ( langEngine ( "%{raceDuration_EndMins}%", $numLaps )); cmdLFS ("/laps " . $numLaps); RemoveDelayedCommand( "raceTimer" ); EndSub Sub SendRaceTimerMessage() globalRcm( langEngine ( "%{raceDuration_StartMins}%", round($rdDuration / 60,0 ) ) ); EndSub ############################################################################# Lang "EN" # Race Events messages raceDuration_SetMins = "^2Race duration set to ^3{0}^2 minutes + ^3{1}^2 laps."; raceDuration_SetKms = "^2Race duration set to ^3{0}^2 Kms which equals ^3{1}^2 laps."; raceDuration_NotNum = "^2Race duration ^1not^2 set as ^3{0} ^2is not an integer."; raceDuration_Clear = "^3Race duration cleared and will deafult to LFS settings."; raceDuration_StartMins = "^3This is a timed race and will run for {0} minutes."; raceDuration_EndMins = "^2Times up! Race will end on lap ^3{0}^2!"; EndLang