Raised This Month: $ Target: $400
 0% 

problem with random player script


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
12345
Senior Member
Join Date: Dec 2004
Old 08-15-2008 , 20:03   problem with random player script
Reply With Quote #1

i get this plugin to get 4 players on restart round, but get all players.

tnx for advanced

PHP Code:
#include <amxmodx>
#include <amxmisc>

public plugin_init() {
register_plugin("AMX Armas""1.1.1""Yokil SpyWare")
register_event("ResetHUD""newround""b")
register_cvar("amx_random","0");
return 
PLUGIN_CONTINUE
}

public 
newround(id)
{
new 
name[3]
new 
iArray[3];
get_user_nameid name 31 );
 
client_print(iArray[0], print_chat"Tudo bem, tudo esta funcionando %s, veja se todos falaram. 4 pessoas!"name);
}


stock get_random_players(const iArray[3])
{
*new 
iPlayers[3], iNum;
*
get_players(iPlayersiNum"ch");
*
*for(new 
i++)
*{
iArray[i] = iPlayers[random(iNum)];
*}

12345 is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-15-2008 , 21:23   Re: problem with random player script
Reply With Quote #2

Try this function:

Code:
get_random_players(players[], total, flags[]="a", team[]="") {     new temp_players[32], pnum;     get_players(temp_players, pnum, flags, team);         new retrieve = min(pnum, total);         new i, rand, j;     for(i = 0; i < retrieve; i++ )     {         rand = random(pnum);                 players[i] = temp_players[rand];                 for( j = rand; j < pnum; j++ )         {             if( (j + 1) == pnum )             {                 temp_players[j] = 0;             }             else             {                 temp_players[j] = temp_players[j + 1];             }         }                 pnum--;     }         return i; }

Usage:

To get 5 alive players:
Code:
new players[32]; new pnum = get_random_players(players, 5, "a");

To get 5 CT players:
Code:
new players[32]; new pnum = get_random_players(players, 5, "e", "CT");

Notice how the flags and team work just like the get_players() function.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!

Last edited by Exolent[jNr]; 08-17-2008 at 18:21.
Exolent[jNr] is offline
12345
Senior Member
Join Date: Dec 2004
Old 08-16-2008 , 06:16   Re: problem with random player script
Reply With Quote #3

i can get her name?
12345 is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-16-2008 , 13:58   Re: problem with random player script
Reply With Quote #4

Code:
new players[5]; // lets get 5 people new pnum = get_random_players(players, 5); new name[32]; for( new i = 0; i < pnum; i++ ) {     get_user_name(players[i], name, 31);     client_print(0, print_chat, "Player %2i. %s", i + 1, name); }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
12345
Senior Member
Join Date: Dec 2004
Old 08-17-2008 , 17:17   Re: problem with random player script
Reply With Quote #5

i get this error:

random2.sma(50) :error 017: undefined symbol "i"

PHP Code:
#include <amxmodx>
#include <amxmisc>

public plugin_init() {
register_plugin("AMX Armas""1.1.1""Yokil SpyWare")
register_clcmd("say /ver","show" )
return 
PLUGIN_CONTINUE
}

public 
show(id) {
new 
players[4]; // lets get 5 people
new pnum get_random_players(players4);

new 
name[32];
for( new 
0pnumi++ )
{
    
get_user_name(players[i], name31);
    
client_print(idprint_chat"Player %2i. %s"1name);
}
}

get_random_players(players[], totalflags[]="a"team[]="")
{
    new 
temp_players[32], pnum;
    
get_players(temp_playerspnumflagsteam);
    
    new 
retrieve min(pnumtotal);
    
    new 
randj;
    for( new 
0retrievei++ )
    {
        
rand random(pnum);
        
        
players[total++] = temp_players[rand];
        
        for( 
randpnumj++ )
        {
            if( (
1) == pnum )
            {
                
temp_players[j] = 0;
            }
            else
            {
                
temp_players[j] = temp_players[1];
            }
        }
        
        
pnum--;
    }
    return 
i;

i make my modification:

PHP Code:
#include <amxmodx>
#include <amxmisc>

public plugin_init() {
register_plugin("AMX Armas""1.1.1""Yokil SpyWare")
register_clcmd("say /ver","show" )
return 
PLUGIN_CONTINUE
}

public 
show(id) {
new 
players[4]; // lets get 5 people
new pnum get_random_players(players4);

new 
name[32];
for( new 
0pnumi++ )
{
    
get_user_name(players[i], name31);
    
client_print(idprint_chat"Player %2i. %s"1name);
}
}

get_random_players(players[], totalflags[]="a"team[]="")
{
    new 
temp_players[32], pnum;
    
get_players(temp_playerspnumflagsteam);
    
    new 
retrieve min(pnumtotal);
    
    new 
randj;
    for( new 
0retrievei++ )
    {
        
rand random(pnum);
        
        
players[total++] = temp_players[rand];
        
        for( 
randpnumj++ )
        {
            if( (
1) == pnum )
            {
                
temp_players[j] = 0;
            }
            else
            {
                
temp_players[j] = temp_players[1];
            }
        }
        
        
pnum--;
    }
    new 
i
    
return i;

PHP Code:
new 
work, but if i say /ver to exec random player show this in chat:

player 1. Counter-Strike
player 2. Counter-Strike
player 3. Counter-Strike
player 4. Counter-Strike
player 5. Counter-Strike

dont show a name, can help?

Last edited by 12345; 08-17-2008 at 17:21.
12345 is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-17-2008 , 18:19   Re: problem with random player script
Reply With Quote #6

I fixed my code error. And I highlighted the lines I changed.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
12345
Senior Member
Join Date: Dec 2004
Old 08-18-2008 , 11:58   Re: problem with random player script
Reply With Quote #7

work, tnx +karma
12345 is offline
Reply


Thread Tools
Display Modes

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


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