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

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
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 05-09-2009 , 15:05   Re: Random player/s.
Reply With Quote #6

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
padilha007
Senior Member
Join Date: Jul 2008
Old 05-09-2009 , 17:34   Re: Random player/s.
Reply With Quote #7

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.

@SnoW

try use my code before say anything
__________________

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

Quote:
Originally Posted by padilha007 View Post
@SnoW

try use my code before say anything
And why I should do that? I already said the problems that it had and attached a code which is five times better than yours. I don't need to test it since I see from the code that it isn't efficient at all.
SnoW is offline
Send a message via MSN to SnoW
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 05-09-2009 , 15:17   Re: Random player/s.
Reply With Quote #9

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
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 05-09-2009 , 15:04   Re: Random player/s.
Reply With Quote #10

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
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 00:06.


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