AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Top15 Sorting From nVault (https://forums.alliedmods.net/showthread.php?t=214813)

Blizzard_87 04-29-2013 22:05

Top15 Sorting From nVault
 
i have this method of getting data from nvault
Code:
public LoadCount( id ) {     new Key[ 64 ], Value[ 64 ], Name[ 32 ];     get_user_name( id, Name, charsmax( Name ) );     formatex( Key, charsmax( Key ), "%s - LMS:", Name );     nvault_get( g_Vault, Key, Value, charsmax( Value ) );         g_iLastManCount[ id ] = str_to_num( Value ); }

and this is the top part of my top15 function for sorting part...
atm it only sorts the CONNECTED players.. but i want it to sort the top15 from ALL players in the nvault

Code:
public Show_Top15_LMS( id ) {     static Sort[ 33 ][ 2 ];     new players[ 32 ], num, count, index;     get_players( players, num );         for( new i = 0; i < num; i++ )     {         index = players[ i ];         Sort[ count ][ 0 ] = index;         Sort[ count ][ 1 ] = g_iLastManCount[ index ];         count++;     }

anyone explain how i can achieve this ?

hornet 04-29-2013 22:11

Re: Top15 Sorting From nVault
 
Take a look at nVault Utility.

Searching usually finds a thing or two aswell.

Blizzard_87 04-30-2013 00:42

Re: Top15 Sorting From nVault
 
Quote:

Originally Posted by hornet (Post 1942660)
Take a look at nVault Utility.

Searching usually finds a thing or two aswell.

so there is no way i could do it with what i have already?

hornet 04-30-2013 00:50

Re: Top15 Sorting From nVault
 
There's no other way to read all entries than nvault_util_readall().

Blizzard_87 05-10-2013 00:13

Re: Top15 Sorting From nVault
 
Quote:

Originally Posted by hornet (Post 1942699)
There's no other way to read all entries than nvault_util_readall().

ok ive been looking into this and so far ive managed to get this.

http://i.snapthat.net/S3zI.png

and the code to get this is
Code:
public test( id ) {     new iPos , szKey[ 32 ] , szVal[ 64 ] , iTimeStamp;     new iVault = nvault_util_open( "Last_Man" );     new iCount = nvault_util_count( iVault );     for ( new iCurrent = 1 ; iCurrent <= iCount ; iCurrent++ )     {         iPos = nvault_util_read( iVault , iPos , szKey , charsmax( szKey ) , szVal , charsmax( szVal ) , iTimeStamp );                 server_print( "[%d of %d] Name: %s LMS Count: %s" , iCurrent , iCount , szKey , szVal );     }         nvault_util_close( iVault ); }

how do i edit it so i can use this in my Top15?

Code:
public ShowTop15( id ) {     static Sort[ 33 ][ 2 ];     new players[ 32 ], num, count, index;     get_players( players, num );        // This Only Shows Online Players In Top15     for( new i = 0; i < num; i++ )     {         index = players[ i ];         Sort[ count ][ 0 ] = index;         Sort[ count ][ 1 ] = g_iLastManCount[ index ];         count++;     }         SortCustom2D( Sort, count, "compare_lms");     new motd[ 1501 ], iLen;     iLen = format( motd, charsmax( motd ), "<body background='http://i.snapthat.net/cXiy.png'><font color=#98f5ff size=4><b><pre>");     iLen += format( motd[ iLen ], ( charsmax( motd ) ) - iLen,"%s %-22.22s %3s^n", "#", "Name", "LMS Count");         new y = clamp( count, 0, 15 );     new name[ 32 ], kindex;         for( new x = 0; x < y; x++ )     {         kindex = Sort[ x ][ 0 ];         get_user_name( kindex, name, charsmax( name ) );         iLen += format( motd[ iLen ], ( charsmax( motd ) ) - iLen,"%d %-22.22s %d^n", x + 1, name, Sort[ x ][ 1 ]);     }     iLen += format( motd[ iLen ], ( charsmax( motd ) ) - iLen, "</body></font></b></pre>" );     show_motd( id, motd, "Last Man Standing Top15" ); } public compare_lms( elem1[], elem2[] ) {     if(elem1[ 1 ] > elem2[ 1 ])         return -1;     else if(elem1[ 1 ] < elem2[ 1 ])         return 1;         return 0; }

Blizzard_87 05-10-2013 06:58

Re: Top15 Sorting From nVault
 
ok now im using your method hornet... but still having no luck...
Code:
//////////////////////////////////// // Saves Last Man Count To nVault // //////////////////////////////////// public SaveCount( id ) {     new Key[ 64 ], Value[ 64 ], Name[ 32 ];     get_user_name( id, Name, charsmax( Name ) );     formatex( Key, charsmax( Key ), "%s", Name );     formatex( Value, charsmax( Value ), "%d", g_iLastManCount[ id ] );         nvault_set( g_Vault, Key, Value ); } ////////////////////////////////////// // Loads Last Man Count From nVault // ////////////////////////////////////// public LoadCount( id ) {     new Key[ 64 ], Value[ 64 ], Name[ 32 ];     get_user_name( id, Name, charsmax( Name ) );     formatex( Key, charsmax( Key ), "%s", Name );     nvault_get( g_Vault, Key, Value, charsmax( Value ) );         g_iLastManCount[ id ] = str_to_num( Value ); } ///////////////////////////////////////////////////////////////// // Shows The Top 15 Last Man Standing Players Currently Online // ///////////////////////////////////////////////////////////////// public On_nVaultUtil_ReadEntry( i, iTotal, const szKey[], const szData[]/*, iTimeStamp, const Data[], iSize*/ ) {     static ArrayData[ PlayersData ], szRank[ 4 ];         /*  Save name with quotes so it can be parsed */         parse( szData, szRank, charsmax( szRank ), ArrayData[ PLAYER_NAME ], charsmax( ArrayData[ PLAYER_NAME ] ) );         remove_quotes( ArrayData[ PLAYER_NAME ] );     ArrayData[ PLAYER_RANK ] = str_to_num( szRank );         ArrayPushArray( g_PlayersArray, ArrayData ); } public ArrayItem_Compare( Array:array, iItem1, iItem2/*, const szData[], iSize*/ ) {     static ArrayData1[ PlayersData ], ArrayData2[ PlayersData ];         ArrayGetArray( g_PlayersArray, iItem1, ArrayData1 );     ArrayGetArray( g_PlayersArray, iItem2, ArrayData2 );         return clamp( ArrayData2[ PLAYER_RANK ] - ArrayData1[ PLAYER_RANK ], -1, 1 ); } public ClientCommand_ShowMotd( id ) {     new iSize = ArraySize( g_PlayersArray );             new ArrayData[ PlayersData ];         new motd[ 1501 ], iLen;     iLen = format( motd, charsmax( motd ), "<body background='http://i.snapthat.net/cXiy.png'><font color=#98f5ff size=4><b><pre>");     iLen += format( motd[ iLen ], ( charsmax( motd ) ) - iLen,"%-5.5s %-22.22s %3s^n", "Rank", "Name", "Time(s) LMS");         for( new i ; i < iSize ; i ++ )     {         ArrayGetArray( g_PlayersArray, i, ArrayData );                 iLen += format( motd[ iLen ], ( charsmax( motd ) ) - iLen,"%-5.5d %-22.22s %d^n", ArrayData[ PLAYER_RANK ], ArrayData[ PLAYER_NAME ], g_iLastManCount[ i ]);                 /*  Add your player into MOTD string here. int i in each iteration         will hold the index of the entry with the next player in order by         rank.                 ArrayData[ PLAYER_NAME ] - Is the string holding player's name         ArrayData[ PLAYER_RANK ] - Is the int holding player's rank         */     }           iLen += format( motd[ iLen ], ( charsmax( motd ) ) - iLen, "</body></font></b></pre>" );     show_motd( id, motd, "Last Man Standing Top15" ); }

it appears like this.

http://i.snapthat.net/2juk.png

hornet 05-10-2013 07:33

Re: Top15 Sorting From nVault
 
Yes I made a readability error in the example I wrote in the linked thread. PLAYER_RANK is the integer that the player's are ranked by. Meaning you could change PLAYER_RANK to something like PLAYER_SCORE for readability.
Therefore the integer you format in the Rank column should be i + 1 :
Code:
iLen += format( motd[ iLen ], ( charsmax( motd ) ) - iLen,"%-5.5d %-22.22s %d^n", i + 1, ArrayData[ PLAYER_NAME ], ArrayData[ PLAYER_RANK ] );

You need to read what I said in the other thread about saving and reading the player's name.

Also make motd array static.


All times are GMT -4. The time now is 10:47.

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