ID:273656
 
Hey, I know how to do a scoreboard in game but what I want to do is make a scoreboard that would update and place people correctly. For example lets say I'm in first place with like 1000 points 2nd place person has 900 points . Then I do something stupid and lose 200 points the scoreboard still shows me as first cause it doesn't update it just checks for higher scores and doesn't check for lower ones. If you need the code I had used just say so and ill post it
You delete the entry, then send the new one.
"Sending an empty text string for the fields will erase the scores for that key."
In response to Pirion
I ment ingame not on the byond HUB
In response to Inferno L Flames
Depends on you you have your scoreboard set up... you of all people should know this. You were one of the ones who helped me get started coding. If you have it like most anime games that will be hard to do since the score isn't saved in a file. the best method would be to save and load scores in a scores file using arrays and such. that way you can subtract and add whenever you need it.
In response to Leur
Never been too good at arrays but I've been tinkering with them recently. I don't know why I didnt think of using arrays I mean if I can make a buddy list that shows when people are online and offline i can do a highscore board.
In response to Inferno L Flames
an array like below along with a simple sort function will get you what you need.

mob/var/list/arraytosort = list("item1"=100,"item2"=200,"item3"=900,"item4"=50, "item5"=150)
mob/var/list/sortlist = new()

mob/verb/sortarray()
var/key = null
while(arraytosort.len>=1)
for(var/x in arraytosort)
if(!key)
key = x
src << "Debug : [x] = [arraytosort[x]]"
if(arraytosort[key]>arraytosort[x])
src << "Debug : [x] = [arraytosort[x]]"
key = x
sortlist[key] = arraytosort[key]
arraytosort.Remove(key)
key = null
for(var/x in sortlist)
src << "List: [x] = [sortlist[x]]"
In response to Pirion
Ok I'm starting to get it I got it to order the stuff from highest to lowest instead of the other way around but the problem is not is getting it read every body and not only update for people online if i can get it to do that i can handle the rest
In response to Inferno L Flames
Ok I found a tutorial that pretty much does what I need it to do but I cant figure out how to add more variables. Ugh I'm so bad with arrays

//Scores



proc
scoreboard_add(name,score)
if(!name)return
if(!score)return

if(score >= 1e+20)
score = 1e+1000

if(findtext("[scoretext]","[name]"))
var/a
var/n = 0
var/z
var/out
for(var/i = 1, i <= length(scoretext), i++)
if(!n)
z = length(name) + 1
a = copytext(scoretext, i, i+z)
if(a == "[name]=")//replace text with new score.
i += z
n = 1
else
a = copytext(scoretext, i, i+1)
out += a
else
out +="[name]=[num2text(round(score),100)]&"
i = findtext3("[scoretext]","&",i)
n = 0
if(out)
scoretext = out
scorelist = params2list(scoretext)
return

scoretext += "[name]=[num2text(round(score),100)]&"
scorelist = params2list(scoretext)

changeit(n)
if(findtext(n,"INF"))
n = 1e+1000
return n
else
n = text2num("[n]")
return n

showscoreboard()
scorelist = params2list(scoretext)
var/html="<center><TABLE BORDER=1><TR><TH><html><BODY><center><h1><U><font color=yellow>Scoreboard<font color=white></u></h1><TABLE CELLSPACING=10>"
html+="<tr><th><B>#</th><th>Name</th><th>Score</th></tr>\n<br>"
var/b
var/c
var/i
while(scorelist.len)
for(var/x in scorelist)
if(changeit("[scorelist[x]]") > b)
b = changeit("[scorelist[x]]")
c = x
i ++
var/n = "[scorelist[c]]"
html+="<tr><td><u><center>[i]\th</center></td><td></u><center>[c]</center></td><td><center>[n]</center></td></tr>\n"
scorelist -= c
b = null
c = null

if(!scorelist.len)
scorelist = params2list(scoretext)
var/scoreboardtitle={"<STYLE>BODY {background: black; color: white}</STYLE><head><title>Scoreboard</title></head></body>"}
return "[scoreboardtitle][html]"

findtext3(hay,needle,start)
if(hay == null||needle == null) return 0
var/i = 1
if(start) i = start
var/b = ""
var/end = length(hay)
while(i < (end - length(needle)+2))
b = copytext(hay,i,length(needle)+i)
if(b == needle)
return i
else
i ++
return 0
In response to Inferno L Flames
That is how to do it with params, prob not the best way to do it in my opinion.

Using the below, the add_scores_proc uses a list of lists to add the following for any entry:

scores[player name]["rank"] is a rank
scores[player name]["points"] are points earned

you can add as many as you want of any name, and as long as the first set of brackets are the player name (or something to link them together)

scores[player name]["level"]
scores[player name]["tiredness"]
etc..

to sort this at any time, you would save it and load it, all entries are accessible even when players are not online.

The way this is coded, you would have to load all scores every time. To update only existing, you would want to check scores[player name] is a list. If it is, then just update (without adding a new() list.)

var/list/scores = list()

mob/verb/add_score(player as text)
var/points = rand(50,10000)
var/rank = pick(list("Loozer!","TaskMaster","Other"))
src << browse(add_scores_proc(player,points,rank))

proc/generate_html()
var/html = "<html><table><tr><th>Player</th><th>Score</th><th>Rank</th></tr>"
for(var/x in scores)
html += "<tr><td>[x]</td><td>[scores[x]["points"]]</td><td>[scores[x]["rank"]]</td></tr>"
html +="</table></html>"
return html

proc/add_scores_proc(var/player,var/points,var/rank)
scores[player] = new/list()
scores[player]["points"] = points
scores[player]["rank"] = rank
world << "Added [scores[player]["points"]] points to [player]."
scores = sort_scores()
return generate_html()
proc/sort_scores()
var/list/new_list = new()
var/key = null
while(scores.len>=1)
for(var/x in scores)
if(!key)
key = x
if(scores[key]["points"]<scores[x]["points"])
key = x
new_list[key] = scores[key]
scores.Remove(key)
key = null
return new_list
In response to Pirion
really silly question but then to show it all i would have to do is make a browser with the set HTML right?
In response to Inferno L Flames
Yes, like I added in the example.
src << browse(add_scores_proc(player,points,rank))//send to browser
proc/generate_html()
var/html = "<html><table><tr><th>Player</th><th>Score</th><th>Rank</th></tr>"
for(var/x in scores)
html += "<tr><td>[x]</td><td>[scores[x]["points"]]</td><td>[scores[x]["rank"]]</td></tr>"
html +="</table></html>"
return html // return browser friendly format.