[Help] Top 10 System
#1

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...
Reply
#2

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.
Reply
#3

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
Reply
#4

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

Take a look at this:

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

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.
Reply
#7

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.
Reply
#8

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?
Reply
#9

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); 
Reply
#10

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....
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)