Posts: 140
Threads: 35
Joined: Jul 2017
How can I do if I want to randomly select one of the many players in the event? That is, of all those who are in the event, one is chosen.
Example: "Tester is now the killer of the event"
Posts: 716
Threads: 92
Joined: May 2018
@TheToretto it's funny how you mentioned almost every Iterator function but made a loop using for(new i; i < MAX_PLAYERS; i++) ..
Posts: 716
Threads: 92
Joined: May 2018
Ah my bad then, after 5 hours of scripting i start to see ghosts.
I thought was you who mentioned all iterator functions.
Posts: 140
Threads: 35
Joined: Jul 2017
Quote:
Originally Posted by SyS
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 код:
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 ...
}
|
I currently have it like this, is it wrong?
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]);
}
}
}
}
}
Posts: 140
Threads: 35
Joined: Jul 2017
I really need it. I need to make him only choose the president and the vice president only once. In the countdown, he chooses the president and the vice president at every moment.
CODE:
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]);
}
}
}
}
}
I need to have him only choose the president and the vice president once, and only show the countdown and not the message again. Any idea how to do that?
Posts: 140
Threads: 35
Joined: Jul 2017
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.
Posts: 140
Threads: 35
Joined: Jul 2017
No, I think that where it is, it's fine. Because thanks to the timer he chooses the president and the vice president in the middle of the count.
I tried to do it that way (I have not tried it yet), but I do not know if it will work or it would be a good idea:
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)
{
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);
}
}
}
}
@Y_LESS, help me please, you have experience on this.