Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 11-15-2014, 07:30 AM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
Scoreboard

So, I started working on a scoreboard script.

Here's what I have so far-
PHP Code:
const MAX_STATS 26;

function 
onCreated() {
  
this.registerStat("Rocks_Staff3""xAndrewx"4);
}

public function 
registerStat(temp.stattemp.pltemp.value) {
  if (
temp.stat != "Rocks_Staff3") return;
  
    
//Create place holders if no stats exist
  
if (this.("Stat_" temp.stat "_" 1) == null) {
    for (
temp.1temp.<= MAX_STATStemp.i++) {
      
this.("Stat_" temp.stat "_" temp.i) = {27 temp.i"(npc-server)""Place Holder""head19.png"};      
      
this.("Stat_PlayerCache_" temp.stat).add("(npc-server" temp.@")");
    }         
  }  
  
    
//Loop from lowest score to highest
  
for (temp.i=MAX_STATStemp.i>=1temp.i--) {
    
temp.data this.("Stat_" temp.stat "_" temp.i);

    
temp.score temp.data[0];
    
temp.owner temp.data[1];
    
      
//Not hit the lowest score- end the loop
    
if (temp.== MAX_STATS) {
      if (
temp.value <= temp.score) {
        break;
      }
    }
        
    if (
temp.value temp.score) {
        
//If it's the last entry, finally add it in!
      
if (temp.== MAX_STATS) continue;      
      
        
//Replace old stats with new score
      
this.("Stat_" temp.stat "_" @ (temp.1)) = temp.data;      
      
this.("Stat_PlayerCache_" temp.stat)[(temp.1)] = temp.owner;
            
        
//If they've beaten the high score
      
if (temp.== 1) {
        
this.("Stat_" temp.stat "_" temp.i) = {temp.valuetemp.plfindplayer(temp.pl).nickfindplayer(temp.pl).head};      
        
this.("Stat_PlayerCache_" temp.stat)[(temp.i)] = temp.pl;        
//        echo("-Beat High Score- Adding stat in at" SPC temp.i SPC "old-" @ temp.score @ ". new-" @ temp.value @ ".");      
      
}      
    } else {
        
//Replace the score where they should sit
      
this.("Stat_" temp.stat "_" @ (temp.1)) = {temp.valuetemp.plfindplayer(temp.pl).nickfindplayer(temp.pl).head};      
      
this.("Stat_PlayerCache_" temp.stat)[(temp.1)] = temp.pl;       
      break;
    }
  }

  
this.trigger("update""");

So, I'm wanting a system which only displays the player in the list once.

The only way to do this is another loop- but what do you guys think?? Can you think of an alternative & more robust method
__________________
Reply With Quote
  #2  
Old 11-15-2014, 01:47 PM
BlueMelon BlueMelon is offline
asdfg
BlueMelon's Avatar
Join Date: Sep 2008
Posts: 1,481
BlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to behold
Basically what you want to do is create a sorted array?

Look into the sortByValue function.

Quote:
TGraalVar.sortbyvalue(str, str, bool) - sorts an array, specify the variable of the array members which is compared, also the variable type and if it should be sorted ascending; variable type can be "string", otherwise it is sorted by floating point value
Example:
PHP Code:
function onCreated() {

  
temp.plScores = {
    {
"BlueMelon",9001},
    {
"snk",69},
    {
"BigMonster",1337},
    {
"supaman771",7331}
  };

  
temp.board null;
  for(
temp.plScore temp.plScores) {
    
temp.board.add(temp.plScore[0]); // acc
    
temp.board[temp.board.size() - 1].score temp.plScore[1]; // score
  
}

  
temp.board.sortByValue("score""float"false);

  echo(
"Scoreboard: ");
  for(
temp.i=0temp.i<temp.board.size(); temp.i++) {
    
temp.acc temp.board[temp.i];
    
temp.score temp.board[temp.i].score;
    echo(
temp.i+@". "@temp.acc SPC "with" SPC temp.score);
  }

which gives
Quote:
Scoreboard:
1. BlueMelon with 9001
2. supaman771 with 7331
3. BigMonster with 1337
4. snk with 69
__________________
http://i.imgur.com/OOJbW.jpg
Reply With Quote
  #3  
Old 11-15-2014, 01:49 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
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
__________________
Reply With Quote
  #4  
Old 11-15-2014, 02:15 PM
BlueMelon BlueMelon is offline
asdfg
BlueMelon's Avatar
Join Date: Sep 2008
Posts: 1,481
BlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to behold
That was just an example, change it to fit your needs

What you want to do seems simple enough,
PHP Code:
  temp.board= {25 values};
  
temp.board.sortdescending();

  
// add a new entry
  
temp.newEntry 123;
  
temp.lowest temp.board[temp.board.size()-1];
  if(
temp.newEntry temp.lowest) {
    
// delete lowest
    // add to board
    // re-sort
  
}
// display or whatever 
I can whip up another example later tonight if needed.
__________________
http://i.imgur.com/OOJbW.jpg
Reply With Quote
  #5  
Old 11-15-2014, 08:31 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
sure

don't store more than 25 scores in the DB though
__________________
Reply With Quote
  #6  
Old 11-16-2014, 03:23 AM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
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 =/
Reply With Quote
  #7  
Old 11-16-2014, 03:52 AM
BlueMelon BlueMelon is offline
asdfg
BlueMelon's Avatar
Join Date: Sep 2008
Posts: 1,481
BlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to behold
Quote:
Originally Posted by xAndrewx View Post
sure

don't store more than 25 scores in the DB though


Try this.
PHP Code:
/* Scoreboard system */

function onCreated() {
  
this.numEntrys 25;
  
clearBoard();

  
addScore("BlueMelon",9001);
  
addScore("snk",69);
  
addScore("BigMonster",1337);
  
addScore("supaman771",7331);

  
displayBoard();
}

function 
displayBoard() {
  for(
temp.i=0temp.i<this.board.size(); temp.i++) {
    echo(
temp.i+1 SPC this.board[temp.iSPC this.board[temp.i].score);
  }
}

function 
clearBoard() {
  
this.board = {};
  for(
temp.i=0temp.i<this.numEntrystemp.i++){
    
this.addScore("(npc server)"0);
  }
}

public function 
addScore(temp.acctemp.score) {
  
this.board.sortByValue("score""float"false);

  
temp.lowest this.board[this.board.size() -1];

  if(
this.board.size() < this.numEntrys){
    
this.board.add(temp.acc);
    
this.board[this.board.size() -1].score temp.score;
  }else if(
temp.score temp.lowest.score && temp.score 0) {
    
this.board.delete(this.board.size() -1);
    
this.board.add(temp.acc);
    
this.board[this.board.size() -1].score temp.score;
  }

  
this.board.sortByValue("score""float"false);

__________________
http://i.imgur.com/OOJbW.jpg
Reply With Quote
  #8  
Old 11-16-2014, 07:12 AM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
Brilliant, thank you very much! (I repped you- you now have 3 bars! **** yeah)

Here's my final piece
PHP Code:
const MAX_STATS 25;

function 
onCreated() {  
  
temp.statsize 5;
  
temp.stats getStat("PlantsPicked");
  for (
temp.0temp.5temp.i++) {
    global.
out(temp.stats[temp.i], "Debug");
  }
}

  
//Return Account, Score, {Nickname, Head, Hat}
public function getStat(stat) {
  for (
temp.0temp.MAX_STATStemp.++) {
    
temp.stats.add({this.("board_" temp.stat)[temp.i], this.("board_" temp.stat)[temp.i].scorethis.("board_" temp.stat)[temp.i].outfit}); 
  } 
  
  return 
temp.stats;
}

public function 
registerStat(statplscore) {  
    
//Create placeholders
  
if (this.("board_" temp.stat) == null) {
    echo(
"Clearing Board-" SPC temp.stat);
    
this.onClearBoard(temp.stat); 
  }
    
//Sort in descending order
  
this.("board_" temp.stat).sortByValue("score""float"false); 
  
    
//If they already have a score, just update it. No duplicates!
  
temp.found this.("board_" temp.stat).index(temp.pl);  
  if (
temp.found >= 0) {
    
this.("board_" temp.stat)[temp.found].score temp.score;

      
//Update outfit
    
temp.pla findplayer(temp.pl);
    if (
temp.pla != null
      
this.("board_" temp.stat)[this.("board_" temp.stat).size() -1].outfit = {temp.pla.nicktemp.pla.headtemp.pla.attr[1]};               
  } else {
      
//Board size
    
temp.board_size this.("board_" temp.stat).size();
  
      
//Get lowest score  
    
temp.lowest this.("board_" temp.stat)[temp.board_size -1];   
      
    if(
temp.board_size MAX_STATS){ 
      
this.("board_" temp.stat).add(temp.pl); 
      
this.("board_" temp.stat)[temp.board_size 1].score temp.score
    }else if(
temp.score temp.lowest.score && temp.score 0) { 
        
//Delete lowest score
      
this.("board_" temp.stat).delete(temp.board_size 1); 
        
        
//Store score
      
this.("board_" temp.stat).add(temp.pl);    
      
this.("board_" temp.stat)[this.("board_" temp.stat).size() -1].score temp.score
    
        
//Store outfit
      
temp.pla findplayer(temp.pl);
      if (
temp.pla != null
        
this.("board_" temp.stat)[this.("board_" temp.stat).size() -1].outfit = {temp.pla.nicktemp.pla.headtemp.pla.attr[1]};     
      
    } 
  }
  
this.("board_" temp.stat).sortByValue("score""float"false);   
  
  
this.trigger("update"""); 
}

  
//Clear stats (only called when creating a new stat)
function onClearBoard(stat) { 
  
this.("board_" temp.stat) = {}; 
  for(
temp.0temp.MAX_STATStemp.i++) { 
    
this.registerStat(temp.stat"(npc server)"1); 
  } 

__________________
Reply With Quote
  #9  
Old 11-16-2014, 07:15 AM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
Quote:
Originally Posted by scriptless View Post
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 =/
p.s. add this once you add / remove any variables

PHP Code:
this.trigger("update"); 
It saves the NPC
__________________
Reply With Quote
  #10  
Old 11-16-2014, 10:54 AM
Inari Inari is offline
Registered User
Join Date: Sep 2014
Posts: 47
Inari is on a distinguished road
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
?
Reply With Quote
  #11  
Old 11-16-2014, 04:43 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
no, i don't want to store EVERY players score to only pull back the highest 25.
__________________
Reply With Quote
  #12  
Old 11-16-2014, 06:06 PM
Inari Inari is offline
Registered User
Join Date: Sep 2014
Posts: 47
Inari is on a distinguished road
Yeah, but why? :3 seems nice to have the saves anyway and its a few bytes per player
Reply With Quote
  #13  
Old 11-17-2014, 01:42 AM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
Quote:
Originally Posted by xAndrewx View Post
p.s. add this once you add / remove any variables

PHP Code:
this.trigger("update"); 
It saves the NPC
Not always. We were doing this on the scoreboard on GK and it still had issues.
Reply With Quote
  #14  
Old 11-18-2014, 04:11 AM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
Why would you store unnecessary information that will never be used if you don't have to.
__________________
Reply With Quote
  #15  
Old 11-18-2014, 01:00 PM
Inari Inari is offline
Registered User
Join Date: Sep 2014
Posts: 47
Inari is on a distinguished road
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.
Reply With Quote
  #16  
Old 11-18-2014, 01:32 PM
Cubical Cubical is offline
Banned
Join Date: Feb 2007
Posts: 1,348
Cubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant future
why don't you just keep track of high scores on a notepad. if internet goes down u have hard copy
Reply With Quote
  #17  
Old 11-18-2014, 02:22 PM
Inari Inari is offline
Registered User
Join Date: Sep 2014
Posts: 47
Inari is on a distinguished road
Quote:
Originally Posted by Cubical View Post
why don't you just keep track of high scores on a notepad. if internet goes down u have hard copy
Possible, but that isn't very dynamic, and doesn't make much sense.
It makes sense to store player-data in a central place where its easily accessible via a language made for accessing such entries
Reply With Quote
  #18  
Old 11-18-2014, 02:33 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by Cubical View Post
why don't you just keep track of high scores on a notepad. if internet goes down u have hard copy
i also backup all my data to offsite stone tablets.
__________________
Quote:
Reply With Quote
  #19  
Old 11-18-2014, 02:33 PM
Tim_Rocks Tim_Rocks is offline
a true gentlemen
Tim_Rocks's Avatar
Join Date: Aug 2008
Location: USA
Posts: 1,863
Tim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to behold
Quote:
Originally Posted by Cubical View Post
why don't you just keep track of high scores on a notepad. if internet goes down u have hard copy
Cubical brings up an excellent point here.
__________________
Reply With Quote
  #20  
Old 11-18-2014, 03:17 PM
Inari Inari is offline
Registered User
Join Date: Sep 2014
Posts: 47
Inari is on a distinguished road
Pros of SQL (some only apply if using a primarily SQL-based system, so probably not to all graal servers ):
  • Easy access to all data
  • Made to store and request data (and has proven itself)
  • Doesn't break from staff editing the attributes
  • Better relational data management
among others

(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)
Reply With Quote
  #21  
Old 11-18-2014, 03:26 PM
Tim_Rocks Tim_Rocks is offline
a true gentlemen
Tim_Rocks's Avatar
Join Date: Aug 2008
Location: USA
Posts: 1,863
Tim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to behold
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.
__________________
Reply With Quote
  #22  
Old 11-18-2014, 03:38 PM
Inari Inari is offline
Registered User
Join Date: Sep 2014
Posts: 47
Inari is on a distinguished road
Quote:
Originally Posted by Tim_Rocks View Post
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.
Well, no direct /need/, except if you use SQL to begin with Which maybe graal servers should consider doing... I guess its more of a point of "hey, if you put your structure more around SQL you can make such things much much easier"~
Reply With Quote
  #23  
Old 11-18-2014, 03:53 PM
Cubical Cubical is offline
Banned
Join Date: Feb 2007
Posts: 1,348
Cubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant future
Quote:
Originally Posted by Inari View Post
Well, no direct /need/, except if you use SQL to begin with Which maybe graal servers should consider doing... I guess its more of a point of "hey, if you put your structure more around SQL you can make such things much much easier"~
Well, no direct /need/, except if you use SQL to begin with Which maybe graal servers should consider doing... I guess its more of a point of "hey, if you put your structure more around SQL you can make such things much much easier"~
Reply With Quote
  #24  
Old 11-18-2014, 03:57 PM
Inari Inari is offline
Registered User
Join Date: Sep 2014
Posts: 47
Inari is on a distinguished road
Quote:
Originally Posted by Cubical View Post
Well, no direct /need/, except if you use SQL to begin with Which maybe graal servers should consider doing... I guess its more of a point of "hey, if you put your structure more around SQL you can make such things much much easier"~
Well, no direct /need/, except if you use SQL to begin with Which maybe graal servers should consider doing... I guess its more of a point of "hey, if you put your structure more around SQL you can make such things much much easier"~
(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.
Reply With Quote
  #25  
Old 11-18-2014, 04:06 PM
Cubical Cubical is offline
Banned
Join Date: Feb 2007
Posts: 1,348
Cubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant future
Quote:
Originally Posted by Inari View Post
Well, no direct /need/, except if you use SQL to begin with Which maybe graal servers should consider doing... I guess its more of a point of "hey, if you put your structure more around SQL you can make such things much much easier"~
(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.
Well, no direct /need/, except if you use SQL to begin with Which maybe graal servers should consider doing... I guess its more of a point of "hey, if you put your structure more around SQL you can make such things much much easier"~
(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.
Reply With Quote
  #26  
Old 11-18-2014, 04:55 PM
Tim_Rocks Tim_Rocks is offline
a true gentlemen
Tim_Rocks's Avatar
Join Date: Aug 2008
Location: USA
Posts: 1,863
Tim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to behold
I use SQL for most systems on Era. Works nicely.
__________________
Reply With Quote
  #27  
Old 12-03-2014, 09:05 PM
Carlito Carlito is offline
Playerworld Admin
Join Date: Nov 2014
Posts: 2
Carlito is on a distinguished road
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.
Reply With Quote
  #28  
Old 12-11-2014, 11:02 PM
prozacboy666 prozacboy666 is offline
Registered User
Join Date: Mar 2002
Posts: 130
prozacboy666 will become famous soon enough
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:
SELECT MIN(scoreFROM myTable
If new score > min, insert new score into the database and delete the min score.
The only thing is you would have to do two queries to delete the min score from the database something like
PHP Code:
minId SELECT id FROM myTable WHERE score = (SELECT min(scoreFROM myTable)
DELETE FROM top20 WHERE id minId 
Then all you have to do is selects on that table if you are looking for the top20
PHP Code:
SELECT FROM top20 ORDER BY score DESC 
You probably could get the ID and delete it from the database all in one query but this should be fast enough.
Reply With Quote
  #29  
Old 12-12-2014, 01:12 AM
Elk Elk is offline
Sr Marketing Strategist
Elk's Avatar
Join Date: Nov 2005
Location: Deerland
Posts: 3,829
Elk has a brilliant futureElk has a brilliant futureElk has a brilliant futureElk has a brilliant futureElk has a brilliant futureElk has a brilliant futureElk has a brilliant future
Send a message via ICQ to Elk Send a message via AIM to Elk Send a message via MSN to Elk Send a message via Yahoo to Elk
Quote:
Originally Posted by fowlplay4 View Post
i also backup all my data to offsite stone tablets.
cuneiform <3
__________________
iEra IGN: *Elk (Darkshire)
iCla. IGN: *Elk (Darkshire)
iZone IGN: *Elk (Darkshire)




Reply With Quote
  #30  
Old 12-12-2014, 08:48 AM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
Quote:
Originally Posted by prozacboy666 View Post
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:
SELECT MIN(scoreFROM myTable
If new score > min, insert new score into the database and delete the min score.
The only thing is you would have to do two queries to delete the min score from the database something like
PHP Code:
minId SELECT id FROM myTable WHERE score = (SELECT min(scoreFROM myTable)
DELETE FROM top20 WHERE id minId 
Then all you have to do is selects on that table if you are looking for the top20
PHP Code:
SELECT FROM top20 ORDER BY score DESC 
You probably could get the ID and delete it from the database all in one query but this should be fast enough.
You'd need three queries.
1,) Find the minimum score
2,) Add the score
3,) Delete old score


I guess it's what you want to store.
__________________
Reply With Quote
  #31  
Old 12-12-2014, 05:13 PM
prozacboy666 prozacboy666 is offline
Registered User
Join Date: Mar 2002
Posts: 130
prozacboy666 will become famous soon enough
Quote:
Originally Posted by xAndrewx View Post
You'd need three queries.
1,) Find the minimum score
2,) Add the score
3,) Delete old score


I guess it's what you want to store.
I just find it easier because when you want to display the top20 scores, in SQL is does all the work for you and faster than getting all the results and then do some type of sorting function.

Did you use another solution? I am curious on how you did it.
Reply With Quote
  #32  
Old 12-14-2014, 05:49 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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.
__________________
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 11:59 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.