Check if map is compatible to avoid script crash
This commit is contained in:
parent
3124754b1e
commit
405bd533f8
@ -221,48 +221,62 @@ 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;
|
||||||
// find a pair (a,b) of valid indices to swap
|
break;
|
||||||
declare a=ML::Rand(0, ShuffledPlayers.count-1);
|
|
||||||
declare b=ML::Rand(0, ShuffledPlayers.count-1);
|
|
||||||
|
|
||||||
// now swap them
|
|
||||||
declare tmp=ShuffledPlayers[b];
|
|
||||||
ShuffledPlayers[b]=ShuffledPlayers[a];
|
|
||||||
ShuffledPlayers[a]=tmp;
|
|
||||||
|
|
||||||
i=i+1;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (Player in ShuffledPlayers) {
|
|
||||||
PlayerLM = Null;
|
|
||||||
while (PlayerLM == Null) {
|
|
||||||
if (LandmarkIndex > Landmarks.count - 1 ) {
|
|
||||||
LandmarkIndex = 0;
|
|
||||||
}
|
|
||||||
if (Map::IsMultilap(Landmarks[LandmarkIndex])) {
|
|
||||||
PlayerLM = Landmarks[LandmarkIndex];
|
|
||||||
}
|
|
||||||
LandmarkIndex = LandmarkIndex + 1 ;
|
|
||||||
}
|
}
|
||||||
Race::Start(Player, PlayerLM , StartTime);
|
|
||||||
AccountIdsOfPlayers.add(Player.User.WebServicesUserId);
|
|
||||||
}
|
}
|
||||||
|
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 = [];
|
||||||
|
|
||||||
Net_NBPlayers = AccountIdsOfPlayers.count;
|
// 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
|
||||||
|
declare a=ML::Rand(0, ShuffledPlayers.count-1);
|
||||||
|
declare b=ML::Rand(0, ShuffledPlayers.count-1);
|
||||||
|
|
||||||
UpdateCustomRanking(Null, -1);
|
// now swap them
|
||||||
StateMgr::ForcePlayersStates([StateMgr::C_State_Playing]);
|
declare tmp=ShuffledPlayers[b];
|
||||||
CarRank::Update(CarRank::C_SortCriteria_BestRace);
|
ShuffledPlayers[b]=ShuffledPlayers[a];
|
||||||
Race::EnableIntroDuringMatch(False);
|
ShuffledPlayers[a]=tmp;
|
||||||
UIManager.UIAll.SendChat("$<$ff3$> Stay the most time on the structure. $<$ff9GL HF!$>");
|
|
||||||
|
i=i+1;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (Player in ShuffledPlayers) {
|
||||||
|
PlayerLM = Null;
|
||||||
|
while (PlayerLM == Null) {
|
||||||
|
if (LandmarkIndex > Landmarks.count - 1 ) {
|
||||||
|
LandmarkIndex = 0;
|
||||||
|
}
|
||||||
|
if (Map::IsMultilap(Landmarks[LandmarkIndex])) {
|
||||||
|
PlayerLM = Landmarks[LandmarkIndex];
|
||||||
|
}
|
||||||
|
LandmarkIndex = LandmarkIndex + 1 ;
|
||||||
|
}
|
||||||
|
Race::Start(Player, PlayerLM , StartTime);
|
||||||
|
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!$>");
|
||||||
|
}
|
||||||
***
|
***
|
||||||
|
|
||||||
***Match_PlayLoop***
|
***Match_PlayLoop***
|
||||||
|
Loading…
Reference in New Issue
Block a user