AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Getting Top5 Players of Map (https://forums.alliedmods.net/showthread.php?t=224525)

Kia 08-25-2013 09:26

Getting Top5 Players of Map
 
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.
http://puu.sh/4at6Z.jpg

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.

Black Rose 08-25-2013 09:36

Re: Getting Top5 Players of Map
 
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; }

Kia 08-25-2013 12:14

Re: Getting Top5 Players of Map
 
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.

Black Rose 08-25-2013 12:59

Re: Getting Top5 Players of Map
 
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]

devilicioux 08-25-2013 13:03

Re: Getting Top5 Players of Map
 
Plugin looks awesome .. U gonna post the Source Kia ?

Kia 08-25-2013 13:12

Re: Getting Top5 Players of Map
 
Yes, after I finished I'll post it.
See my homepage in my signature for my details. (Elimination Race)

devilicioux 08-25-2013 13:14

Re: Getting Top5 Players of Map
 
Quote:

Originally Posted by Kia (Post 2021459)
Yes, after I finished I'll post it.
See my homepage in my signature for my details.

I already subscribed you there :P May be u removed that subscription thing from you page :/

Kia 08-25-2013 13:18

Re: Getting Top5 Players of Map
 
Yes, because Mail adresses get only saved in SQL Database, to lazy to copy adresses from there.
Maybe I'll fix it one day.

devilicioux 08-25-2013 13:23

Re: Getting Top5 Players of Map
 
Quote:

Originally Posted by Kia (Post 2021469)
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 :fox:
Gud job as always :D


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

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