Raised This Month: $32 Target: $400
 8% 

sorting floats+id


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
JocAnis
Veteran Member
Join Date: Jun 2010
Old 11-25-2018 , 14:44   sorting floats+id
Reply With Quote #1

hello..i have a little trouble to connect id to sorted float value...here is the example:

Code:
p_marker[ id ] = float( g_pBestTouch[ id ] )
p_marker[ 5 ] = 105.3 
p_marker[ 8 ] = 152.2

SortFloats( p_marker, sizeof( p_marker ),  Sort_Descending )//this is working
it stamps:
1. 5005.0
2. 152.2
3.105.3

which is correct by the SortFloat, but how can i implement names to their desired float value?
i went with:
Code:
SortFloats( p_marker, sizeof( p_marker ), Sort_Descending )
for( new i = 0; i < sizeof( p_marker ); i++ )
{
	get_user_name( i, name, charsmax( name ) )
	client_print( 0, print_console, "%d %.01f %s", i, p_marker[ i ], name )
}
but names arent connected with printed floats in console...maybe its needed sort2d, but how with floats :/
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)
JocAnis is offline
E1_531G
Senior Member
Join Date: Dec 2017
Old 11-25-2018 , 15:02   Re: sorting floats+id
Reply With Quote #2

At the moment, thinking fast, i found the next solution:
use Trie to map values to ids.
Quote:
TrieSetCell( gTrie, float_to_string(value), id ); // this value belong to this id
But, there must be better solution, i will think more.
__________________
My English is A0
E1_531G is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-25-2018 , 17:14   Re: sorting floats+id
Reply With Quote #3

Made slight tweaks to this
PHP Code:

#include <amxmodx>

#define MAX_PLAYERS 32

new Float:g_PlayerFragsMAX_PLAYERS ][ ];

public 
plugin_init() 
{
    
//Load player data in array
    // g_PlayerFrags[][ 0 ] = player id
    // g_PlayerFrags[][ 1 ] = float value
    
    
g_PlayerFrags][ ] = Float:3;
    
g_PlayerFrags][ ] = 5.6;
    
    
g_PlayerFrags][ ] = Float:2;
    
g_PlayerFrags][ ] = 3.4;
    
    
g_PlayerFrags][ ] = Float:1;
    
g_PlayerFrags][ ] = 1.2;
    
    
DisplayInfo();
}

public 
DisplayInfo()
{
    new 
iPlayer;

    
SortCustom2D_:g_PlayerFrags sizeofg_PlayerFrags ) , "SortCompare" );

    for ( new 
sizeofg_PlayerFrags ) ; i++ )
    {
        
iPlayer _:g_PlayerFrags][ ];
    
        
//Get players name, or whatever
        //get_user_name( iPlayer , szName , charsmax( szName ) );
        
        
server_print"id=%d - Rank: %d - Frags: %f" iPlayer i+g_PlayerFrags][ ] );
    }
}

public 
SortCompareFloat:elem1[] , Float:elem2[] )
{
    if( 
elem1[1] > elem2[1] ) 
        return -
1;
    else if( 
elem1[1] < elem2[1] )
        return 
1;
    
    return 
0;

__________________

Last edited by Bugsy; 11-25-2018 at 17:30.
Bugsy is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 11-25-2018 , 18:43   Re: sorting floats+id
Reply With Quote #4

you d maaaan thank you, its printing all good now
also thanks @E1_531G for trying to help (dont know why but i hate tries, if bugsy didnt saw this thread i would probably go with multiplying that Float and use sort2D haha
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)
JocAnis is offline
shauli
Member
Join Date: Jun 2018
Old 11-25-2018 , 19:59   Re: sorting floats+id
Reply With Quote #5

Quote:
Originally Posted by Bugsy View Post
Made slight tweaks to this
I don't know if you're involved in the new AMXX version, but is there a chance of us getting a "cmp" stock in one of the default includes? Just like floats have one (floatcmp)?
shauli is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-26-2018 , 03:21   Re: sorting floats+id
Reply With Quote #6

Quote:
Originally Posted by shauli View Post
I don't know if you're involved in the new AMXX version, but is there a chance of us getting a "cmp" stock in one of the default includes? Just like floats have one (floatcmp)?
To request a new feature, you should submit an "issue" on the Github repo. It seems like it's a simple concept that need not be done with a native, simply use == or > or <.

If you want to have a discussion about it, you should create a new thread since it's unrelated to this topic.
__________________

Last edited by fysiks; 11-26-2018 at 03:23.
fysiks 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:26.


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