Random player select - 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 select (
/showthread.php?tid=261708)
Random player select -
VoViNaToR - 14.06.2011
Hello can someone help me with this command.
It should randomly select player who is online and display it.
pawn Code:
if(strcmp(cmd, "/mission", true) == 0)
{
format(coordsstring, sizeof(coordsstring), "Player name is %s", RANDOM PLAYER NAME);
SendClientMessage(playerid, COLOR_WHITE,coordsstring);
return 1;
}
Its like type some command and it says : you should kill (playername)
Re: Random player select -
Mauzen - 14.06.2011
Getting a random player was already made lots of times here in the forum. I know the search isnt the best all the time, but you could try to find it.
Re: Random player select -
VoViNaToR - 14.06.2011
Ok thanks
Re: Random player select -
WooTFTW - 14.06.2011
https://sampforum.blast.hk/showthread.php?tid=259885
Re: Random player select -
Ricop522 - 14.06.2011
I make this righ now
pawn Code:
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;
}
Re: Random player select -
Benjo - 14.06.2011
Hello again.
I would do something like this:
pawn Code:
if(strcmp(cmd, "/mission", true) == 0)
{
new onlineids[MAX_PLAYERS]; // to store all online playerids
new playersonline; // to store the amount of current online players
new pname[16]; // to store the chosen player's name
for(new i=0; i<MAX_PLAYERS; i++) // loop through max amount of players (hopefully redefined from default!)
{
if(IsPlayerConnected(i)) // check to see if current id in the loop is connected
{
onlineids[playersonline] = i; // store the current id into the onlineids variable
playersonline++; // increase the playersonline by 1
}
}
GetPlayerName(onlineids[random(playersonline)], pname, sizeof(pname)); // use the random function to randomly select a store online id
format(pname, sizeof(pname), "Player name is %s", pname);
SendClientMessage(playerid, COLOR_WHITE, pname);
return 1;
}
EDIT: ninja'd big time
Re: Random player select -
VoViNaToR - 14.06.2011
Super! Thanks you guys, I Love you