ID:2041566
 
Code:
#define SCOREBOARD_BASE Overall_Lvl // Change this to whatever\
variable you want to base your scoreboard on


#define MAX_RANKS 20 // MAX_RANKS is the number of maximum entries\
the scoreboard can have, change this at will as it will not break anything\
in the library.


var/scoreboard/A_SB = new // Creates our scoreboard datum.
world/New()
..()
sleep(1)
A_SB.load()

world/Del()
A_SB.save()
..()



scoreboard
var/list/ranks
proc
save()
var/savefile/F = new("scoreboard.sav")
F["ranks"] << ranks
return 1

load()
var/savefile/F = new("scoreboard.sav")
if(F["ranks"])
F["ranks"] >> ranks
return 1
return 0
proc/Update(var/mob/M in world)
if(!M||!M.client)return
if(!ranks) ranks = list()
if(M.key in ranks)
ranks[M.key] = M.SCOREBOARD_BASE
UpdateRanks(M.key)
else
if(ranks.len < MAX_RANKS)
ranks[M.key] = M.SCOREBOARD_BASE
else
var/Key = ranks[20]
var/BASE = ranks[Key]
if(BASE > M.SCOREBOARD_BASE) return
ranks[Key] = M.key
ranks[M.key] = M.SCOREBOARD_BASE
var/INDEX
proc/UpdateRanks(key)
for()
var/BASE = ranks[key]
INDEX = ranks.Find(key)
var/NEWINDEX = INDEX - 1
if(NEWINDEX>MAX_RANKS||NEWINDEX<=0) break
var/NEWBASE = ranks[ranks[NEWINDEX]]
if(NEWBASE > BASE)
ranks.Swap(INDEX,NEWINDEX)
else break

proc/Display(mob/M)
var/counter=1
var/html= {"<head><title>A_Scoreboard</title></head><body style=\"background-color:black;\"><center><table border=2>
<th colspan=\"3\"><font color=white>Scoreboard library created by Andre-g1</font color></th>
<tr><td style=\"background-color: #666666;\"><center><font color=white><b>#</b></font color></center></td>
<td style=\"background-color: #666666;\"><center><font color=white><b>Name</b></font color></center></td>
<td style=\"background-color: #666666;\"><center><font color=white><b>Level</b></font color></center></td></tr>""}

for(var/Key in ranks)
counter++
var/Value = ranks[Key]
html += "<tr>[counter%2 ? "<td style=\"background-color: #666666;\">" : "<td>"]<center><font color=white>[INDEX]</font color></center></td>[counter%2 ? "<td style=\"background-color: #666666;\">" : "<td>"]<center><font color=white>[M.name]([Key])</font color></center></td>[counter%2 ? "<td style=\"background-color: #666666;\">" : "<td>"]<center><font color=white>[Value]</font color></center></td></tr>"
html += "</table></center></p>"
M << browse(html,"window=A_Scoreboard;can_resize=0;can_minimize=0")
mob/verb
Displayy()
// for(var/mob/m in world)
A_SB.Display(src) // Display the scoreboard to the user.

Update()
A_SB.Update(src) // Update the scoreboard


Problem description: Hi byond developers, im having a problem with a scoreboard library.

1st of all after add the code and edit it as i needed to use my values and save the scores in a sav file. Now the problem is that when i use my update verb (i tryed to when used the update verb look for all online clients in world so it would add all them and not just the player who uses the scoreboard as the library does (idk what i did but dosnt look for the online clients so just adds the one who uses the code.

2nd problem is that on the scoreboard dosnt display the real player name, displays the name of the one who executes the verb and the indexes are the same for everyone.

3th problem is that the scoreboard idk why dosnt order the ranks so a lvl 50 is above a 70?.

I uploaded a pic if it can help in my description of my problem sry for bad english...
http://postimg.org/image/el11y7dmn/
Okey better forget all what i said above could someone teach me what shoud i use to make my own scoreboard? I mean about the reference, how to check all the clients in world and add them to a list, after that check in the list every client score "level" after that would come the update the list ordering the players by higher level and for finish save the list with the values on a sav file.
So:
1. Create a Scoreboard List.
2. Update it adding players to it.
3. Order the players by higher to lower level.
4. Save/Load the list.
//To start i think that that datums would be the best.
Scoreboard // Scoreboard datum
var/list/sb = list() // We create a list for the scoreboard
var/maxlen = 10 // Displays the highest 10 players.
proc/UpdateSB(var/mob/Player/M in world) // We create a proc to update the list and add the players in world to it.
if(!M||!M.client)return // If the is not a mob and if the mob is not client return.
if(M in sb)return // If the mob is already in the list return.
else // If the client is not in the list
if(sb.len < maxlen) // If list length is lower than maxlength(10).
sb[M.Key]=M.Level // Adds to the list the player Key and his lvl if am not wrong.
else // If list length is higher than maxlength(10).
Code here... // Now i dont know how to continue how to add to the list just the higher level players

prob/ReoderSB()
Code Here... // I dont know how to add a number to each one in the list and order them from higher to lower level.

verb/Scoreboard(mob/Player/M)
html code here....

proc
Save() // Make a savefile and stor in SB list...
Load() // Load the SB list.
help pls
Just to be clear, the scoreboard is only supposed to show the 10 highest levels online, right?
Augh, who wrote that "library"? The whole point of a library is that you shouldn't have to make changes to it to use it. Don't use that code; it's horrible and should not be trusted.

Mostly I'm just not sure what question you're asking.
The new("level") is what determines what value/variable that scoreboard will accept.

max is the limit of items in the container/scoreboard.

mob
var level = 1

verb/Test()
global.scoreboard.add(src)
src << browse(global.scoreboard.display())

var/scoreboard/scoreboard = new("level")

scoreboard
New(id)
src.variable_id = id
var
list/container[] = new
max = 10
variable_id = null
proc
add(mob/MOB)
. = 0
var value = MOB.vars[src.variable_id]
for(var/string in src.container)
.++
if(MOB.vars[variable_id] > src.container[string])
src.container.Insert(.,MOB.key)
container[MOB.key] = value
break
if(container.len < 10)
container[MOB.key] = value
else if(container.len > max)
container = container.Copy(1,max+1)

display()
. = "<table border=TRUE>"
var pos = 0
for(var/string in src.container)
pos ++
. += "<tr><td>#[pos]</td><td>[string]</td><td>[src.container[string]]</td></tr>"
return . + "</table>"
sorry i coudnt check it till now, what i want for the scoreboard is not to check and add the top 10 players online, what i would like a list with all the players existing in game (online and offline), add the players to the list when they create the account and update the list with the names/levels when they logout and every 30 min, afert this the scoreboard will look in that list and add to the top 10 the 10 players with the higher value(level)
Using Kozumas scoreboard as temporally scoreboard, could you pls explain me every line in Add? i dont undersant something and i want to add a new proc to update the list becuase the add procs adds the same player every time he uses the Test verb :S