Points leaderboard broken

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

Wolfy

New Member
Dec 26, 2019
5
1
3
23
Hey, I've been using that sorting method to make a leaderboard that shows the 5 players that have the most points (you get points on kill, events, staying on the server, etc.) and I've noticed that some players had enough points to be in the leaderboard but they weren't.

My code:

Code:
import:
    java.util.ArrayList
    java.util.Collections
    java.util.Map$Entry
    ch.njol.skript.variables.Variables
 
expression replace values %strings% with %strings% in %string%:
    get:
        set {_string} to expression-3
        loop expressions-1:
            add 1 to {_index}
            replace all "%loop-value%" with "%{_index}th element of expressions-2%" in {_string}
        return {_string}
 
plural expression [the] (1¦(highest|top)|2¦(lowest|last)) %integer% values of %objects% [formatted] as %string%:
    get:
        set {_list} to new ArrayList(Variables.getVariable(raw expressions-2.getName().toString(event), event, raw expressions-2.isLocal()).entrySet())
        {_list}.sort(Entry.comparingByValue())
        if parse mark = 1:
            Collections.reverse({_list})
        loop ...{_list}:
            "%loop-value.getValue()%" is not "0"
            add 1 to {_index}
            set {_sorted::%{_index}%} to replace values "@place", "@index" and "@value" with "%{_index}%", "%loop-value.getKey()%" and "%loop-value.getValue()%" in expression-3
            {_index} = expression-1
            stop loop
        return {_sorted::*}

on load:
    loop 5 times:
        set {lb::%loop-value%::*} to 0 and "Not catched yet!"
        
every minute:
    make console execute command "/refreshlb"

command /refreshlb:
    permission: *
    trigger:
        async:
            loop {points::*}:
                set {_points::%loop-index parsed as offline player%} to loop-value
            set {_lb::*} to the highest 5 values of {_points::*} as "@place @index @value"
            loop 5 times:
                set {lb::%loop-value%::*} to 0 and "No one!"
            loop {_lb::*}:
                if ("%loop-index%" parsed as integer) is between 5 - (5 - 1) and 5:
                    set {_lv::*} to loop-value split at " "
                    set {_lv::3} to "%{_lv::3}%" parsed as a number
                set {_lv::2} to "%{_lv::2}%" parsed as offline player
                set {lb::%loop-index%::*} to {_lv::3} and {_lv::2}

command /leaderboard:
    trigger:
        loop 5 times:
            send "&9##%loop-value% &9%{lb::%loop-value%::2}% &f- %{lb::%loop-value%::1}%"
        send "&6You currently have &6&l%{points::%player's uuid%}% &6points."

How I add points:


Code:
on join:
    if {points::%uuid of player%} is not set:
        set {points::%uuid of player%} to 0

when you should gain points:
    add x to {points::%uuid of player%}

What am I doing wrong?
 
Status
Not open for further replies.