AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   pick 6 ready players (https://forums.alliedmods.net/showthread.php?t=313278)

orel56000 01-03-2019 16:03

pick 6 ready players
 
I have a var ReadyPlayer[id] = 0/1

What is the best way to pick 6 random of all of the ready players?

redivcram 01-03-2019 16:15

Re: pick 6 ready players
 
#define MAXPLAYERS 32

...

ReadyPlayer[random_num(0, MAXPLAYERS)]

orel56000 01-03-2019 16:18

Re: pick 6 ready players
 
Quote:

Originally Posted by redivcram (Post 2632657)
#define MAXPLAYERS 32

...

ReadyPlayer[random_num(0, MAXPLAYERS)]

that not what I meant, I know who's ready and who's not, I just need a random that returns me 6 players from all those that are ready (ReadyPlayer[id] == 1)

CrazY. 01-03-2019 16:24

Re: pick 6 ready players
 
https://forums.alliedmods.net/showpo...36&postcount=4

orel56000 01-03-2019 16:53

Re: pick 6 ready players
 
Quote:

Originally Posted by CrazY. (Post 2632662)

how do I pick 6 different players?

Xalus 01-04-2019 11:04

Re: pick 6 ready players
 
Try this:

PHP Code:

new ready_list[7]
log_amx("Found %i players"get_randomplayers(ready_listcharsmax(ready_list)))


get_randomplayers(player_list[], player_amount)
{
    new 
server_playerlist[32], server_playernum
    get_players
(server_playerlistserver_playernum"a")

    new Array:
array_playerlist ArrayCreate()
    for(new 
0server_playernumi++)
    {
        if(
ReadyPlayerserver_playerlist[i] ])
        {
            
ArrayPushCell(array_playerlisti)
        }
    }

    new 
playerlist_found 0,
        
playerlist_index

    
while( (ArraySize(array_playerlist) && player_amount playerlist_found) )
    {
        
playerlist_index random(ArraySize(array_playerlist))

        
player_listplayerlist_found ] = ArrayGetCell(array_playerlistplayerlist_index)
        
ArrayDeleteItem(array_playerlistplayerlist_index)

        
playerlist_found += 1
    
}
    
ArrayDestroy(array_playerlist)

    return 
playerlist_found



thEsp 01-04-2019 13:53

Re: pick 6 ready players
 
Quote:

Originally Posted by redivcram (Post 2632657)
#define MAXPLAYERS 32

...

ReadyPlayer[random_num(0, MAXPLAYERS)]

Best way to do this is by using playersnumber rather than maxplayers. In this case, the number returned is valid index/player.

shauli 01-04-2019 17:40

Re: pick 6 ready players
 
AMXX 1.8.3:
PHP Code:

public test()
{
    new 
players[6], ret;
    
ret getRandom(playerssizeof players);

    
//ret = amount of players returned (maybe lower than 6 if not enough are ready)
}

getRandom(players[], cnt)
{
    new 
copy_cntcopy[sizeof ReadyPlayer];

    for(new 
0sizeof copyi++)
    {
        if(
ReadyPlayer[i])
           
copy[copy_cnt++] = i;
    }

    
SortIntegers(copycopy_cntSort_Random);
    
copy_cnt min(copy_cntcnt);

    for(new 
0copy_cnti++)
        
players[i] = copy[i];
    
    return 
copy_cnt;


If AMXX < 1.8.3, replace SortIntegers with this:
PHP Code:

SortCustom1D(copycopy_cnt"sortRandom");

public 
sortRandom()
{
    return 
random_num(-11);




All times are GMT -4. The time now is 07:39.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.