AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   sorting floats+id (https://forums.alliedmods.net/showthread.php?t=312297)

JocAnis 11-25-2018 14:44

sorting floats+id
 
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 :/

E1_531G 11-25-2018 15:02

Re: sorting floats+id
 
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.

Bugsy 11-25-2018 17:14

Re: sorting floats+id
 
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;



JocAnis 11-25-2018 18:43

Re: sorting floats+id
 
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

shauli 11-25-2018 19:59

Re: sorting floats+id
 
Quote:

Originally Posted by Bugsy (Post 2625680)
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)?

fysiks 11-26-2018 03:21

Re: sorting floats+id
 
Quote:

Originally Posted by shauli (Post 2625689)
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.


All times are GMT -4. The time now is 07:29.

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