AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Random player/s. (https://forums.alliedmods.net/showthread.php?t=92049)

micke1101 05-09-2009 11:59

Random player/s.
 
Hi.

I was wondering if anyone knew a tutorial (cause i cant find one) or could show a script that chooses a random (or more) player(s) at new round (of course reseted at round end).

Arkshine 05-09-2009 12:21

Re: Random player/s.
 
It will help you : http://forums.alliedmods.net/showthread.php?t=74666

xPaw 05-09-2009 12:25

Re: Random player/s.
 
take a look into my deathrun manager :)

padilha007 05-09-2009 12:35

Re: Random player/s.
 
PHP Code:

#include <amxmodx>
#include <fakemeta>

public plugin_init()
{
    
register_plugin("Random Player""0.1""padilha007")
    
register_logevent("random_player"2"1=Round_Start")
}

public 
random_player()
{
    new 
players[32], totalplayersrandplayer;
    
get_players(playerstotalplayers)

    if (!
randplayer)
        
randplayer random_num(1totalplayers)

    if(!
is_user_connected(randplayer) || !is_user_alive(randplayer))
    {
        
set_task(0.1"random_player")
        return 
PLUGIN_HANDLED
     
}


    
// You stuff with randplayer
    // index = randplayer



SnoW 05-09-2009 15:00

Re: Random player/s.
 
Quote:

Originally Posted by padilha007 (Post 824198)
PHP Code:

//...
public random_player()
{
    new 
players[32], totalplayersrandplayer;
    
get_players(playerstotalplayers)
 
    if (!
randplayer)
        
randplayer random_num(1totalplayers)
   
//....



randplayer is always false, don't understand why are you checking it.
Also that's just a bad way.

xPaw 05-09-2009 15:04

Re: Random player/s.
 
PHP Code:

new bool:g_Randromized;

public 
random_FFS() {
    if( 
g_Randromized )
        return 
PLUGIN_CONTINUE;
    
    
g_Randromized true;
    
    new 
iPlayersindexArray[32];
    
    for( new 
1<= g_Maxplayersi++ ) {
        if( 
is_user_connected(i) ) {
            
indexArray[iPlayers] = i;
            
iPlayers++;
        }
    }
    
    if( 
iPlayers <= )
        return 
PLUGIN_CONTINUE;
    
    new 
ID indexArray[random_num(0iPlayers 1)];
    
    if( 
cs_get_user_team(ID) == CS_TEAM_CT || cs_get_user_team(ID) == CS_TEAM_T ) {
        
// ID is random player
    
} else {
        
g_Randromized false;
        
random_FFS();
    }
    
    return 
PLUGIN_CONTINUE;



Exolent[jNr] 05-09-2009 15:05

Re: Random player/s.
 
padilha's way is only good if you want 1 player.
If you want random players, see the tutorial that arkshine gave.

SnoW 05-09-2009 15:17

Re: Random player/s.
 
Quote:

Originally Posted by padilha007 (Post 824198)
PHP Code:

#include <amxmodx>
#include <fakemeta>
 
public plugin_init()
{
    
register_plugin("Random Player""0.1""padilha007")
    
register_logevent("random_player"2"1=Round_Start")
}
 
public 
random_player()
{
    new 
players[32], totalplayersrandplayer;
    
get_players(playerstotalplayers)
 
    if (!
randplayer)
        
randplayer random_num(1totalplayers)
 
    if(!
is_user_connected(randplayer) || !is_user_alive(randplayer))
    {
        
set_task(0.1"random_player")
        return 
PLUGIN_HANDLED
     
}
 
 
    
// You stuff with randplayer
    // index = randplayer



Quote:

Originally Posted by Exolent[jNr] (Post 824343)
padilha's way is only good if you want 1 player.
If you want random players, see the tutorial that arkshine gave.

Good? No it isn't. It's not efficient and can take even 3 secs. Also the connected check isn't needed. And it's getting maxplayers many times even it isn't needed.
PHP Code:

new players[32], totalplayersrandplayer;
get_players(playerstotalplayers"a");
randplayer random_num(1totalplayers);
//player index is randplayer 


hleV 05-09-2009 15:24

Re: Random player/s.
 
Code:
#include <amxmodx>   new g_iRandomCl;   public plugin_init() {         register_event("HLTV", "eventHLTV", "a", "1=0", "2=0");         register_logevent("eventRoundEnd", 2, "1=Round_End"); }   public eventHLTV() {         new iPlrsNum = get_playersnum();           if (iPlrsNum)                 g_iRandomCl = random_num(1, iPlrsNum); }   public eventRoundEnd()         g_iRandomCl = 0;

Lee 05-09-2009 15:28

Re: Random player/s.
 
I don't know why you guys are using set_task() and recursion when a simple while loop would be more efficient.

hleV, do you not see the problem with that? Since player indexes aren't necessarily consecutive, you're far from guaranteed to hit a connected player.


All times are GMT -4. The time now is 23:09.

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