AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Best 2 CT players (https://forums.alliedmods.net/showthread.php?t=170764)

RuleBreaker 10-28-2011 17:10

Best 2 CT players
 
How to find 2 best players in CT? (TAB, first and second one)

nikhilgupta345 10-28-2011 17:39

Re: Best 2 CT players
 
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.

Evaldas.Grigas 10-29-2011 03:05

Re: Best 2 CT players
 
Check player team and frags.

Backstabnoob 10-29-2011 08:16

Re: Best 2 CT players
 
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

nikhilgupta345 10-29-2011 11:04

Re: Best 2 CT players
 
Quote:

Originally Posted by Backstabnoob (Post 1585598)
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.

Backstabnoob 10-29-2011 14:33

Re: Best 2 CT players
 
Good catch, haven't thought of that.

kotinha 10-29-2011 14:54

Re: Best 2 CT players
 
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

jim_yang 10-29-2011 22:32

Re: Best 2 CT players
 
you can check scoreboard.cpp in hlsdk to see how it managed.

Backstabnoob 10-30-2011 06:03

Re: Best 2 CT players
 
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.

nikhilgupta345 10-30-2011 10:09

Re: Best 2 CT players
 
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.


All times are GMT -4. The time now is 14:19.

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