SA-MP Forums Archive
[Help] Top 10 System - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [Help] Top 10 System (/showthread.php?tid=661472)



[Help] Top 10 System - ApolloScripter - 05.12.2018

Hello, I am developing a ranking system, with the 10 best players on the server (with more score), I would like to know how to create an order, from highest to lowest, considering that rank includes players offline, and yes, I know I need to save their score on some database, and I did this with DOF2.

Suppose I have 10 players, each with a different score, how do I put them in order from highest to lowest?

saving the id of each in an Array, for example:

PHP код:
new topserver[11]
//Code here
topserver[1] = // such a player id
//Code here
topserver[2] = //another player id 
so forth...


Re: [Help] Top 10 System - v1k1nG - 05.12.2018

As far as I know DOF2 uses dini, and I don't suggest you to use that for player data saving, anyways you can simply use native GetPlayerScore and order the results.


Re: [Help] Top 10 System - GameOvr - 06.12.2018

I had the same problem, then ****** said me "What you are describing is what a database is for", I think you must switch to MySQL or SQLite(I mean not to change the whole saving system just add this only for top players thing)

like,
When you are registering players register them in database too like in files(by MySQL or SQLite whatever...) then when players quit save their stats in the database too. like you save them in files then You can make a command like /top but when player types this you must save player(online players) data again in the database .. so it's easy to write a query and get them from database

Then you can get the top players including offline players.. if you don't know how to write a query then post a comment, I will help you


Re: [Help] Top 10 System - andrejc999 - 06.12.2018

You have to use a sorting algorithm. If you want I can write you one a bit later, at 10 o'clock maybe.


Re: [Help] Top 10 System - andrejc999 - 06.12.2018

Take a look at this:

https://sampforum.blast.hk/showthread.php?tid=647061


Re: [Help] Top 10 System - Kaliber - 06.12.2018

Quote:
Originally Posted by andrejc999
Посмотреть сообщение
You have to use a sorting algorithm. If you want I can write you one a bit later, at 10 o'clock maybe.
Don't write such things on your own.

You can use it already with SQL, just with ORDER BY.


Re: [Help] Top 10 System - GTLS - 06.12.2018

If you use SQL, it will ease your this and many other future problems. If you can not do it, you can get Scores of all registered account using INI and store it inside array. Then, sort the array using many already available methods. Like Quick Sort or Bubble Sort. Search on internet if you dont know their logic. They are just loops which help you sorting.


Re: [Help] Top 10 System - ApolloScripter - 06.12.2018

Quote:
Originally Posted by GTLS
Посмотреть сообщение
If you use SQL, it will ease your this and many other future problems. If you can not do it, you can get Scores of all registered account using INI and store it inside array. Then, sort the array using many already available methods. Like Quick Sort or Bubble Sort. Search on internet if you dont know their logic. They are just loops which help you sorting.
Okay, it seems to be the best method, using INI, but I have no idea how to start, can you give me a hint or a "push" showing the right direction?


Re: [Help] Top 10 System - Kane - 06.12.2018

You can use this.

https://sampforum.blast.hk/showthread.php?tid=343172

Quick example:

PHP код:
new _store_our_scoresMAX_PLAYERS ][ ], sizeof_our_list;
for( new 
iMAX_PLAYERSi++ )
{
    if( !
IsPlayerConnected) ){
        continue;
    }
    if( 
E_SCORE_VAR] > )
    {
        
_store_our_scores[i][0] = E_SCORE_VAR[i];
        
_store_our_scores[i][1] = i;
        
sizeof_our_list++;
    }
}
SortDeepArray_store_our_scores); 



Re: [Help] Top 10 System - Doddinger - 06.12.2018

Quote:
Originally Posted by Kaliber
Посмотреть сообщение
Don't write such things on your own.

You can use it already with SQL, just with ORDER BY.
and LIMIT....