![]() |
Scoreboard
So, I started working on a scoreboard script.
Here's what I have so far- PHP Code:
The only way to do this is another loop- but what do you guys think?? Can you think of an alternative & more robust method |
Basically what you want to do is create a sorted array?
Look into the sortByValue function. Quote:
PHP Code:
Quote:
|
no
With that system you're storing millions of variables - I only want it to store the top 25 scores p.s. love the 69 ;) |
That was just an example, change it to fit your needs :p
What you want to do seems simple enough, PHP Code:
|
sure
don't store more than 25 scores in the DB though |
I don't like DBNPC's being used like that anymore. I have had way to many problems with the DBNPC flags being reset randomly =/
|
Quote:
Try this. PHP Code:
|
Brilliant, thank you very much! (I repped you- you now have 3 bars! **** yeah)
Here's my final piece PHP Code:
|
Quote:
PHP Code:
|
Couldn't you just like, use SQL, have a database with each player + their scores, update the player entry and build the scoreboard using something like
SELECT * FROM myTable ORDER BY Stat_Blah ASC LIMIT 25 ? |
no, i don't want to store EVERY players score to only pull back the highest 25.
|
Yeah, but why? :3 seems nice to have the saves anyway and its a few bytes per player
|
Quote:
|
Why would you store unnecessary information that will never be used if you don't have to.
|
Well it has to be stored somewhere either way, SQL is nice for backups like that imo. Also you get a more central place to manage such info than the client vars provide.
|
why don't you just keep track of high scores on a notepad. if internet goes down u have hard copy
|
Quote:
It makes sense to store player-data in a central place where its easily accessible via a language made for accessing such entries |
Quote:
|
Quote:
|
Pros of SQL (some only apply if using a primarily SQL-based system, so probably not to all graal servers :p):
(Of course storing all data in NPC-flags is also a way, but then you end up having to write more potentially slower and buggier script code) |
Yea, but there's no need to create an SQL table for over a thousand players when all you really need is 25 of them.
|
Quote:
|
Quote:
|
Quote:
(am i missing something?) Anyway, my original point still is valid I guess: If you use SQL you have a much cleaner code and the < 1 MB you use to store data doesn't bother anyone ever. |
Quote:
(am i missing something?) Anyway, my original point still is valid I guess: If you use SQL you have a much cleaner code and the < 1 MB you use to store data doesn't bother anyone ever. |
I use SQL for most systems on Era. Works nicely.
|
SQL is great i use it mostly but at the same time it can easily be abused and bloat your db. If Snk only wanted the top 20 players why would he store and update over 3000 accounts. I feel for this reason his method is best, it is only maintaining the top 25 oppose of all 3000+ players. DB npcs are great for temp storage especially on situations like this.
|
Use SQL. Here is how I would do it.
When a new score comes in do a select on the database for the minimum score to get into the top20. PHP Code:
The only thing is you would have to do two queries to delete the min score from the database something like PHP Code:
PHP Code:
|
Quote:
|
Quote:
1,) Find the minimum score 2,) Add the score 3,) Delete old score I guess it's what you want to store. |
Quote:
Did you use another solution? I am curious on how you did it. |
Using SQL when you have a small fixed number of rows that you're not even performing real queries on doesn't make any sense.
If all you want is a list of the top 25 players, store them in an array in a DB NPC flag. There are built-in (fast) functions for sorting arrays, and performance is not an issue here anyway (but I'd be willing to bet this is faster than constantly shuffling things in/out of SQLite, anyway). The only way I see the code being simpler is if you store all players in a table, and use a query (SELECT .. ORDER BY .. LIMIT 25), which is how I would recommend doing it. |
| All times are GMT +2. The time now is 03:53 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.