ID:264310
 
Code:
var/list/rankholder1 = list("Player"="Someone","Level"=2000)
var/list/rankholder2 = list("Player"="Someone","Level"=2000)
var/list/rankholder3 = list("Player"="Someone","Level"=2000)
mob
verb
View_Rank()
var/p
var/savefile/Rankers = new("Rankers.sav")
Rankers["rankholder1"] >> rankholder1
Rankers["rankholder2"] >> rankholder2
Rankers["rankholder3"] >> rankholder3
for(var/i=1,i<=rankholder1.len,i++)
p = rankholder1[i]
src<< "<b>One: [p] = [rankholder1[p]]<br><br></b>"
for(var/i=1,i<=rankholder2.len,i++)
p = rankholder2[i]
src<< "<b>One: [p] = [rankholder2[p]]<br><br></b>"
for(var/i=1,i<=rankholder3.len,i++)
p = rankholder3[i]
src<< "<b>One: [p] = [rankholder3[p]]<br><br></b>"
Test_Rank()
var/savefile/Rankers = new("Rankers.sav")
if(rankholder1.len)
if(src.level>rankholder1["Level"])
rankholder1["Player"] = "[src]"
rankholder1["Level"] = src.level
Rankers["rankholder1"] << rankholder1
src.status = "Captain"
src.squad = "One"
return
if(rankholder2.len)
if(src.level>rankholder2["Level"])
rankholder2["Player"] = "[src]"
rankholder2["Level"] = src.level
Rankers["rankholder2"] << rankholder2
src.status = "Captain"
src.squad = "Two"
return
if(rankholder3.len)
if(src.level>rankholder3["Level"])
rankholder3["Player"] = "[src]"
rankholder3["Level"] = src.level
Rankers["rankholder3"] << rankholder3
src.status = "Captain"
src.squad = "Three"
return


Problem description:
Well, I'm attempting to implement a Ranking system that's completely automatic, and I have the feeling I'm going at this horribly wrong. What I'm trying to do is basically this, but 46 times (its a Bleach game taking account 13 Captains, 13 Lieutenants and 20 Other ranks) which ends up being 46 some odd vars, another 46 lines for just loading up each var, Basically it seems like its being "Over coded". Well basically what I'm asking is if there is a better way to do this.


Can you please give an example of what you are trying to achieve? (eg that code taking into account 2 or 3 ranks?) Because I don't quite understand what you want to do.
In response to Immibis
Ehh, I guess I didn't explain myself enough. I'm trying to do an automatic ranking system. There are 46 different ranks though, So I would have to do that basically 46 Different Times. I'm trying to see if there is a better way to do that....lol
Not quite sure what you're doing, but depending on what it is, here are three things that might be able to help you:
In response to Popisfizzy
Although those were all useful, I don't believe I can adapt any of those to work for exactly what I'm trying to do.
In response to King killer 113711
I would do it like this:

For each player:
    If the list is empty, add the player to the list.
    If their score is better than the first player in the list's score, then add them to the front of the list.
    If their score is worse than the last player's score:
        If the length of the list is less than the number of players you want ranked, then add them to the end of the list.
        Otherwise, this player is not ranked.
    If their score is between the first player's score and the last player's score, find the first player in the list whose
    score is worse than this player's score, and insert them before that player. If this makes the list longer than the
    number of players you want ranked, remove the last player from the list.


Since that probably looks very complicated, here's some code (which I haven't tested so it may have problems):
var/const/MAX_RANKINGS = 20

proc/RankPlayers()
var/mob/m
var/mob/temp
var/k
var/list/rankings = list()
for(m in world)
if(m.client)
if(rankings.len == 0)
rankings.Add(m)
continue
temp = rankings[1]
if(m.score > temp.score)
rankings.Insert(1, m)
continue
temp = rankings[rankings.len]
if(m.score < temp.score)
if(rankings.len < MAX_RANKINGS)
rankings.Add(m)
continue
for(k = 1, k <= rankings.len, k++)
temp = rankings[k]
if(m.score > temp.score)
rankings.Insert(k, m)
if(rankings.len > MAX_RANKINGS)
rankings.len = MAX_RANKINGS
break
return rankings
In response to Immibis
Immibis wrote:
I would do it like this:

For each player:If the list is empty, add the player to the list.If their score is better than the first player in the list's score, then add them to the front of the list.If their score is worse than the last player's score:If the length of the list is less than the number of players you want ranked, then add them to the end of the list.Otherwise, this player is not ranked.If their score is between the first player's score and the last player's score, find the first player in the list whosescore is worse than this player's score, and insert them before that player. If this makes the list longer than thenumber of players you want ranked, remove the last player from the list.

Since that probably looks very complicated, here's some code (which I haven't tested so it may have problems):
> var/const/MAX_RANKINGS = 20
>
> proc/RankPlayers()
> var/mob/m
> var/mob/temp
> var/k
> var/list/rankings = list()
> for(m in world)
> if(m.client)
> if(rankings.len == 0)
> rankings.Add(m)
> continue
> temp = rankings[1]
> if(m.score > temp.score)
> rankings.Insert(1, m)
> continue //error: bad argument definition
> temp = rankings[rankings.len]
> if(m.score < temp.score)
> if(rankings.len < MAX_RANKINGS)
> rankings.Add(m)
> continue
> for(k = 1, k <= rankings.len, k++)
> temp = rankings[k]
> if(m.score > temp.score)
> rankings.Insert(k, m)
> if(rankings.len > MAX_RANKINGS)
> rankings.len = MAX_RANKINGS
> break
> return rankings
>
>
In response to Immibis
No need to use a const var when you can just use a define. It'd look like this:

#define MAX_RANKINGS 20


And it'd be used the same way.
In response to Mizukouken Ketsu
Compiles fine for me, except for an inconsistent indentation error on the last line where there's an extra space. (which I've edited my post to fix)
In response to King killer 113711
Well then, can you expand on what you want? You stated you want 46 ranks (or something), but that's about all you said. There are a lot of different things that you could want.
In response to Immibis
o.O I made a rookie mistake xD I forgot to name the proc haha. My bad. ^-^;
I've edited my code to show with more then one rank done.
In response to King killer 113711
Change the rankholder1..rankholder3 variables into an array and loop over it.
In response to Immibis
How exactly would I go about doing this? ehh, Sounds like a stupid question, but the way I tried was the only way I could think of to do it.
Bleach eh?

You wouldn't need such a long code for this type of code, You should talk to Gokaumasaki, he did something similar to yours.

mob
proc
test_rank()
if(src.level >= (level number))
if(src.race == "(race)")
src.rank = "rank"

Obviously that's not the full code, but yours should be similar to this. To get it to actually work you need implant null, and many other vars.


In response to Rasengan3oo4
Lmao I helped him with that (Hahah =]) && Mines a bit more advanced then his... x.x
In response to King killer 113711
Lol, he got me thinking, that he fully developed it.