Get random players
#1

Hello i want to make command that will display random player name who is online, can i have any help with this ?
Reply
#2

Your best bet would be to make use of the 'random' function. A few examples of how it can be used:
pawn Код:
new i = random(10); // would store a random integer between 0 - 10 into the i variable
pawn Код:
if(random(5) == 1) // would give a 1 in 5 chance of passing the IF statement
For further information, check the wiki entry here: https://sampwiki.blast.hk/wiki/Random
Reply
#3

Yes i know how to make simple random function like:
pawn Код:
new screenie = random(13);
    if(screenie == 1)
    {
        SetPlayerPos(playerid, 720.4771,-1744.3759,7.3889);
        SetPlayerCameraPos(playerid, 693.2117,-1794.4960,53.9965);
        SetPlayerCameraLookAt(playerid, 767.3105,-1609.9528,17.4037);
    }
    else if( screenie == 2)
    {
        SetPlayerPos(playerid, 2246.4504,-1705.5930,22.8527);
        SetPlayerCameraPos(playerid, 2227.4084,-1715.7412,49.0753);
        SetPlayerCameraLookAt(playerid, 2261.9358,-1772.0881,13.5469);
    }
    else if( screenie == 3)
    {
I bet you didnt even read my question.
Reply
#4

Ok i found similiar function on GF /lotto comand will use it then
Reply
#5

I'm extremely offended that you have responded in such a manner, I find it to be very rude.

Your initial request for help is very vague; exactly what bits do you need help with? How do you want the name to be displayed? Textdraw, ClientMessage, 3DTextLabel? Do you want the code writing for you, or do you just want pointing in the right direction? Understand that I have no way of knowing what level of coding you are at.

EDIT: too late, nevermind then.
Reply
#6

Benjo im sorry. Im just hard working on my script and i didnt solve my problem, i needed just randomly select some player and show me his name in any way
pawn Код:
format(string, sizeof(string), "* %s .",RANDOM PLAYER NAME);
SendClientMessage(i, COLOR_YELLOW, string);
Reply
#7

pawn Код:
new OnlineID[MAX_SERVER_SLOTS],Add; // replace MAX_SERVER_SLOTS
for(new d,g=GetMaxPlayers(); d < g; d++)
    if(IsPlayerConnected(d))
    {
        OnlineID[Add] = d;
        Add++;
    }
new RandomID = OnlineID[random(Add)];
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)