Solved Points Leaderboard

  • 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.

07L

Member
Feb 23, 2019
43
0
0
23
I have tried to think how I would make a leaderboard, but I cant get my head round how. I made a points system, it works fine and fully. But how would I make a leaderboard with the command /points leaderboard.
Here's my current points file code (I haven't started the leaderboard yet as I couldn't figure out how and mess up the code).

Code:
options:

    prefix: &8[&eAnimeme&8]

variables:
    {points.%player%} = 0

command /points [<text>] [<offline player>] [<text>]:
    trigger:
        if player has permission "animeme.pointsadmin":
            if arg-1 is set:
                if arg-1 is "give":
                    if arg-2 is set:
                        if arg-2 has played before:
                            if arg-3 is set:
                                if (arg-3 parsed as num) is set:
                                    set {_amount} to arg-3 parsed as a number
                                    add {_amount} to {points.%arg-2%}
                                    send message "{@prefix} &7Successfully added &c%arg-3% &7to &6%arg-2%&7's &7points!"
                                else:
                                    send message "{@prefix} &cInvalid argument! You must specify a valid number to give."                              
                            if arg-3 is not set:
                                send message "{@prefix} &cInvalid argument! Usage: &7/points give (player) (amount)"
                        if arg-2 has not played before:
                            send message "{@prefix} &cPlayer has not played before!"
                    if arg-2 is not set:
                        send message "{@prefix} &cInvalid argument! Usage: &7/points give (player) (amount)"
                else if arg-1 is "clear":
                    if arg-2 is set:
                        if arg-2 has played before:
                            set {points.%arg-2%} to 0
                            send message "{@prefix} &6%arg-2%&7's points have been cleared!"
                        if arg-2 has not played before:
                            send message "{@prefix} &cPlayer has not played before!"
                    if arg-2 is not set:
                        send message "{@prefix} &cInvalid argument! Usage: &7/points clear (player) "
                else if arg-1 is "remove":
                    if arg-2 is set:
                        if arg-2 has played before:
                            if arg-3 is set:
                                if (arg-3 parsed as num) is set:
                                    set {_amount} to arg-3 parsed as a number
                                    if {_amount} is smaller than or equal to {points.%arg-2%}:
                                        if {points.%arg-2%} is equal to 0:
                                            send message "{@prefix} &cThis player has no points to be removed!"
                                        else:
                                            subtract {_amount} from {points.%arg-2%}
                                            send message "{@prefix} &7Successfully took &c%arg-3% &7points from &6%arg-2%&7!"
                                    else:
                                        send message "{@prefix} &cThat number is bigger than the player's amount of points!"
                                else:
                                    send message "{@prefix} &cInvalid argument! You must specify a valid number to remove."                              
                            if arg-3 is not set:
                                send message "{@prefix} &cInvalid argument! Usage: &7/points give (player) (amount)"
                        if arg-2 has not played before:
                            send message "{@prefix} &cPlayer has not played before!"
                    if arg-2 is not set:
                        send message "{@prefix} &cInvalid argument! Usage: &7/points give (player) (amount)"
                else if arg-1 is "set":
                    if arg-2 is set:
                        if arg-2 has played before:
                            if arg-3 is set:
                                if (arg-3 parsed as num) is set:
                                    set {points.%arg-2%} to arg-3 parsed as a number
                                    if {points.%arg-2%} is equal to 1:
                                        send message "{@prefix} &7Successfully set &6%arg-2%&7's points to &a%arg-3% &apoint&7!"
                                    else:
                                        send message "{@prefix} &7Successfully set &6%arg-2%&7's points to &a%arg-3% &apoints&7!"
                                else:
                                    send message "{@prefix} &cInvalid argument! You must specify a valid number to set."                              
                            if arg-3 is not set:
                                send message "{@prefix} &cInvalid argument! Usage: &7/points give (player) (amount)"
                        if arg-2 has not played before:
                            send message "{@prefix} &cPlayer has not played before!"
                    if arg-2 is not set:
                        send message "{@prefix} &cInvalid argument! Usage: &7/points give (player) (amount)"
                else:
                    send message "{@prefix} &cInvalid argument! Usage: &7/points (give/clear/remove/set) (player) (amount)"
            if arg-1 is not set:
                send message "{@prefix} &7You have &a%{points.%player%}% &apoints&7."      
        if player does not have permission "animeme.pointsadmin":
            send message "{@prefix} &7You have &a%{points.%player%}% &apoints&7."
 
I have tried to think how I would make a leaderboard, but I cant get my head round how. I made a points system, it works fine and fully. But how would I make a leaderboard with the command /points leaderboard.
Here's my current points file code (I haven't started the leaderboard yet as I couldn't figure out how and mess up the code).

Code:
options:

    prefix: &8[&eAnimeme&8]

variables:
    {points.%player%} = 0

command /points [<text>] [<offline player>] [<text>]:
    trigger:
        if player has permission "animeme.pointsadmin":
            if arg-1 is set:
                if arg-1 is "give":
                    if arg-2 is set:
                        if arg-2 has played before:
                            if arg-3 is set:
                                if (arg-3 parsed as num) is set:
                                    set {_amount} to arg-3 parsed as a number
                                    add {_amount} to {points.%arg-2%}
                                    send message "{@prefix} &7Successfully added &c%arg-3% &7to &6%arg-2%&7's &7points!"
                                else:
                                    send message "{@prefix} &cInvalid argument! You must specify a valid number to give."                             
                            if arg-3 is not set:
                                send message "{@prefix} &cInvalid argument! Usage: &7/points give (player) (amount)"
                        if arg-2 has not played before:
                            send message "{@prefix} &cPlayer has not played before!"
                    if arg-2 is not set:
                        send message "{@prefix} &cInvalid argument! Usage: &7/points give (player) (amount)"
                else if arg-1 is "clear":
                    if arg-2 is set:
                        if arg-2 has played before:
                            set {points.%arg-2%} to 0
                            send message "{@prefix} &6%arg-2%&7's points have been cleared!"
                        if arg-2 has not played before:
                            send message "{@prefix} &cPlayer has not played before!"
                    if arg-2 is not set:
                        send message "{@prefix} &cInvalid argument! Usage: &7/points clear (player) "
                else if arg-1 is "remove":
                    if arg-2 is set:
                        if arg-2 has played before:
                            if arg-3 is set:
                                if (arg-3 parsed as num) is set:
                                    set {_amount} to arg-3 parsed as a number
                                    if {_amount} is smaller than or equal to {points.%arg-2%}:
                                        if {points.%arg-2%} is equal to 0:
                                            send message "{@prefix} &cThis player has no points to be removed!"
                                        else:
                                            subtract {_amount} from {points.%arg-2%}
                                            send message "{@prefix} &7Successfully took &c%arg-3% &7points from &6%arg-2%&7!"
                                    else:
                                        send message "{@prefix} &cThat number is bigger than the player's amount of points!"
                                else:
                                    send message "{@prefix} &cInvalid argument! You must specify a valid number to remove."                             
                            if arg-3 is not set:
                                send message "{@prefix} &cInvalid argument! Usage: &7/points give (player) (amount)"
                        if arg-2 has not played before:
                            send message "{@prefix} &cPlayer has not played before!"
                    if arg-2 is not set:
                        send message "{@prefix} &cInvalid argument! Usage: &7/points give (player) (amount)"
                else if arg-1 is "set":
                    if arg-2 is set:
                        if arg-2 has played before:
                            if arg-3 is set:
                                if (arg-3 parsed as num) is set:
                                    set {points.%arg-2%} to arg-3 parsed as a number
                                    if {points.%arg-2%} is equal to 1:
                                        send message "{@prefix} &7Successfully set &6%arg-2%&7's points to &a%arg-3% &apoint&7!"
                                    else:
                                        send message "{@prefix} &7Successfully set &6%arg-2%&7's points to &a%arg-3% &apoints&7!"
                                else:
                                    send message "{@prefix} &cInvalid argument! You must specify a valid number to set."                             
                            if arg-3 is not set:
                                send message "{@prefix} &cInvalid argument! Usage: &7/points give (player) (amount)"
                        if arg-2 has not played before:
                            send message "{@prefix} &cPlayer has not played before!"
                    if arg-2 is not set:
                        send message "{@prefix} &cInvalid argument! Usage: &7/points give (player) (amount)"
                else:
                    send message "{@prefix} &cInvalid argument! Usage: &7/points (give/clear/remove/set) (player) (amount)"
            if arg-1 is not set:
                send message "{@prefix} &7You have &a%{points.%player%}% &apoints&7."     
        if player does not have permission "animeme.pointsadmin":
            send message "{@prefix} &7You have &a%{points.%player%}% &apoints&7."

Use list variables for player data so you can sort them into an order. Take a look at this tutorial I made on making a leaderboard:
https://forums.skunity.com/threads/sorting-method-toplists.9931/
 
Can you help me? I'm completely stuck on your example.
Make sure you have skript-mirror.
1. Do not store the player's points in a non list variable. Store it in a list, example: {points::%arg 2%}
2. Use the expressions shown in the post:
code_language.skript:
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::*}

command /testsort:
    trigger:
        set {TopPoints::*} to the highest (size of {points::*}) values of {points::*} as "&e@place. &b@index &7- &6@value"

3. {TopPoints::*} will contain all the players, their places, and the amount of points they have each in one string.

Once again this is just an example. You can make it however you like.
 
Make sure you have skript-mirror.
1. Do not store the player's points in a non list variable. Store it in a list, example: {points::%arg 2%}
2. Use the expressions shown in the post:
code_language.skript:
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::*}

command /testsort:
    trigger:
        set {TopPoints::*} to the highest (size of {points::*}) values of {points::*} as "&e@place. &b@index &7- &6@value"

3. {TopPoints::*} will contain all the players, their places, and the amount of points they have each in one string.

Once again this is just an example. You can make it however you like.
Thank you, it works almost perfectly. I have two questions though,
1) Is it possible to make it display the players name with the capital letters in correct spaces?
2) Is there a way to make it update when I clear the players points? (see image)
upload_2019-11-12_19-43-54.png
 
Thank you, it works almost perfectly. I have two questions though,
1) Is it possible to make it display the players name with the capital letters in correct spaces?
2) Is there a way to make it update when I clear the players points? (see image)View attachment 3951
Yes there is. You can change this line of code in the expression for sorting:
code_language.skript:
set {_sorted::%{_index}%} to replace values "@place", "@index" and "@value" with "%{_index}%", "%loop-value.getKey()%" and "%loop-value.getValue()%" in expression-3

Change it to this:
code_language.skript:
set {_sorted::%{_index}%} to replace values "@place", "@index" and "@value" with "%{_index}%", "%(loop-value.getKey()) parsed as offline player%" and "%loop-value.getValue()%" in expression-3
If that does not work, let me know as it is untested.

To update it, you have to do the:
code_language.skript:
set {TopPoints::*} to the highest (size of {points::*}) values of {points::*} as "&e@place. &b@index &7- &6@value"
again. It is recommended to make an auto-updator or a manual way to update the list and not update it every time they use the command.
 
Yes there is. You can change this line of code in the expression for sorting:
code_language.skript:
set {_sorted::%{_index}%} to replace values "@place", "@index" and "@value" with "%{_index}%", "%loop-value.getKey()%" and "%loop-value.getValue()%" in expression-3

Change it to this:
code_language.skript:
set {_sorted::%{_index}%} to replace values "@place", "@index" and "@value" with "%{_index}%", "%(loop-value.getKey()) parsed as offline player%" and "%loop-value.getValue()%" in expression-3
If that does not work, let me know as it is untested.

To update it, you have to do the:
code_language.skript:
set {TopPoints::*} to the highest (size of {points::*}) values of {points::*} as "&e@place. &b@index &7- &6@value"
again. It is recommended to make an auto-updator or a manual way to update the list and not update it every time they use the command.
How come it never removes the last player. I had 2 players, set their points to 0 yet it still displays one of them with their points even though they dont have any. Even with an updator to run every 3 seconds. However, the player names with capitalisation works, thanks.
 
How come it never removes the last player. I had 2 players, set their points to 0 yet it still displays one of them with their points even though they dont have any. Even with an updator to run every 3 seconds. However, the player names with capitalisation works, thanks.
What code are you using to set someone's points? What you can also try is "delete {TopPoints::*}" before updating again.
 
Last edited:
It's fine now, all works. Thank you so much!
 
Last edited:
Status
Not open for further replies.