Raised This Month: $ Target: $400
 0% 

Best 2 CT players


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
RuleBreaker
Senior Member
Join Date: May 2011
Old 10-28-2011 , 17:10   Best 2 CT players
Reply With Quote #1

How to find 2 best players in CT? (TAB, first and second one)
RuleBreaker is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 10-28-2011 , 17:39   Re: Best 2 CT players
Reply With Quote #2

Use a sort algorithm (I would suggest an insertion sort for this small amount of data). Search for it on the internet.

Then take the last 2 slots of the array (or first 2 if you sort in descending order), and those are your top 2 players.
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please

Last edited by nikhilgupta345; 10-28-2011 at 17:40.
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
Evaldas.Grigas
Senior Member
Join Date: Sep 2011
Location: Lithuania
Old 10-29-2011 , 03:05   Re: Best 2 CT players
Reply With Quote #3

Check player team and frags.
__________________
Please enter this website everyday: http://forums.alliedmods.net/showthread.php?t=169067
Evaldas.Grigas is offline
Send a message via Skype™ to Evaldas.Grigas
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 10-29-2011 , 08:16   Re: Best 2 CT players
Reply With Quote #4

Code:
    new Players[32], iNum, Kills[sizeof(Players)], Best[2], i         get_players(Players, iNum, "e", "TERRORIST")         for(i = 0; i < iNum; i++)         Kills[Players[i]] = get_user_frags(Players[i])         SortIntegers(Kills, sizeof(Players), Sort_Descending)         Best[0] = Kills[0]         get_players(Players, iNum, "e", "CT")         for(i = 0; i < iNum; i++)         Kills[Players[i]] = get_user_frags(Players[i])         SortIntegers(Kills, sizeof(Players), Sort_Descending)         Best[1] = Kills[0]         // best T player: Best[0], best CT player: Best[1]

I guess it can be done without two loops, but I can't think of any other way

Last edited by Backstabnoob; 10-29-2011 at 08:17.
Backstabnoob is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 10-29-2011 , 11:04   Re: Best 2 CT players
Reply With Quote #5

Quote:
Originally Posted by Backstabnoob View Post
Code:
    new Players[32], iNum, Kills[sizeof(Players)], Best[2], i         get_players(Players, iNum, "e", "TERRORIST")         for(i = 0; i < iNum; i++)         Kills[Players[i]] = get_user_frags(Players[i])         SortIntegers(Kills, sizeof(Players), Sort_Descending)         Best[0] = Kills[0]         get_players(Players, iNum, "e", "CT")         for(i = 0; i < iNum; i++)         Kills[Players[i]] = get_user_frags(Players[i])         SortIntegers(Kills, sizeof(Players), Sort_Descending)         Best[1] = Kills[0]         // best T player: Best[0], best CT player: Best[1]

I guess it can be done without two loops, but I can't think of any other way
That may give fall results. If one person is 10 and 0, and the other is 10 and 40, the 10 and 40 person may be earlier in the array.

Best thing to do with your method is to get the players, run a SortCustom1D on it, and then check the players frags AND deaths to the other. Then return the correct amount for it to sort for you.
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 10-29-2011 , 14:33   Re: Best 2 CT players
Reply With Quote #6

Good catch, haven't thought of that.

Last edited by Backstabnoob; 10-29-2011 at 14:34.
Backstabnoob is offline
kotinha
Senior Member
Join Date: Jun 2009
Location: Alentejo, Portugal :)
Old 10-29-2011 , 14:54   Re: Best 2 CT players
Reply With Quote #7

Not tested:
PHP Code:
public getBestCT(bestcts[2]) {
    
    new 
players[32], num
    get_players
(players,num)
    
    new 
cts[32], n
    
for(new inumi++) {
        if(
cs_get_user_team(players[i]) == CS_TEAM_CT) {
            
cts[n] = players[i]
            
n++;
        }
    }
    
    
SortCustom1D(ctssizeof cts"fnSortScores")
    
    
// cts[0] = first place
    // cts[1] = second place
    // cts[2] = third place
    // ...
}
public 
fnSortScores(elem1elem2) {
    new 
frags1 get_user_frags(elem1), frags2 get_user_frags(elem2)
    new 
deaths1 get_user_deaths(elem1), deaths2 get_user_deaths(elem2)
    
    if(
frags1 frags2)
        return -
1;
    else if (
frags1 frags2)
        return 
1;
    else {
        if(
deaths1 deaths2)
            return 
1;
        else if(
deaths1 deaths2)
            return -
1;
        else
            return 
0;
    }
    
    return 
0;

It's like nikhilgupta345 said, with SortCustom1D() to avoid wrong results, however I don't know if the scoreboard works like nikhilgupta345 said.
I think that it has the same bug that Backstabnoob made in his script
__________________
"If God exists, I hope he has a good excuse." - Woody Allen
kotinha is offline
jim_yang
Veteran Member
Join Date: Aug 2006
Old 10-29-2011 , 22:32   Re: Best 2 CT players
Reply With Quote #8

you can check scoreboard.cpp in hlsdk to see how it managed.
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>
jim_yang is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 10-30-2011 , 06:03   Re: Best 2 CT players
Reply With Quote #9

Code:
int highest_frags = -99999;     int lowest_deaths = 99999; int best_player = 0;                     for ( int i = 1; i < MAX_PLAYERS; i++ ) {     if ( m_PlayerInfoList[i].name && m_PlayerExtraInfo[i].frags >= highest_frags )     {         if ( !(team && stricmp(m_PlayerExtraInfo[i].teamname, team)) )  // make sure it is the specified team         {             extra_player_info_t *pl_info = &m_PlayerExtraInfo[i];             if ( pl_info->frags > highest_frags || pl_info->deaths < lowest_deaths )             {                 best_player = i;                 lowest_deaths = pl_info->deaths;                 highest_frags = pl_info->frags;                         }         }     } }

So I guess they've done it as I thought before. This should be the right conversion:

Code:
stock GetBestPlayer(CsTeams: Team) {     new highest_frags = -99999, lowest_deaths = 99999, best_player, frags[MAX_PLAYERS + 1], deaths[MAX_PLAYERS + 1]         for(new i = 1; i <= MAX_PLAYERS; i++)     {         if(!is_user_connected(i) || cs_get_user_team(i) != Team)             continue                 frags[i] = get_user_frags(i)         deaths[i] = get_user_deaths(i)                 if(frags[i] >= highest_frags)         {             highest_frags = frags[i]                         if(deaths[i] < lowest_deaths)             {                 best_player = i                                 lowest_deaths = deaths[i]             }         }     }         return best_player }

However this will print only one player.

Last edited by Backstabnoob; 10-30-2011 at 11:39.
Backstabnoob is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 10-30-2011 , 10:09   Re: Best 2 CT players
Reply With Quote #10

kotinha's code should work fine.

As far as I know, the scoreboard is set by at the top whoever has the highest kills, no matter their amount of deaths. However, if two people have the same amount of kills, the one with the lower amount of deaths goes higher in the scoreboard.
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
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:33.


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