Thread: Scoreboard
View Single Post
  #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.i = 0; temp.i < 5; temp.i++) {
    global.
out(temp.stats[temp.i], "Debug");
  }
}

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

public function 
registerStat(stat, pl, score) {  
    
//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.nick, temp.pla.head, temp.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.nick, temp.pla.head, temp.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.i = 0; temp.i < MAX_STATS; temp.i++) { 
    
this.registerStat(temp.stat, "(npc server)", 1); 
  } 
} 
__________________
Reply With Quote