Raised This Month: $ Target: $400
 0% 

Getting Top5 Players of Map


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 08-25-2013 , 09:26   Getting Top5 Players of Map
Reply With Quote #1

Hello,

I'd like to get the Top5 Player IDs of the Map using this code.

PHP Code:
public calculate_places()
{
    new 
iFragsiFrags1iFrags2iFrags3iFrags4iFrags5
    
    
if(g_iFirstPlace == 0)
        
iFrags1 0
    
else
        
iFrags1 get_user_frags(g_iFirstPlace)
        
    if(
g_iSecondPlace == 0)
        
iFrags2 0
    
else
        
iFrags2 get_user_frags(g_iSecondPlace)
        
    if(
g_iThirdPlace == 0)
        
iFrags3 0
    
else
        
iFrags3 get_user_frags(g_iThirdPlace)
        
    if(
g_iFourthPlace == 0)
        
iFrags4 0
    
else
        
iFrags4 get_user_frags(g_iFourthPlace)
        
    if(
g_iFifthPlace == 0)
        
iFrags5 0
    
else
        
iFrags5 get_user_frags(g_iFifthPlace)
    
    new 
players[32], pnumtempid
    get_players
(playerspnum)
    
    for( new 
ii<pnumi++ ) 
    {
        
tempid players[i]
        
        
iFrags get_user_frags(tempid)
        
        if(
iFrags iFrags1)
        {
            
g_iFirstPlace tempid
            
return PLUGIN_HANDLED
        
}
        
        if(
iFrags iFrags2)
        {
            
g_iSecondPlace tempid
            
return PLUGIN_HANDLED
        
}
        
        if(
iFrags iFrags3)
        {
            
g_iThirdPlace tempid
            
return PLUGIN_HANDLED
        
}
        
        if(
iFrags iFrags4)
        {
            
g_iFourthPlace tempid
            
return PLUGIN_HANDLED
        
}
        
        if(
iFrags iFrags5)
        {
            
g_iFifthPlace tempid
            
return PLUGIN_HANDLED
        
}
        
    }
    return 
PLUGIN_HANDLED

But as you can see in the Picture it always shows me on all places, even when others have frags too.


Code for HUD below :

PHP Code:
// ===============================================================================
//     Left HUD
// ===============================================================================

public func_HUDLeft()
{    
    if(!
g_bGameHasStarted)
        return 
PLUGIN_HANDLED
    
    set_hudmessage
(HUD_LEFT_REDHUD_LEFT_GREENHUD_LEFT_BLUEHUD_LEFT_XHUD_LEFT_Y0_HUD_FREQ__2)
    
    new 
players[32], pnumtempid
    get_players
(playerspnum"a")
    
    new 
szNameO[64]
    new 
szName1[64], szName2[64], szName3[64], szName4[64], szName5[64]
    
    if(
g_iFirstPlace != 0)
        
get_user_name(g_iFirstPlace,     szName1charsmax(szName1))
    else
        
formatex(szName1charsmax(szName1), "-")
    
    if(
g_iSecondPlace != 0)
        
get_user_name(g_iSecondPlace,     szName2charsmax(szName2))
    else
        
formatex(szName2charsmax(szName2), "-")
    
    if(
g_iThirdPlace != 0)
        
get_user_name(g_iThirdPlace,     szName3charsmax(szName3))
    else
        
formatex(szName3charsmax(szName3), "-")
    
    if(
g_iFourthPlace != 0)
        
get_user_name(g_iFourthPlace,     szName4charsmax(szName4))
    else
        
formatex(szName4charsmax(szName4), "-")
    
    if(
g_iFifthPlace != 0)
        
get_user_name(g_iFifthPlace,     szName5charsmax(szName5))
    else
        
formatex(szName5charsmax(szName5), "-")
        
    
/* Scoreboard Style :

    (HUD) 1st [Kills] Name
    (HUD) 2nd [Kills] Name
    (HUD) 3rd [Kills] Name
    (HUD) 4th [Kills] Name
    (HUD) 5th [Kills] Name
    ^n
    (HUD) >> [Kills] Own Name */
    
    
for( new ii<pnumi++ ) 
    {
        
tempid players[i]
        
get_user_name(tempidszNameOcharsmax(szNameO))
        
        
ShowSyncHudMsg(tempidSyncObj_Left"1st [%i] %s ^n 2nd [%i] %s ^n 3rd [%i] %s ^n 4th [%i] %s ^n 5th [%i] %s ^n^n >> [%i] %s",
        
get_user_frags(g_iFirstPlace), szName1,
        
get_user_frags(g_iSecondPlace), szName2,
        
get_user_frags(g_iThirdPlace), szName3,
        
get_user_frags(g_iFourthPlace), szName4,
        
get_user_frags(g_iFifthPlace), szName5,
        
get_user_frags(tempid), szNameO)
    }    
    
    return 
PLUGIN_HANDLED

I'm quite sure my code is bad, so, if anyone could help me, that would be great.
__________________
Kia is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 08-25-2013 , 09:36   Re: Getting Top5 Players of Map
Reply With Quote #2

Perfect situation for SortCustom*.
Code:
#include <amxmodx> #include <cstrike> public whatever(id) {         new iPlayers[32], iPlayersnum;         get_players(iPlayers, iPlayersnum, "c");     SortCustom1D(iPlayers, iPlayersnum, "SortFunc");         /* The top 5(or less) players */     for ( new i = 0 ; i < clamp(iPlayersnum, 0, 5) ; i++ ) {         // ...     } } public SortFunc(elem1, elem2) {     if ( get_user_frags(elem1) > get_user_frags(elem2) )         return -1;     else if ( get_user_frags(elem1) < get_user_frags(elem2) )         return 1;     else if ( get_user_deaths(elem1) < get_user_deaths(elem2) )         return -1;     else if ( get_user_deaths(elem1) > get_user_deaths(elem2) )         return 1;     return 0; }
__________________

Last edited by Black Rose; 08-25-2013 at 09:42.
Black Rose is offline
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 08-25-2013 , 12:14   Re: Getting Top5 Players of Map
Reply With Quote #3

I'm not quite sure how to use this, like this?

PHP Code:
for ( new clamp(iPlayersnum05) ; i++ ) 
    {
        switch(
i)
        {
            case 
0g_iFirstPlace iPlayers[i]
            case 
1g_iSecondPlace iPlayers[i]
            case 
2g_iThirdPlace iPlayers[i]
            case 
3g_iFourthPlace iPlayers[i]
            case 
4g_iFifthPlace iPlayers[i]
        }
    } 
// EDIT : Works great, thanks.
__________________

Last edited by Kia; 08-25-2013 at 12:38.
Kia is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 08-25-2013 , 12:59   Re: Getting Top5 Players of Map
Reply With Quote #4

That's one way. I would format the message inside the loop instead of using those variables. But you may need them somewhere else of course. Then they really should be an array instead of 5 separate variables.

If we're going to use the code you provided there's no point of looping it since we know what indexes we want.
Code:
for ( new i = 0 ; i < clamp(iPlayersnum, 0, 5) ; i++ ) {     switch(i)     {     case 0: g_iFirstPlace = iPlayers[i]     case 1: g_iSecondPlace = iPlayers[i]     case 2: g_iThirdPlace = iPlayers[i]     case 3: g_iFourthPlace = iPlayers[i]     case 4: g_iFifthPlace = iPlayers[i]     } }
-->
Code:
g_iFirstPlace = iPlayers[0] g_iSecondPlace = iPlayers[1] g_iThirdPlace = iPlayers[2] g_iFourthPlace = iPlayers[3] g_iFifthPlace = iPlayers[4]
__________________

Last edited by Black Rose; 08-25-2013 at 12:59.
Black Rose is offline
devilicioux
Veteran Member
Join Date: Jun 2013
Location: Delhi,India
Old 08-25-2013 , 13:03   Re: Getting Top5 Players of Map
Reply With Quote #5

Plugin looks awesome .. U gonna post the Source Kia ?
__________________
You keep bringing ANTICHRISTUS down .. He will rise again and kick asses !

#RespectList ANTICHRISTUS fysiks Bugsy

Most Common Errors You Can Encounter Every Now and Then
devilicioux is offline
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 08-25-2013 , 13:12   Re: Getting Top5 Players of Map
Reply With Quote #6

Yes, after I finished I'll post it.
See my homepage in my signature for my details. (Elimination Race)
__________________

Last edited by Kia; 08-25-2013 at 13:17.
Kia is offline
devilicioux
Veteran Member
Join Date: Jun 2013
Location: Delhi,India
Old 08-25-2013 , 13:14   Re: Getting Top5 Players of Map
Reply With Quote #7

Quote:
Originally Posted by Kia View Post
Yes, after I finished I'll post it.
See my homepage in my signature for my details.
I already subscribed you there May be u removed that subscription thing from you page :/
__________________
You keep bringing ANTICHRISTUS down .. He will rise again and kick asses !

#RespectList ANTICHRISTUS fysiks Bugsy

Most Common Errors You Can Encounter Every Now and Then
devilicioux is offline
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 08-25-2013 , 13:18   Re: Getting Top5 Players of Map
Reply With Quote #8

Yes, because Mail adresses get only saved in SQL Database, to lazy to copy adresses from there.
Maybe I'll fix it one day.
__________________
Kia is offline
devilicioux
Veteran Member
Join Date: Jun 2013
Location: Delhi,India
Old 08-25-2013 , 13:23   Re: Getting Top5 Players of Map
Reply With Quote #9

Quote:
Originally Posted by Kia View Post
Yes, because Mail adresses get only saved in SQL Database, to lazy to copy adresses from there.
Maybe I'll fix it one day.
Looking forward for the source of this plugin
Gud job as always
__________________
You keep bringing ANTICHRISTUS down .. He will rise again and kick asses !

#RespectList ANTICHRISTUS fysiks Bugsy

Most Common Errors You Can Encounter Every Now and Then
devilicioux 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 19:00.


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