Raised This Month: $ Target: $400
 0% 

pick 6 ready players


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
orel56000
Member
Join Date: Apr 2015
Old 01-03-2019 , 16:03   pick 6 ready players
Reply With Quote #1

I have a var ReadyPlayer[id] = 0/1

What is the best way to pick 6 random of all of the ready players?
orel56000 is offline
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 01-03-2019 , 16:15   Re: pick 6 ready players
Reply With Quote #2

#define MAXPLAYERS 32

...

ReadyPlayer[random_num(0, MAXPLAYERS)]
redivcram is offline
orel56000
Member
Join Date: Apr 2015
Old 01-03-2019 , 16:18   Re: pick 6 ready players
Reply With Quote #3

Quote:
Originally Posted by redivcram View Post
#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)
orel56000 is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 01-03-2019 , 16:24   Re: pick 6 ready players
Reply With Quote #4

https://forums.alliedmods.net/showpo...36&postcount=4
__________________








CrazY. is offline
orel56000
Member
Join Date: Apr 2015
Old 01-03-2019 , 16:53   Re: pick 6 ready players
Reply With Quote #5

Quote:
Originally Posted by CrazY. View Post
how do I pick 6 different players?

Last edited by orel56000; 01-03-2019 at 16:53.
orel56000 is offline
Xalus
Veteran Member
Join Date: Dec 2009
Location: Belgium
Old 01-04-2019 , 11:04   Re: pick 6 ready players
Reply With Quote #6

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

__________________
Retired.

Last edited by Xalus; 01-04-2019 at 11:16.
Xalus is offline
thEsp
BANNED
Join Date: Aug 2017
Old 01-04-2019 , 13:53   Re: pick 6 ready players
Reply With Quote #7

Quote:
Originally Posted by redivcram View Post
#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.
thEsp is offline
shauli
Member
Join Date: Jun 2018
Old 01-04-2019 , 17:40   Re: pick 6 ready players
Reply With Quote #8

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);


Last edited by shauli; 01-04-2019 at 17:40.
shauli is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:22.


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