#leaderboard skript problem

1 messages · Page 1 of 1 (latest)

zenith horizon
#

im having a problem getting this leaderboard skript to work and i think it might be with sorting. please check my code and the image provided and see if you could tell me what ive done wrong

``command /leaderboard <text>:
trigger:
set {_stat} to arg-1
set {_validStats::*} to "kills", "deaths", "blocksBroken", "blocksPlaced", "distanceTraveled", "playtime", "amberMined"

    if {_validStats::*} does not contain {_stat}:
        send "&cInvalid statistic. Valid options: %{_validStats::*}%"
        stop

    delete {_data::*}

    loop all players:
        set {_uuid} to uuid of loop-player
        set {_val} to {%{_stat}%.%loop-player%}
        if {_val} is not set:
            set {_val} to 0
        set {_data::%loop-player%} to {_val}

    loop all offline players:
        set {_uuid} to uuid of loop-offlineplayer
        set {_val} to {%{_stat}%.%loop-offlineplayer%}
        if {_val} is not set:
            set {_val} to 0
        set {_data::%loop-offlineplayer%} to {_val}
        send {_val} to all players

    set {_sorted::*} to {_data::*}
    set {_sorted::*} to sorted {_data::*}

    send "&6Top 10 %{_stat}%:"
    set {_rank} to 0
    loop {_sorted::*}:
        add 1 to {_rank}
        send "&e%{_rank}%. %loop-index%: &f%loop-value%"
        if {_rank} is 10:
            stop loop

    
    set {_me} to player
    set {_pyRank} to 0
    set {_i} to 0
    loop {_sorted::*}:
        add 1 to {_i}
        if loop-index is {_me}:
            set {_pyRank} to {_i}
            stop loop

    if {_pyRank} > 0:
        send "&bYour rank in %{_stat}%: %{_pyRank}%"
    else:
        send "&bYou have no rank in %{_stat}%."

``

#

woah i kinda messed up pasting the code

zenith horizon
#
    trigger:
        set {_stat} to arg-1
        set {_validStats::*} to "kills", "deaths", "blocksBroken", "blocksPlaced", "distanceTraveled", "playtime", "amberMined"

        if {_validStats::*} does not contain {_stat}:
            send "&cInvalid statistic. Valid options: %{_validStats::*}%"
            stop

        delete {_data::*}

        loop all players:
            set {_uuid} to uuid of loop-player
            set {_val} to {%{_stat}%.%loop-player%}
            if {_val} is not set:
                set {_val} to 0
            set {_data::%loop-player%} to {_val}

        loop all offline players:
            set {_uuid} to uuid of loop-offlineplayer
            set {_val} to {%{_stat}%.%loop-offlineplayer%}
            if {_val} is not set:
                set {_val} to 0
            set {_data::%loop-offlineplayer%} to {_val}
            #send "%loop-offlineplayer% %{_val}%" to all players

        set {_sorted::*} to {_data::*}
        set {_sorted::*} to sorted {_data::*}
        
        loop {_sorted::*}:
            send "%loop-value%" to all players

        send "&6Top 10 %{_stat}%:"
        set {_rank} to 0
        loop {_sorted::*}:
            add 1 to {_rank}
            send "&e%{_rank}%. %loop-index%: &f%loop-value%"
            if {_rank} is 10:
                stop loop

        
        set {_me} to player
        set {_pyRank} to 0
        set {_i} to 0
        loop {_sorted::*}:
            add 1 to {_i}
            if loop-index is {_me}:
                set {_pyRank} to {_i}
                stop loop

        if {_pyRank} > 0:
            send "&bYour rank in %{_stat}%: %{_pyRank}%"
        else:
            send "&bYou have no rank in %{_stat}%."
lean tide
#

a few things.

"set {_val} to {%{_stat}%.%loop-offlineplayer%}"
Why are you not using lists originally? Then you could just use sorted indices..

  1. Looping offline players loops pnline players as well so you dont need to do both
rare osprey
#
  1. You set the {_uuid} variable, but never used it
zenith horizon
#

but thats not the problem