new Iterator:PlayersInEvent<MAX_PLAYERS>;
Iter_Add(PlayersInEvent,playerid);
new randomid = Iter_Random(PlayersInEvent);
Iter_Remove(PlayersInEvent,playerid);
Iter_Clear(PlayersInEvent);
for(new i; i < MAX_PLAYERS; i++)
{
if(//a boolean variable which is assigned to the playerid who joins the event. ex: InEvent[i])
{
// ur code here
}
}
@TheToretto it's funny how you mentioned almost every Iterator function but made a loop using for(new i; i < MAX_PLAYERS; i++) ..
|
if(Iter_Count(PlayersInEvent) > 2){
new president = Iter_Random(PlayersInEvent);
Iter_Remove(PlayersInEvent,president);
new vice_president = Iter_Random(PlayersInEvent);
Iter_Add(PlayersInEvent,president);
}else{
Iter_Clear(PlayersInEvent);
//end event ...
}
The above method would be simple and will work but relying on random data to exit a iterative statement is a bad practice.You can remove random value from the iterator,assign it to a variable denoting president and again take the random value from iterator for vice president and add the value that was removed previously, back into the iterator.Also you can take the number of players in event using Iter_Count function.
PHP код:
|
P_INFO[TIME_START] --;
if(P_INFO[TIME_START] >= 1)
{
for(new playerid = 0, j = GetPlayerPoolSize(); playerid <= j; playerid++)
{
if(IsPlayerConnected(playerid))
{
if(Player[playerid][M_PTP] == 1)
{
new str[10]; format(str, sizeof(str), "%d", P_INFO[TIME_START]);
GameTextForPlayer(playerid, str, 1000, 3);
new r = Iter_Random(PlayersInEvent);
if(!P_INFO[PRESIDENT_READY])
{
Iter_Remove(PlayersInEvent, r);
P_INFO[PRESIDENT_READY] = true;
Player[r][PLAYER_SERVICE_SECRET] = PRESIDENT;
SendClientMessageEx(playerid, -1, "%s is the new president", Player[r][NAME]);
}
else
{
Player[r][PLAYER_SERVICE_SECRET] = VICE_PRESIDENT;
SendClientMessageEx(playerid, -1, "%s is the new vice president", Player[r][NAME]);
}
}
}
}
}
P_INFO[TIME_START] --;
if(P_INFO[TIME_START] >= 1)
{
for(new playerid = 0, j = GetPlayerPoolSize(); playerid <= j; playerid++)
{
if(IsPlayerConnected(playerid))
{
if(Player[playerid][M_PTP] == 1)
{
new str[10]; format(str, sizeof(str), "%d", P_INFO[TIME_START]);
GameTextForPlayer(playerid, str, 1000, 3);
new r = Iter_Random(PlayersInEvent);
if(!P_INFO[PRESIDENT_READY])
{
Iter_Remove(PlayersInEvent, r);
P_INFO[PRESIDENT_READY] = true;
Player[r][PLAYER_SERVICE_SECRET] = PRESIDENT;
SendClientMessageEx(playerid, -1, "%s is the new president", Player[r][NAME]);
}
else
{
Player[r][PLAYER_SERVICE_SECRET] = VICE_PRESIDENT;
SendClientMessageEx(playerid, -1, "%s is the new vice president", Player[r][NAME]);
}
}
}
}
}
If I understand, but I want to already choose the president and vice president, just continue the countdown and do not choose again. Is a timer that repeats every 1 second, then through that countdown is going to elect the president and the vice president, the problem is that it is choosing until the countdown is over and I do not want that, I want to choose a once..
I do not know if they understand me enough. |
P_INFO[TIME_START] --;
if(P_INFO[TIME_START] >= 1)
{
for(new playerid = 0, j = GetPlayerPoolSize(); playerid <= j; playerid++)
{
if(IsPlayerConnected(playerid))
{
if(Player[playerid][M_PTP] == 1)
{
if(!P_INFO[ALL_READY])
{
new president = Iter_Random(PlayersInEvent);
Iter_Remove(PlayersInEvent, president);
Player[president][PLAYER_SERVICE_SECRET] = PRESIDENT;
SendClientMessageEx(playerid, -1, "%s is the new president", Player[president][NAME]);
new vice_president = Iter_Random(PlayersInEvent);
Player[vice_president][PLAYER_SERVICE_SECRET] = VICE_PRESIDENT;
SendClientMessageEx(playerid, -1, "%s is the new vice president", Player[vice_president][NAME]);
P_INFO[ALL_READY] = true;
}
new str[10]; format(str, sizeof(str), "%d", P_INFO[TIME_START]);
GameTextForPlayer(playerid, str, 1000, 3);
}
}
}
}