Raised This Month: $51 Target: $400
 12% 

Random player/s.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
micke1101
Veteran Member
Join Date: Jan 2008
Location: Banned-town
Old 05-09-2009 , 11:59   Random player/s.
Reply With Quote #1

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).
micke1101 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 05-09-2009 , 12:21   Re: Random player/s.
Reply With Quote #2

It will help you : http://forums.alliedmods.net/showthread.php?t=74666
Arkshine is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 05-09-2009 , 12:25   Re: Random player/s.
Reply With Quote #3

take a look into my deathrun manager
__________________
xPaw is offline
padilha007
Senior Member
Join Date: Jul 2008
Old 05-09-2009 , 12:35   Re: Random player/s.
Reply With Quote #4

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

__________________

padilha007 is offline
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 05-09-2009 , 15:00   Re: Random player/s.
Reply With Quote #5

Quote:
Originally Posted by padilha007 View Post
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.
SnoW is offline
Send a message via MSN to SnoW
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 05-09-2009 , 15:04   Re: Random player/s.
Reply With Quote #6

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;

__________________
xPaw is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 05-09-2009 , 15:05   Re: Random player/s.
Reply With Quote #7

padilha's way is only good if you want 1 player.
If you want random players, see the tutorial that arkshine gave.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 05-09-2009 , 15:17   Re: Random player/s.
Reply With Quote #8

Quote:
Originally Posted by padilha007 View Post
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] View Post
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 

Last edited by SnoW; 05-09-2009 at 15:21.
SnoW is offline
Send a message via MSN to SnoW
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 05-09-2009 , 15:24   Re: Random player/s.
Reply With Quote #9

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;
__________________
hleV is offline
Lee
AlliedModders Donor
Join Date: Feb 2006
Old 05-09-2009 , 15:28   Re: Random player/s.
Reply With Quote #10

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.
__________________
No support via PM.
Lee 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 21:32.


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