SA-MP Forums Archive
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=188307)



Random player - marinov - 07.11.2010

How do I make choose a random player and move it to another team ? or a team balance kinda thing ?


Re: Random player - marinov - 07.11.2010

anyone ?


Re: Random player - Kwarde - 07.11.2010

pawn Code:
new randomp;
randomp = random(MAX_PLAYERS);
gTeam[randomp] = TEAM; //Change this to your variables
SpawnPlayer(randomp);
Add this somewhere in your script. I don't know if this is working, I just made it :P
Try it ouy


Re: Random player - legodude - 07.11.2010

NO!

max players is 500.
i dont think you run a server with 500 players (do you?)
Code:
new randomp;
randomp = random(GetMaxPlayers());
gTeam[randomp] = TEAM; //Change this to your variables
SpawnPlayer(randomp);
GetMaxPlayers will read in config.cfg what you have set there.


Re: Random player - Kwarde - 07.11.2010

Yeah I didn't think: On this way you have fast an invalid player. Try this :P (3 time's is the charm)

pawn Code:
new RandomP;
RandomP = random(GetMaxPlayers());
if(!IsPlayerConnected(RandomP)) return false;
gTeam[RandomP] = team; //Change to your variables
SpawnPlayer(RandomP);



Re: Random player - iggy1 - 07.11.2010

Just in case you use foreach theres a nice random player function that comes with it.
pawn Code:
new randomplayer = Iter_Random(Player);



Re: Random player - (SF)Noobanatior - 07.11.2010

untested but i would go like this
pawn Code:
public GetRandomPlayer(){          //returns random playerid or -1 if no players
    new test,test2,players[MAX_PLAYERS];
    for(new i=0;i<MAX_PLAYERS;i++){
        if(IsPlayerConnected(i)){
            players[test] = i;
            test++;
        }
    }
    if(test == 0)return -1;
    else test2 = random(test);
    return players[test2];
}
fine dont think it makes much difference however -1 it is


Re: Random player - iggy1 - 07.11.2010

But 0 is a playerid i think it would be safer returning -1 if no players are found. Na won't make much difference just thought i'd point it out. Most of the time there probably would have to be a player online to use the function (unless timers).