Random team choose - 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 team choose (
/showthread.php?tid=243142)
Random team choose -
Typhome - 21.03.2011
Hello.
I want make one gamemode, but.. i need build this random teamplayer chooser.
Like...
gTeam[playerid] = 2; (<-- BLUE TEAM)
System will choose (random) one player FROM BLUE TEAM and
makes player to VIP.
How do make this random chooser? Thanks.
// I have already searched, still didn't found.
Re: Random team choose -
iJumbo - 21.03.2011
pawn Код:
stock GetRandomPlayer()
{
new players = 0;
for(new i = 0; i < GetMaxPlayers(); i++)
{
if(IsPlayerConnected(i)) players ++;
}
players = random(players) + 1;
for(new i = 0; i < GetMaxPlayers(); i ++)
{
if(IsPlayerConnected(i))
{
players --;
if(players == 0) return i;
}
}
return 0;
}
??
Re: Random team choose -
Sascha - 21.03.2011
hm maybe kind of this:
pawn Код:
stock RandomPlayer()
{
new count = 0;
for(new i=0; i<GetMaxPlayers(); i++)
{
if(IsPlayerConnected(i))
{
if(gTeam[i] == 2)
{
count++;
}
}
}
if(count != 0)
{
new rst = random(count);
new count2;
for(new n=0; n<GetMaxPlayers(); n++)
{
if(IsPlayerConnected(n))
{
if(gTeam[n] == 2)
{
count2++;
if(count2 == rst)
{
return n;
}
}
}
}
}
return -1;
}
no clue whether it works though, just wrote it up
edit: oh one before me
Re: Random team choose -
Typhome - 21.03.2011
Quote:
Originally Posted by [ISS]jumbo
pawn Код:
stock GetRandomPlayer() { new players = 0; for(new i = 0; i < GetMaxPlayers(); i++) { if(IsPlayerConnected(i)) players ++; } players = random(players) + 1; for(new i = 0; i < GetMaxPlayers(); i ++) { if(IsPlayerConnected(i)) { players --; if(players == 0) return i; } } return 0; }
??
|
Where is
gTeam[playerid] == 2?
Quote:
Originally Posted by Typhome
Like... gTeam[playerid] = 2; (<-- BLUE TEAM)
System will choose (random) one player FROM BLUE TEAM and makes player to VIP.
|
Re: Random team choose -
iJumbo - 21.03.2011
you have 2 use GetRandomPlayer function in your script
Re: Random team choose -
Typhome - 21.03.2011
You cant really understand..
SYSTEM MUST CHOOSE PLAYER FROM BLUE TEAM.
Re: Random team choose -
iJumbo - 21.03.2011
like mmm
pawn Код:
public SetRandomPlayerToBlueTeam()
{
new randomp,name[MAX_PLAYER_NAME],string[128];
randomp = GetRandomPlayer();
gTeam[randomp] = 2;
GetPlayerName(randomp,name,sizeof(name));
format(string,sizeof(string),"%s is now blue team",name);
SendClientMessageToAll(color,string);
return 1;
}
idk if can work
Re: Random team choose -
iJumbo - 21.03.2011
Quote:
SYSTEM MUST CHOOSE PLAYER FROM BLUE TEAM.
|
AHHHHHHHHHH LOOOOL xD mmmm try modify the GetRandomPlayer