Random player - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Random player (
/showthread.php?tid=249450)
Random player -
Amine_Mejrhirrou - 18.04.2011
ok i have a question ... how can i make a
random player change team i
f all the players are in the same team !
i mean if all the player are in the same team : change a random player to an other team
Re: Random player -
admantis - 18.04.2011
pawn Code:
stock ChooseRandomPlayer() // Function by Admantis
{
new TMP, TOTAL; // Creates TMP and TOTAL
for(new I = 0; I < MAX_PLAYERS; I++) // Player loop
{
if (IsPlayerConnected(I)) { TMP += 1; } // If player is connected, count is increased
}
TOTAL = random(TMP); // TOTAL is equal of the random of online players
return TOTAL; // Returning a value (TOTAL)
}
Example:
pawn Code:
gTeam[ChooseRandomPlayer()] = 1;
SetPlayerTeam(ChooseRandomPlayer(), 1);
Re : Random player -
Amine_Mejrhirrou - 18.04.2011
what's about chйking if all the online players are in the same team ?
Re: Random player -
admantis - 18.04.2011
pawn Code:
stock GetPlayersInTeam(team_id)
{
new COUNT;
for(new I = 0; I < MAX_PLAYERS; I++)
{
if (IsPlayerConnected(I))
{
if (GetPlayerTeam(I) == team_id) { COUNT += 1; }
}
}
return COUNT;
}
Is this what you mean?
Re : Random player -
Amine_Mejrhirrou - 18.04.2011
Code:
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i) && (GetPlayerTeam(i)!= 2))
{
SetPlayerTeam(ChooseRandomPlayer(), 2)
}
}
is this corйct ?
is this will chang a random player to team 2 if all the players are in team 2 ?