• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] How does one make a top5?
#1
I don't have a good idea on how to make a top5 all time it, only thing I can think of is for(i=0;i<MAX_PLAYERS;i) but don't know how to continue the rest.
  Reply
#2
You need to be more specific about what you want to do. Is it an all time top or just for the online players?
  Reply
#3
more like top 5 killers of all time, i'm using yini so..
  Reply
#4
(2021-02-26, 02:22 AM)Z3fRaN Wrote: more like top 5 killers of all time, i'm using yini so..



There is no need for loops. All you need is already there for you to use:



https://open.mp/docs/scripting/callbacks...Disconnect

https://open.mp/docs/scripting/callbacks/OnPlayerDeath



You make an enum that holds top5 players information (player names, number of kills, maybe time when they moved up in the top and so on...). On?OnPlayerDeath callback you just make the checks if the player has more kills than top5 player or top4 player and so on. On that callback you do the checks and would be a good idea to save the top list after the top changes. Of course you will need to use Y_INI to load the top5 on OnGameModeInit also.
  Reply
#5
If you're using MySQL you can very easily select a top 5 based on certain data. For example, let's say we have this users table:\
Code:
+---+----------+------+-------+------
| id | name      | kills | deaths | score |
+---+----------+------+-------+------
|  1 | Kwarde    |    16 |     25 |     4 |
|  2 | Playa     |     2 |     19 |     1 |
|  3 | Z3fRaN    |    28 |      1 |   100 |
|  4 | Narf3z    |     1 |     28 |     0 |
|  5 | MathPi    |    99 |      0 |    50 |
|  6 | Slayer    |    66 |     13 |    25 |
|  7 | JimmyPage |     0 |      2 |     0 |
+---+----------+------+-------+------
Using this query:
Code:
SELECT name, kills FROM users ORDER BY kills DESC LIMIT 5;
This would select columns "name" and "kills" from the table "users" and order by kills, descending (DESC -- ASC would order ascending, and thus beginning with the lowest values). LIMIT 5 says: Limit to 5 results. The query itself should be pretty clear.
This would give this output:
Code:
+-------+------
| name   | kills |
+-------+------
| MathPi |    99 |
| Slayer |    66 |
| Z3fRaN |    28 |
| Kwarde |    16 |
| Playa  |     2 |
+-------+------
  Reply
#6
(2021-02-26, 05:22 AM)Kwarde Wrote: If you're using MySQL you can very easily select a top 5 based on certain data. For example, let's say we have this users table:\

Code:
+---+----------+------+-------+------

| id | name? ? ? | kills | deaths | score |

+---+----------+------+-------+------

|? 1 | Kwarde? ? |? ? 16 |? ? 25 |? ? 4 |

|? 2 | Playa? ? |? ? 2 |? ? 19 |? ? 1 |

|? 3 | Z3fRaN? ? |? ? 28 |? ? ? 1 |? 100 |

|? 4 | Narf3z? ? |? ? 1 |? ? 28 |? ? 0 |

|? 5 | MathPi? ? |? ? 99 |? ? ? 0 |? ? 50 |

|? 6 | Slayer? ? |? ? 66 |? ? 13 |? ? 25 |

|? 7 | JimmyPage |? ? 0 |? ? ? 2 |? ? 0 |

+---+----------+------+-------+------

Using this query:

Code:
SELECT name, kills FROM users ORDER BY kills DESC LIMIT 5;

This would select columns "name" and "kills" from the table "users" and order by kills, descending (DESC -- ASC would order ascending, and thus beginning with the lowest values). LIMIT 5 says: Limit to 5 results. The query itself should be pretty clear.

This would give this output:

Code:
+-------+------

| name? | kills |

+-------+------

| MathPi |? ? 99 |

| Slayer |? ? 66 |

| Z3fRaN |? ? 28 |

| Kwarde |? ? 16 |

| Playa? |? ? 2 |

+-------+------



Going through all user files is really unnecessary. This would need only 5 rows as the checking who has more kills would still be checked on the server live. There is no need to go through all user files.
  Reply
#7
Going through "user files"? Is unnecessary? Is an issue somehow? Do you know how MySQL works?



You found the secret text!

If your database (and server, and system, eventually) is set up properly there's no issue at all.

An old InnoDB users table from some server backup, 11.140 rows, 7.2MiB. 97 columns (this database wasn't set up properly). Using the query from above, it takes about 0.0155-0.020 seconds. Selecting all data (*) would take about 0.065-0.07 seconds.

It's on so many levels different than "going through user files" (as in ini-based includes).



Also keep in mind: MySQL is a relational database management system. It's designed (atleast one of the reasons) to be able to perform eventually complex queries to find data in seperate tables,eventually databases. Such a simple query as above is nothing
  Reply
#8
(2021-02-27, 02:26 PM)Kwarde Wrote: Going through "user files"? Is unnecessary? Is an issue somehow? Do you know how MySQL works?



You found the secret text!

If your database (and server, and system, eventually) is set up properly there's no issue at all.

An old InnoDB users table from some server backup, 11.140 rows, 7.2MiB. 97 columns (this database wasn't set up properly). Using the query from above, it takes about 0.0155-0.020 seconds. Selecting all data (*) would take about 0.065-0.07 seconds.

It's on so many levels different than "going through user files" (as in ini-based includes).



Also keep in mind: MySQL is a relational database management system. It's designed (atleast one of the reasons) to be able to perform eventually complex queries to find data in seperate tables,eventually databases. Such a simple query as above is nothing



You can nag about the non-essential things, but I think you don't get my point and my point is:



5 rows < hundreds or thousands of rows / 1 file < hundreds or thousands of files / loading and saving data only for the top5 (5 players) instead of comparing data to hundreds or thousands of players. I know the time difference is not that great, but if I can make things smarter and better then I'm going to do it that way. If you want to do things another way and it works for you then nobody is stopping you. Go ahead. I just showed OP at least how I would have done it.
  Reply
#9
(2021-02-27, 08:43 PM)Virsenas Wrote:
(2021-02-27, 02:26 PM)Kwarde Wrote: Going through "user files"? Is unnecessary? Is an issue somehow? Do you know how MySQL works?



You found the secret text!

If your database (and server, and system, eventually) is set up properly there's no issue at all.

An old InnoDB users table from some server backup, 11.140 rows, 7.2MiB. 97 columns (this database wasn't set up properly). Using the query from above, it takes about 0.0155-0.020 seconds. Selecting all data (*) would take about 0.065-0.07 seconds.

It's on so many levels different than "going through user files" (as in ini-based includes).



Also keep in mind: MySQL is a relational database management system. It's designed (atleast one of the reasons) to be able to perform eventually complex queries to find data in seperate tables,eventually databases. Such a simple query as above is nothing



You can nag about the non-essential things, but I think you don't get my point and my point is:



5 rows < hundreds or thousands of rows / 1 file < hundreds or thousands of files / loading and saving data only for the top5 (5 players) instead of comparing data to hundreds or thousands of players. I know the time difference is not that great, but if I can make things smarter and better then I'm going to do it that way. If you want to do things another way and it works for you then nobody is stopping you. Go ahead. I just showed OP at least how I would have done it.



He isnt saving data for only top 5 he is using the DESC command that is used to sort data in descending order and specifying?the number of records he wants to?return?5, 10, 50?(keyword LIMIT).
  Reply
#10
(2021-02-26, 01:37 AM)Z3fRaN Wrote: I don't have a good idea on how to make a top5 all time it, only thing I can think of is for(i=0;i<MAX_PLAYERS;i) but don't know how to continue the rest.


I can give you a code that gets top 5 online players, if you want it.
But to get the best players all the time you have to use MySQL:

(2021-02-26, 05:22 AM)Kwarde Wrote: If you're using MySQL you can very easily select a top 5 based on certain data. For example, let's say we have this users table:\

Code:
+---+----------+------+-------+------

| id | name? ? ? | kills | deaths | score |

+---+----------+------+-------+------

|? 1 | Kwarde? ? |? ? 16 |? ? 25 |? ? 4 |

|? 2 | Playa? ? |? ? 2 |? ? 19 |? ? 1 |

|? 3 | Z3fRaN? ? |? ? 28 |? ? ? 1 |? 100 |

|? 4 | Narf3z? ? |? ? 1 |? ? 28 |? ? 0 |

|? 5 | MathPi? ? |? ? 99 |? ? ? 0 |? ? 50 |

|? 6 | Slayer? ? |? ? 66 |? ? 13 |? ? 25 |

|? 7 | JimmyPage |? ? 0 |? ? ? 2 |? ? 0 |

+---+----------+------+-------+------

Using this query:

Code:
SELECT name, kills FROM users ORDER BY kills DESC LIMIT 5;

This would select columns "name" and "kills" from the table "users" and order by kills, descending (DESC -- ASC would order ascending, and thus beginning with the lowest values). LIMIT 5 says: Limit to 5 results. The query itself should be pretty clear.

This would give this output:

Code:
+-------+------

| name? | kills |

+-------+------

| MathPi |? ? 99 |

| Slayer |? ? 66 |

| Z3fRaN |? ? 28 |

| Kwarde |? ? 16 |

| Playa? |? ? 2 |

+-------+------
  Reply
#11
Thank you all for help.



(2021-02-27, 11:45 PM)Radical Wrote:
(2021-02-26, 01:37 AM)Z3fRaN Wrote: I don't have a good idea on how to make a top5 all time it, only thing I can think of is for(i=0;i<MAX_PLAYERS;i) but don't know how to continue the rest.





I can give you a code that gets top 5 online players, if you want it.

But to get the best players all the time you have to use MySQL:



(2021-02-26, 05:22 AM)Kwarde Wrote: If you're using MySQL you can very easily select a top 5 based on certain data. For example, let's say we have this users table:\



Code:
+---+----------+------+-------+------



| id | name? ? ? | kills | deaths | score |



+---+----------+------+-------+------



|? 1 | Kwarde? ? |? ? 16 |? ? 25 |? ? 4 |



|? 2 | Playa? ? |? ? 2 |? ? 19 |? ? 1 |



|? 3 | Z3fRaN? ? |? ? 28 |? ? ? 1 |? 100 |



|? 4 | Narf3z? ? |? ? 1 |? ? 28 |? ? 0 |



|? 5 | MathPi? ? |? ? 99 |? ? ? 0 |? ? 50 |



|? 6 | Slayer? ? |? ? 66 |? ? 13 |? ? 25 |



|? 7 | JimmyPage |? ? 0 |? ? ? 2 |? ? 0 |



+---+----------+------+-------+------



Using this query:



Code:
SELECT name, kills FROM users ORDER BY kills DESC LIMIT 5;



This would select columns "name" and "kills" from the table "users" and order by kills, descending (DESC -- ASC would order ascending, and thus beginning with the lowest values). LIMIT 5 says: Limit to 5 results. The query itself should be pretty clear.



This would give this output:



Code:
+-------+------



| name? | kills |



+-------+------



| MathPi |? ? 99 |



| Slayer |? ? 66 |



| Z3fRaN |? ? 28 |



| Kwarde |? ? 16 |



| Playa? |? ? 2 |



+-------+------



It's alright, I've done it with Y_INI, just need to test it for now.
  Reply


Forum Jump: