Raised This Month: $51 Target: $400
 12% 

Top 5 values


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
abdelwahab
Member
Join Date: Aug 2019
Old 03-08-2024 , 17:28   Top 5 values
Reply With Quote #1

Hello, hope you are doing well,
So my question is how to get top 5 highest value in some array for example lets call it g_iKeys[33];
i want to get the highest values and their ids, Thanks!
abdelwahab is offline
WATCH_D0GS UNITED
Senior Member
Join Date: Jan 2023
Old 03-08-2024 , 18:36   Re: Top 5 values
Reply With Quote #2

(AI) We are a bit busy now.

Tested in game, it works well.

PHP Code:
new g_iKeys[33] = {105812315792611411413201819161725222123272426302931283233};

new 
g_iTopValues[5];
new 
g_iTopIndices[5]; 
PHP Code:
        for (new 0sizeof(g_iKeys); i++)
        {
                for (new 
0sizeof(g_iTopValues); j++)
                {
                        if (
g_iKeys[i] > g_iTopValues[j])
                        {
                                
// Shift the values and indices to make room for the new value
                                
for (new sizeof(g_iTopValues) - 1jk--)
                                {
                                        
g_iTopValues[k] = g_iTopValues[1];
                                        
g_iTopIndices[k] = g_iTopIndices[1];
                                }

                                
// Assign the new value and index to the correct position
                                
g_iTopValues[j] = g_iKeys[i];
                                
g_iTopIndices[j] = i;

                                break;
                        }
                }
        }

        for (new 
0sizeof(g_iTopValues); i++)
        {
                
client_print(id,print_chat,"Value: %d, Index: %d"g_iTopValues[i], g_iTopIndices[i])
        } 
__________________
💻Know Our New Blog👄
🔗tube2downs.blogspot.com
WATCH_D0GS UNITED is offline
abdelwahab
Member
Join Date: Aug 2019
Old 03-09-2024 , 09:56   Re: Top 5 values
Reply With Quote #3

Thanks, what ai used ?
abdelwahab is offline
WATCH_D0GS UNITED
Senior Member
Join Date: Jan 2023
Old 03-09-2024 , 10:47   Re: Top 5 values
Reply With Quote #4

For your question, ChatGPT 3.5

Select the one you want here (Check your inbox)
__________________
💻Know Our New Blog👄
🔗tube2downs.blogspot.com
WATCH_D0GS UNITED is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-09-2024 , 16:58   Re: Top 5 values
Reply With Quote #5

PHP Code:
#include <amxmodx>

enum _:DataLayout
{
    
PlayerID,
    
XPVal
}

new 
yourData[][ DataLayout] = 

    { 
55 },
    { 
10 32 },
    { 
32 },
    { 
100 },
    { 
58 }
};

public 
plugin_init() 
{
    
SortCustom2DyourData sizeofyourData ) , "CompareXP" );
    
    
//Replace "sizeof( yourData )" with 5, or whatever.
    
for ( new sizeofyourData ) ; i++ )
        
server_print"Player id %d - XP %d" yourData][ PlayerID ] , yourData][ XPVal ] );
}

public 
CompareXPelem1[] , elem2[] ) 

    if ( 
elem1] > elem2] ) 
        return -
1
    else if(
elem1] < elem2] ) 
        return 
1
    
    return 
0

Output
Code:
Player id 5 - XP 100
Player id 1 - XP 58
Player id 2 - XP 55
Player id 10 - XP 32
Player id 32 - XP 5
__________________

Last edited by Bugsy; 03-09-2024 at 16:59.
Bugsy is offline
abdelwahab
Member
Join Date: Aug 2019
Old 03-12-2024 , 15:19   Re: Top 5 values
Reply With Quote #6

Thanks thats even more helpful
abdelwahab 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 10:15.


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