18.12.2010, 00:16
This is how would go about doing it:
Sorry for the comment spam, I tried to make it clear exactly what is happening! In this solution, I have assumed that the variable gTeam[] holds an integer value that represents the "team ID" that a player is in.
I do have a suggestion regarding the MapChange() method: give it a parameter so that it knows which team has just lost. For example: MapChange(gTeam[playerid]) would tell the MapChange method that this player's team has just lost. If you have already thought of doing this, then just ignore me
pawn Код:
new bool:flag = false; // this flag will turn true if another person is found
// to be alive on the player's team
for(new i = 0; i < MAX_PLAYERS; i++) { // loop through all players
if(gTeam[i] == gTeam[playerid]) { // is the current player in the loop on the same team as the player who died?
if(GetPlayerState(i) != PLAYER_STATE_SPECTATING) { // is the team-mate still alive?
if(!flag) { // has an alive team-mate been found yet?
TogglePlayerSpectating(playerid, 1);
PlayerSpectatePlayer(playerid, i); // spectate the team-mate who is alive!
flag = true; // set flag to true, to indicate there has been an alive team-mate found
}
}
}
}
if(!flag) { // loop has finished, was an alive team-mate found?
MapChange(); // no alive team-mates found, initiate the MapChange method!
}
I do have a suggestion regarding the MapChange() method: give it a parameter so that it knows which team has just lost. For example: MapChange(gTeam[playerid]) would tell the MapChange method that this player's team has just lost. If you have already thought of doing this, then just ignore me
