Raised This Month: $ Target: $400
 0% 

Get a Random Dead Player Who is Not Admin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mlk27
Veteran Member
Join Date: May 2008
Old 04-02-2009 , 20:17   Get a Random Dead Player Who is Not Admin
Reply With Quote #1

Solved: How to get a random dead player?

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

Last edited by Mlk27; 04-03-2009 at 04:26. Reason: Fixed topic title
Mlk27 is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-02-2009 , 20:24   Re: Get a Random Dead Players
Reply With Quote #2

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--; }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
alan_el_more
Veteran Member
Join Date: Jul 2008
Location: amxmodx-es.com
Old 04-02-2009 , 20:24   Re: Get a Random Dead Players
Reply With Quote #3

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;

__________________
alan_el_more is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-02-2009 , 20:25   Re: Get a Random Dead Players
Reply With Quote #4

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.
Arkshine is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-02-2009 , 20:45   Re: Get a Random Dead Players
Reply With Quote #5

Then use this:

Quote:
Originally Posted by arkshine View Post
Code:
new Players[32]; new Num; new RandomDeadPlayer ; get_players( Players, Num, "bh" ); RandomDeadPlayer = players[ random( Num ) ];
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Mlk27
Veteran Member
Join Date: May 2008
Old 04-02-2009 , 20:44   Re: Get a Random Dead Player
Reply With Quote #6

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
Mlk27 is offline
Mlk27
Veteran Member
Join Date: May 2008
Old 04-02-2009 , 20:50   Re: Get a Random Dead Player
Reply With Quote #7

oh okay. that will return the player index of a randomly picked dead player?
Mlk27 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-02-2009 , 20:58   Re: Get a Random Dead Player
Reply With Quote #8

Yes.
Arkshine is offline
Mlk27
Veteran Member
Join Date: May 2008
Old 04-03-2009 , 01:53   Re: Get a Random Dead Player
Reply With Quote #9

I have another question..what if I want to get a randomly picked dead player who has no admin ban flag?
Mlk27 is offline
Dores
Veteran Member
Join Date: Jun 2008
Location: You really don't wanna k
Old 04-03-2009 , 05:15   Re: Get a Random Dead Player Who is Not Admin
Reply With Quote #10

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

__________________
O o
/Ż________________________
| IMMA FIRIN' MAH LAZOR!!!
\_ŻŻŻ
Dores 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:16.


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