AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Get a Random Dead Player Who is Not Admin (https://forums.alliedmods.net/showthread.php?t=89148)

Mlk27 04-02-2009 20:17

Get a Random Dead Player Who is Not Admin
 
Solved: How to get a random dead player?

Another question: #9
Get a randomly picked dead player who has no admin ban flag?

Exolent[jNr] 04-02-2009 20:24

Re: Get a Random Dead Players
 
Code:
new players[32], pnum; get_players(players, pnum, "b"); new randplayers[32], randcount; for( new i = random(pnum); i < pnum; i = random(pnum) ) {     randplayers[randcount++] = players[i];         for( new j = i; j < pnum; j++ )     {         if( (j + 1) == pnum )         {             players[j] = 0;         }         else         {             players[j] = players[j + 1];         }     }         pnum--; }

alan_el_more 04-02-2009 20:24

Re: Get a Random Dead Players
 
try this

PHP Code:

fnGetRandomdead(n)
{
    static 
ideadid
    idead 
0
    
    
for (id 1id <= 32id++)
    {
        if (!
is_user_alive(id))
            
idead++
        
        if (
idead == n)
            return 
id;
    }
    
    return -
1;



Arkshine 04-02-2009 20:25

Re: Get a Random Dead Players
 
Retrieve a list of dead players ( using get_players() with "bh" as flags, or using a loop with for() + a check is_user_alive() ), then pick up a player randomly with random().

Basicaly :

Code:
new Players[32]; new Num; new RandomDeadPlayer ; get_players( Players, Num, "bh" ); RandomDeadPlayer = random( Num );

or

Code:
new MaxClients = get_maxplayers(); new RandomDeadPlayer ; new Num; for( new id = 1; id <= MaxClients; id++ ) {      if ( !is_user_alive( id ) ) { Num++; } } RandomDeadPlayer = random( Num );


[Edit] Ah. You say players not a player.

Mlk27 04-02-2009 20:44

Re: Get a Random Dead Player
 
arkshine you sure about that? cause both codes seem to only return a random number from total numbers of dead players


Im trying to randomly pick a player from all dead players

Exolent[jNr] 04-02-2009 20:45

Re: Get a Random Dead Players
 
Then use this:

Quote:

Originally Posted by arkshine (Post 795863)
Code:
new Players[32]; new Num; new RandomDeadPlayer ; get_players( Players, Num, "bh" ); RandomDeadPlayer = players[ random( Num ) ];


Mlk27 04-02-2009 20:50

Re: Get a Random Dead Player
 
oh okay. that will return the player index of a randomly picked dead player?

Arkshine 04-02-2009 20:58

Re: Get a Random Dead Player
 
Yes.

Mlk27 04-03-2009 01:53

Re: Get a Random Dead Player
 
I have another question..what if I want to get a randomly picked dead player who has no admin ban flag?

Dores 04-03-2009 05:15

Re: Get a Random Dead Player Who is Not Admin
 
Something like this:

PHP Code:

new Players[32];
new 
Num;
new 
RandomDeadPlayerWithoutBanFlag;
get_playersPlayersNum"bh" );

new 
idj;
for(new 
Num i++)
{    
    if(
access(Players[i], ADMIN_BAN))
    {
        
// I finally understand why you do it, Exolent! :D
        
for(Num j++)
        {
            if(
Num == 1)
            {
                
Players[j] = 0;
            }
            
            else
            {
                
Players[j] = Players[1];
            }
        }
        
        
Num--;
    }
}

if(
Num)
{
    
RandomDeadPlayerWithoutBanFlag playersrandomNum ) ];




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

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