############################################################################# # Race Progress System by Krayy ############################################################################# # The Race Progress System tracks the number of racers that are # currently in a race and allows for a custom sub to be run after # all current racers have had a valid Result. ############################################################################# # Ver 1.0.1 15/01/2010 Initial release ############################################################################# CatchEvent OnLapperStart() GlobalVar $RaceInProgress; GlobalVar $NumRacers; $RaceInProgress = 0; $NumRacers = 0; EndCatchEvent CatchEvent OnRaceStart( $NumP ) # Lapper event $RaceInProgress = 1; $NumRacers = $NumP; EndCatchEvent CatchEvent OnNewPlayerJoin( $userName ) # Player event IF ( IsRaceRunning() == 1 ) THEN $NumRacers = $NumRacers + 1; globalMsg( "DEBUG: Player join. NumRacers: " . $NumRacers ); ENDIF EndCatchEvent CatchEvent OnLeaveRace( $userName ) # Player event IF ( IsRaceRunning() == 1 ) THEN $NumRacers = $NumRacers - 1; globalMsg( "DEBUG: Player left. NumRacers: " . $NumRacers ); ENDIF EndCatchEvent CatchEvent OnPit( $userName ) # Player event IF ( IsRaceRunning() == 1 ) THEN $NumRacers = $NumRacers - 1; globalMsg( "DEBUG: Player pitted. NumRacers: " . $NumRacers ); ENDIF EndCatchEvent CatchEvent OnResult( $userName,$flagConfirm ) # Player event IF ( IsRaceRunning() == 1 ) THEN $NumRacers = $NumRacers - 1; ENDIF # Set RaceInProgress to 0 to indicate that all racers have finished the race IF ( ToNum($NumRacers) == 0 ) THEN $RaceInProgress = 0; RaceComplete (); ENDIF EndCatchEvent Sub IsRaceRunning() IF ( ToNum($RaceInProgress) == 1 ) THEN return(1); ELSE return(0); ENDIF EndSub Sub RaceComplete () globalMsg( langEngine( "%{raceprogress_complete}%") ); EndSub Lang "EN" # Race Progress Messages raceprogress_complete = "^3All racers finished! Race complete."; EndLang