Check if map is compatible to avoid script crash
This commit is contained in:
		| @@ -221,14 +221,27 @@ Net_CurrentRoundNb = Map_ValidRoundsNb + 1; | |||||||
|  |  | ||||||
| declare Text[] AccountIdsOfPlayers for This = []; | declare Text[] AccountIdsOfPlayers for This = []; | ||||||
| declare CMapLandmark[] Landmarks = Map::GetFinishesAndMultilaps(); | declare CMapLandmark[] Landmarks = Map::GetFinishesAndMultilaps(); | ||||||
| declare CMapLandmark PlayerLM; |  | ||||||
| declare Integer LandmarkIndex for This = 0; |  | ||||||
| AccountIdsOfPlayers = []; |  | ||||||
|  |  | ||||||
| // Suffle Players list to randomise spawn | declare Boolean MapIsCompatible; | ||||||
| declare CSmPlayer[] ShuffledPlayers = Players; | foreach (Landmark in Landmarks) { | ||||||
| declare Integer i=0; | 	if (Map::IsMultilap(Landmark)) { | ||||||
| while(i<ShuffledPlayers.count) { // this should be enough, you can use arbitrary values, should the need arise | 		MapIsCompatible = True; | ||||||
|  | 		break; | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | if (!MapIsCompatible) { | ||||||
|  | 	UIManager.UIAll.QueueMessage(3000, 1, CUIConfig::EMessageDisplay::Big, _("This map is not valid")); | ||||||
|  | 	MB_Sleep(3000); | ||||||
|  | 	MB_StopMap(); | ||||||
|  | } else { | ||||||
|  | 	declare CMapLandmark PlayerLM; | ||||||
|  | 	declare Integer LandmarkIndex for This = 0; | ||||||
|  | 	AccountIdsOfPlayers = []; | ||||||
|  | 	 | ||||||
|  | 	// Suffle Players list to randomise spawn | ||||||
|  | 	declare CSmPlayer[] ShuffledPlayers = Players; | ||||||
|  | 	declare Integer i=0; | ||||||
|  | 	while(i<ShuffledPlayers.count) { // this should be enough, you can use arbitrary values, should the need arise | ||||||
| 		// find a pair (a,b) of valid indices to swap | 		// find a pair (a,b) of valid indices to swap | ||||||
| 		declare a=ML::Rand(0, ShuffledPlayers.count-1); | 		declare a=ML::Rand(0, ShuffledPlayers.count-1); | ||||||
| 		declare b=ML::Rand(0, ShuffledPlayers.count-1); | 		declare b=ML::Rand(0, ShuffledPlayers.count-1); | ||||||
| @@ -239,9 +252,9 @@ while(i<ShuffledPlayers.count) { // this should be enough, you can use arbitrary | |||||||
| 		ShuffledPlayers[a]=tmp; | 		ShuffledPlayers[a]=tmp; | ||||||
| 		 | 		 | ||||||
| 		i=i+1; | 		i=i+1; | ||||||
| } | 	} | ||||||
| 	 | 	 | ||||||
| foreach (Player in ShuffledPlayers) { | 	foreach (Player in ShuffledPlayers) { | ||||||
| 		PlayerLM = Null; | 		PlayerLM = Null; | ||||||
| 		while (PlayerLM == Null) { | 		while (PlayerLM == Null) { | ||||||
| 			if (LandmarkIndex > Landmarks.count - 1 ) { | 			if (LandmarkIndex > Landmarks.count - 1 ) { | ||||||
| @@ -254,15 +267,16 @@ foreach (Player in ShuffledPlayers) { | |||||||
| 		} | 		} | ||||||
| 		Race::Start(Player, PlayerLM , StartTime); | 		Race::Start(Player, PlayerLM , StartTime); | ||||||
| 		AccountIdsOfPlayers.add(Player.User.WebServicesUserId); | 		AccountIdsOfPlayers.add(Player.User.WebServicesUserId); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	Net_NBPlayers = AccountIdsOfPlayers.count; | ||||||
|  | 	 | ||||||
|  | 	UpdateCustomRanking(Null, -1); | ||||||
|  | 	StateMgr::ForcePlayersStates([StateMgr::C_State_Playing]); | ||||||
|  | 	CarRank::Update(CarRank::C_SortCriteria_BestRace); | ||||||
|  | 	Race::EnableIntroDuringMatch(False); | ||||||
|  | 	UIManager.UIAll.SendChat("$<$ff3$> Stay the most time on the structure. $<$ff9GL HF!$>"); | ||||||
| } | } | ||||||
|  |  | ||||||
| Net_NBPlayers = AccountIdsOfPlayers.count; |  | ||||||
|  |  | ||||||
| UpdateCustomRanking(Null, -1); |  | ||||||
| StateMgr::ForcePlayersStates([StateMgr::C_State_Playing]); |  | ||||||
| CarRank::Update(CarRank::C_SortCriteria_BestRace); |  | ||||||
| Race::EnableIntroDuringMatch(False); |  | ||||||
| UIManager.UIAll.SendChat("$<$ff3$> Stay the most time on the structure. $<$ff9GL HF!$>"); |  | ||||||
| *** | *** | ||||||
|  |  | ||||||
| ***Match_PlayLoop*** | ***Match_PlayLoop*** | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user