Good way to create top player system
#1

Hey there! So I've been thinking of creating a system with the top players which would get number of kills from each player and sort it so everyone on the server can see who's the best.
I'm not little bit more familiar with MySQL so I wanted to do something like this. There would be 'TopPlayers' table which would have two fields for now: Name and KillCount. When someone enters a command '/topplayers', they get a dialog with top players which was previously formatted so I don't have to run a query each time someone enters the command. I could maybe add a loop which would run every hour to update the list of the best players.
But I have to ask which way would be better: when a player kills someone, the table gets updated with the current kill count, or when the player leaves the server, the table gets updated. The second way would maybe be better so the table doesn't get updated each second, which could maybe reduce lag?
Feel free to tell me what do you guys think.
Reply
#2

I had experience with the second option, so... well there's a good side and a bad side

Good side:
It's called less frequently and hence quite efficient because a player can kill as much as they want but will leave the server only once.

Bad side:
Once in a while, when a player crashes (timeout), you may get bad results and/or corrupted data from them over OnPlayerDisconnect which will make them lose all the score they achieved since logged in which is damn annoying.

I addressed this issue by adding a timer (not to be called so frequently though, talking of minutes here) to backup all connected players, so if they crashed (bad side took place), they would lose less score (hopefully none).
Reply
#3

So, timer with, let's say, 15 minutes interval would be the best way to go. Thanks Khalid!
Reply
#4

Just use callback OnPlayerDeath or whatever.
As soon as someone kills another player, update your table.
You don't need a timer for that.
Suppose your timer has just executed and the next iteration is 15 minutes away.
Your player makes 5 more kills and leaves the server several minutes before the next timer iteration.

His variables are cleared upon leaving and those 5 kills have not been saved.

Just save whenever there is a kill.

You won't get lag if you use threaded queries.
Players don't kill 5 other players in a second.
Even then, sending 5 queries at once won't lag at all.

You could also retrieve the updated kill-list after each kill.
Using threaded queries, you send the query to sort the kill-list by mysql itself and it executes in the background.
When mysql has the result, it will call a callback in your script and you can simply read it and update your textdraws or whatever you use to display the ordered list.

Even when this happens every second, it won't lag.

Big MMORPG servers process alot more queries for 6000 players at once and it doesn't lag at all.
Surely mysql can handle your little server with only 50 players and a handful of queries every second.
Reply
#5

The MySQL server is built to handle large amount of queries, don't worry. In fact, that statistic is measured in "queries per second". Save immediately. I would even dare to save every single kill as a new row, rather than simply the count itself.
Reply
#6

Just update it every time the player dies.
Reply
#7

Okay. That seems like a more simpler option. Thanks!
Reply
#8

Quote:
Originally Posted by PowerPC603
View Post
Suppose your timer has just executed and the next iteration is 15 minutes away.
Your player makes 5 more kills and leaves the server several minutes before the next timer iteration.

His variables are cleared upon leaving and those 5 kills have not been saved.
He's gonna save them and execute queries over OnPlayerDisconnect in that case, so they are GOING TO be saved.
Reply
#9

Youre storing the top players kills in a separate table, and also keep every single players kills in another table?
Just use ORDER BY and LIMIT then to get your toplist from the normal player database, no need to save the same stuff again and again.
Reply
#10

Quote:
Originally Posted by Mauzen
View Post
Youre storing the top players kills in a separate table, and also keep every single players kills in another table?
Just use ORDER BY and LIMIT then to get your toplist from the normal player database, no need to save the same stuff again and again.
I haven't thought about this. Thanks Mauzen. This is how I'm gonna do it.
Thank you everyone for your answers!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)