Random Player ?
#1

How to give cash, scores, etc to Random Player when player spawn or something else
Reply
#2

pawn Код:
forward RandomMoney();
new Players;
pawn Код:
public OnGameModeInit()
{
    SetTimer("RandomMoney,100000,1); Timer to give the random money
    return 1;
}
pawn Код:
public OnPlayerConnect(playerid)
{
    Players++; // Each time player joins the server
    return 1;
}
pawn Код:
public OnPlayerDisconnect(playerid)
{
    Players--; // Each time player leaves the server
    return 1;
}
pawn Код:
public RandMoney()
{
    GivePlayerMoney(random(Players),50); // Giver random player 50$
}
You can do the same thing with Score.
Reply
#3

EDIT: Too late.

Should have read the above first as now I have to rewrite this. If you want it on player spawn, and just for that player say: he has a 3/10 chance of getting score, money etc when he spawns. Just reply asking in more detail what you want. As I deleted my post.
Reply
#4

Quote:
Originally Posted by Clad
Посмотреть сообщение
pawn Код:
forward RandomMoney();
new Players;
pawn Код:
public OnGameModeInit()
{
    SetTimer("RandomMoney,100000,1); Timer to give the random money
    return 1;
}
pawn Код:
public OnPlayerConnect(playerid)
{
    Players++; // Each time player joins the server
    return 1;
}
pawn Код:
public OnPlayerDisconnect(playerid)
{
    Players--; // Each time player leaves the server
    return 1;
}
pawn Код:
public RandMoney()
{
    GivePlayerMoney(random(Players),50); // Giver random player 50$
}
You can do the same thing with Score.
This way is bad, since player IDs are not sorted.

You can see player IDs are like this: 0, 3, 4, 5, 7, 15, 19, 41.
In the above example, total connected players is : 8
So random ( 8 ) can't return the correct 'random' player ID.

I Have a better way:

pawn Код:
stock RandomPlayer()
{
    new
        ConnectedPlayers[MAX_PLAYERS] = {INVALID_PLAYER_ID, ...},
        idx;
    for(new i = 0; i != MAX_PLAYERS; ++i)
    {
        if(IsPlayerConnected(i))
        {
            ConnectedPlayers[idx] = i;
            idx++;
        }
    }

    if(!idx)
        return INVALID_PLAYER_ID;

    return ConnectedPlayers[random(idx)];
}
Reply
#5

Use Iter_Random.

https://sampforum.blast.hk/showthread.php?tid=92679
Reply
#6

Quote:
Originally Posted by Clad
Посмотреть сообщение
pawn Код:
forward RandomMoney();
new Players;
pawn Код:
public OnGameModeInit()
{
    SetTimer("RandomMoney,100000,1); Timer to give the random money
    return 1;
}
pawn Код:
public OnPlayerConnect(playerid)
{
    Players++; // Each time player joins the server
    return 1;
}
pawn Код:
public OnPlayerDisconnect(playerid)
{
    Players--; // Each time player leaves the server
    return 1;
}
pawn Код:
public RandMoney()
{
    GivePlayerMoney(random(Players),50); // Giver random player 50$
}
You can do the same thing with Score.
Thanks for your help..
Reply
#7

Quote:
Originally Posted by iFarbod
Посмотреть сообщение
This way is bad, since player IDs are not sorted.

You can see player IDs are like this: 0, 3, 4, 5, 7, 15, 19, 41.
In the above example, total connected players is : 8
So random ( 8 ) can't return the correct 'random' player ID.

I Have a better way:

pawn Код:
stock RandomPlayer()
{
    new
        ConnectedPlayers[MAX_PLAYERS] = {INVALID_PLAYER_ID, ...},
        idx;
    for(new i = 0; i != MAX_PLAYERS; ++i)
    {
        if(IsPlayerConnected(i))
        {
            ConnectedPlayers[idx] = i;
            idx++;
        }
    }

    if(!idx)
        return INVALID_PLAYER_ID;

    return ConnectedPlayers[random(idx)];
}
How use this any example ?
Reply
#8

pawn Код:
public RandMoney()
{
    GivePlayerMoney(RandomPlayer(), 50); // Giver random player 50$
}
Reply
#9

Quote:
Originally Posted by Venice
Посмотреть сообщение
Thanks for your help..
Didn't work ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)