Raised This Month: $32 Target: $400
 8% 

[SOLVED]Random a player in a team .


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
5c0r-|3i0
Veteran Member
Join Date: Nov 2008
Location: Việt Nam
Old 04-28-2010 , 11:11   [SOLVED]Random a player in a team .
Reply With Quote #1

I want to choose randomly a player from a team.....Then.....do something with him..( give him ammo , weapon , health , armor....) ......
......Thanks in advance..
__________________

Last edited by 5c0r-|3i0; 04-28-2010 at 20:03.
5c0r-|3i0 is offline
S34Qu4K3
Veteran Member
Join Date: Jan 2010
Location: Galicia
Old 04-28-2010 , 11:21   Re: [CS 1.6]Random a player in a team .
Reply With Quote #2

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

#define PLUGIN "Random X"
#define VERSION "1.0"
#define AUTHOR "L//"


public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_event("HLTV""event_startround""a",    "1=0""2=0")
}

// Delay despues del start round
public event_startround() set_task(1.0"random_x")

public 
random_x()
{
    new 
indexnumxiplayers[32]

    
get_players(playersnum)

    
index random_num(0num 1)
    
    for(
index 1; ; x++)
    {    
        if(
>= num0
        
        i 
players[x]
        
        
// Condiciones
        
if(is_user_connected(i))
        {
            
// Setear X cosa a 'i'
            
            
break;
        }

        if(
== index) break;
    }

Code by //L ;)
</span></span>
__________________

- ASM2SMA: Experimental AMXX Assembly encoder

- Defuse Bar Fix

Quote:
Originally Posted by Arkshine
I DON'T WANT TO SEE NOOOOOOOOOOOOOOO AHHHHH. MY EYES ARE ALREADY HURT.
S34Qu4K3 is offline
tuty
Veteran Member
Join Date: Jul 2008
Location: UK
Old 04-28-2010 , 13:46   Re: [CS 1.6]Random a player in a team .
Reply With Quote #3

you should check if players is bot or hltv.. with flags "ch" on get_players.. you should skip dead players with other flag....^^
__________________
tuty is offline
Send a message via ICQ to tuty Send a message via AIM to tuty
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-28-2010 , 17:04   Re: [CS 1.6]Random a player in a team .
Reply With Quote #4

Quote:
Originally Posted by S34Qu4K3 View Post
PHP Code:
#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Random X"
#define VERSION "1.0"
#define AUTHOR "L//"


public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_event("HLTV""event_startround""a",    "1=0""2=0")
}

// Delay despues del start round
public event_startround() set_task(1.0"random_x")

public 
random_x()
{
    new 
indexnumxiplayers[32]

    
get_players(playersnum)

    
index random_num(0num 1)
    
    for(
index 1; ; x++)
    {    
        if(
>= num0
        
        i 
players[x]
        
        
// Condiciones
        
if(is_user_connected(i))
        {
            
// Setear X cosa a 'i'
            
            
break;
        }

        if(
== index) break;
    }

Code by //L ;)
</span></span>
Why would you post such unnecessary code?

Code:
yourFunction( ) {     new iPlayers[ 32 ], iNum;         // only use 1 of these 3 lines     get_players( iPlayers, iNum, "ach" ); // find any player     get_players( iPlayers, iNum, "aceh", "CT" ); // find a CT player     get_players( iPlayers, iNum, "aceh", "TERRORIST" ); // find a T player         if( iNum )     {         // there are players to choose from                 // get a random index of the players array         new iRandomIndex = random( iNum );                 // get the player index         new iPlayer = iPlayers[ iRandomIndex ];                 // do what you want with iPlayer     } }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
5c0r-|3i0
Veteran Member
Join Date: Nov 2008
Location: Việt Nam
Old 04-28-2010 , 20:03   Re: [SOLVED]Random a player in a team .
Reply With Quote #5

Thanks. Title modified .
__________________
5c0r-|3i0 is offline
epic .
Senior Member
Join Date: Oct 2009
Location: China
Old 04-29-2010 , 19:43   Re: [CS 1.6]Random a player in a team .
Reply With Quote #6

Quote:
Originally Posted by Exolent[jNr] View Post
// only use 1 of these 3 lines
get_players( iPlayers, iNum, "ach" ); // find any player
get_players( iPlayers, iNum, "aceh", "CT" ); // find a CT player
get_players( iPlayers, iNum, "aceh", "TERRORIST" ); // find a T player
"e" flag can return incorrect results (for cstrike/czero at least).

"We don't really support get_players() with flags anymore. It was a bad idea and if it was our choice, it would have never been added to the original AMX Mod."

Do a loop instead flag "e", such as:
Code:
yourFunction( )
{
   new iPlayers[32], iNum, id, iRandom[32], iPlayer, iRandomNum;
 
   get_players( iPlayers, iNum ); // find any player
 
   for ( new i = 0 ; i < iNum ; i++ )
   {
       id = iPlayers[i];
       if ( cs_get_user_team(id) == CS_TEAM_T )
       {
           iRandom[ iRandomNum++ ] = id;
           iPlayer = iRandom[ random( iRandomNum ) ];
 
           // do what you want with iPlayer who is a T
 
       }
 
       if ( cs_get_user_team(id) == CS_TEAM_CT )
       {
           iRandom[ iRandomNum++ ] = id;
           iPlayer = iRandom[ random( iRandomNum ) ];
 
           // do what you want with iPlayer who is a CT
 
       }
 
   }
}
__________________
Quote:
Destinies in my AWP sight are all alike;
Destinies out of my AWP sight in its own way.
epic . is offline
Send a message via ICQ to epic .
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-29-2010 , 20:16   Re: [CS 1.6]Random a player in a team .
Reply With Quote #7

Quote:
Originally Posted by epic . View Post
"e" flag can return incorrect results (for cstrike/czero at least).

"We don't really support get_players() with flags anymore. It was a bad idea and if it was our choice, it would have never been added to the original AMX Mod."

Do a loop instead flag "e", such as:
You are misinformed.

If you knew what you were talking about, "e" flag can only return incorrect results when retrieving dead players.
This is because if you switch teams while alive, you are killed and your team will not be updated til your next spawn.
Therefore, you will be seen as a dead player on your previous team.

Also, get_players() works fine, so that quote about being unsupported doesn't mean it shouldn't be used.

Get your facts straight before spreading them.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
epic .
Senior Member
Join Date: Oct 2009
Location: China
Old 04-29-2010 , 21:44   Re: [CS 1.6]Random a player in a team .
Reply With Quote #8

Quote:
Originally Posted by Exolent[jNr] View Post
You are misinformed.

If you knew what you were talking about, "e" flag can only return incorrect results when retrieving dead players.
This is because if you switch teams while alive, you are killed and your team will not be updated til your next spawn.
Therefore, you will be seen as a dead player on your previous team.

Also, get_players() works fine, so that quote about being unsupported doesn't mean it shouldn't be used.

Get your facts straight before spreading them.
Am I misinformed ? Haha
Real Knowledge Comes From Practice. Just try to get players with flag "ae" by yourself, you will know the facts. You have to try a lot of times, because it only doesn`t work occasionally.
And this is why there are so many people report the slaylosers.sma doesn`t work everytime http://forums.alliedmods.net/showthread.php?t=924
__________________
Quote:
Destinies in my AWP sight are all alike;
Destinies out of my AWP sight in its own way.
epic . is offline
Send a message via ICQ to epic .
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-29-2010 , 21:48   Re: [SOLVED]Random a player in a team .
Reply With Quote #9

I have never had a problem with get_players() (other than the one I described) in my server and I use it in almost all of my plugins.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] 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 03:42.


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