09.09.2016, 12:58
Hi, I'm starting to use foreach. But I do not understand how to select a player so random, that is on the same team (GetPlayerTeam).
Is there an example?
Is there an example?
if(strcmp(cmd, "/mission", true) == 0)
{
for(new i = 0; i < MAX_PLAYERS; ++i) {
if(IsPlayerConnected(i)) {
new RRandom = random(i);
}
}
new name[MAX_PLAYER_NAME];
GetPlayerName(RRandom, name, sizeof(name));
format(coordsstring, sizeof(coordsstring), "Player name is %s %i", name, RRandom);
SendClientMessage(playerid, COLOR_WHITE,coordsstring);
return 0x01;
}
new playerteam = GetPlayerTeam(playerid),
teamarray[MAX_PLAYERS],
index;
foreach(Player, targetid)
{
if(GetPlayerTeam(targetid) == playerteam)
{
teamarray[index] = targetid;
index++;
}
}
new randomtarget = teamarray[random(index)]; // this variable now stores the random player.
foreach(new targetid:Player)
Iter_Random(GroupPlayers[GroupOfPlayersOnYourTeam]);
|
TORKQ: That's really old foreach syntax, you'll get deprecated warning. So:
pawn Code:
OP: You can go a step further, using y_groups it'd be as easy as pawn Code:
|