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.stat, temp.pl, temp.value) {
if (temp.stat != "Rocks_Staff3") return;
//Create place holders if no stats exist
if (this.("Stat_" @ temp.stat @ "_" @ 1) == null) {
for (temp.i = 1; temp.i <= MAX_STATS; temp.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.i @")");
}
}
//Loop from lowest score to highest
for (temp.i=MAX_STATS; temp.i>=1; temp.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.i == 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.i == MAX_STATS) continue;
//Replace old stats with new score
this.("Stat_" @ temp.stat @ "_" @ (temp.i + 1)) = temp.data;
this.("Stat_PlayerCache_" @ temp.stat)[(temp.i + 1)] = temp.owner;
//If they've beaten the high score
if (temp.i == 1) {
this.("Stat_" @ temp.stat @ "_" @ temp.i) = {temp.value, temp.pl, findplayer(temp.pl).nick, findplayer(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.i + 1)) = {temp.value, temp.pl, findplayer(temp.pl).nick, findplayer(temp.pl).head};
this.("Stat_PlayerCache_" @ temp.stat)[(temp.i + 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