Help with a list containing players and values

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

ZsCortzones

Member
Feb 18, 2021
32
1
8
26
Hello SkUnity,

I've currently got a skript where I'm trying to make a list of players with the highest kills on the server. I currently have the complete numerical list working properly, but I'm struggling with having the player names associated with the kill numbers.

Code:
command /refreshtopkills:
    permission: owner.refreshtopkills
    trigger:
        clear {topkills::*}
        loop all offline players:
            add {kills.%loop-offline player%} to {topkills::*}
        send "Done!"
           
command /topkills:
    permission: owner.topkills
    trigger:
        set {topkills::*} to sorted {topkills::*}
        loop {topkills::*}:
            send "&7- &f%loop-value%"
           
command /cleartopkills:
    permission: owner.cleartopkills
    trigger:
        clear {topkills::*}
        send "Done!"

The skript currently works perfectly for displaying the amount of kills, but I'd like for it to display as %player% - %kills% like "ZsCortzones - 25"

Does anyone know how I would get the list to display with specific playernames like that?

1696964863943.png
 
Last edited:
I was able to get the names matched up by changing the value I added to the list to be a combination of the kills and player name, but now it doesn't sort properly and sorts it as a text string

1696965568876.png
 
send code :emoji_call_me:
Probably not the best code ever, and I haven’t bothered “polishing” it at all, just trying to get it to work rn lol

Code:
command /refreshtopkills:
    permission: owner.refreshtopkills
    trigger:
        clear {topkills::*}
        loop all offline players:
            if {kills.%loop-offline player%} is not set:
                set {kills.%loop-offline player%} to 0
            set {_topkill::%loop-offline player%} to "&f%{kills.%loop-offline player%}% &7- &c%loop-offline player% "
            add {_topkill::%loop-offline player%} to {topkills::*}
        send "Done!"
            
command /topkills:
    permission: owner.topkills
    trigger:
        set {topkills::*} to sorted {topkills::*}
        loop {topkills::*}:
            send "&7- &f%loop-value%"
            
command /cleartopkills:
    permission: owner.cleartopkills
    trigger:
        clear {topkills::*}
        send "Done!"
 
Okay so I got it to display how I wanted in a bit of a janky way but it freezes both the client and server for about 5 seconds when I execute the "topkills"command lmao. Surely there's a more efficient way to do this?

The goal of this anyways was also just to display the top 10 people with the highest kills, so would there be a way to just cut it off after the top 10 to optimize it maybe?

Code:
command /refreshtopkills:
    permission: owner.refreshtopkills
    trigger:
        clear {topkills::*}
        loop all offline players:
            add {kills.%loop-offline player%} to {topkills::*}
        send "Done!"
           
command /topkills:
    permission: owner.topkills
    trigger:
        set {topkills::*} to sorted {topkills::*}
        loop {topkills::*}:
            loop all offline players:
                if loop-value-1 = {kills.%loop-offline player%}:
                    send "&7- &f%loop-value-1% &7- &c%loop-offline player%"
           
command /cleartopkills:
    permission: owner.cleartopkills
    trigger:
        clear {topkills::*}
        send "Done!"

1697040419731.png
 
Last edited:
I finally fixed the lag issue by just cutting off anyone who had a kill count lower than 10 and fixed the formatting by just re-writing a little bit and also just polished up the output a little bit. Only thing I'm missing and don't really know how to do would be making the skript just take the top 10 kill counts in reverse order (so No.1 is the top one) and labeling them as "1." "2." "3.", etc.

I also just combined the refresh command with the topkills command for simplicity because yeah

Code:
command /topkills:
    permission: owner.topkills
    trigger:
        clear {topkills::*}
        loop all offline players:
            clear {onboard::%loop-offline player%}
            if {kills.%loop-offline player%} > 10:
                add {kills.%loop-offline player%} to {topkills::*}
        send " "
        set {_sortedtopkills::*} to sorted {topkills::*}
        send "&7&l-----&8&l<&c&lTop Kills in KitWarFare&8&l>&7&l-----"
        send " "
        loop {_sortedtopkills::*}:
            loop all offline players:
                if loop-value-1 = {kills.%loop-offline player%}:
                    if {onboard::%loop-offline player%} is not set:
                        set {onboard::%loop-offline player%} to 1
                        send "&7- &c%loop-offline player% &7- &f%loop-value-1% &7Kills"
        send " "
        send "&7&l--------------&8&l<&c☠&8&l>&7&l--------------"
        send " "

            
command /cleartopkills:
    permission: owner.cleartopkills
    trigger:
        clear {topkills::*}
        send "Done!"


1697048514120.png
 
I finally fixed the lag issue by just cutting off anyone who had a kill count lower than 10 and fixed the formatting by just re-writing a little bit and also just polished up the output a little bit. Only thing I'm missing and don't really know how to do would be making the skript just take the top 10 kill counts in reverse order (so No.1 is the top one) and labeling them as "1." "2." "3.", etc.

I also just combined the refresh command with the topkills command for simplicity because yeah

Code:
command /topkills:
    permission: owner.topkills
    trigger:
        clear {topkills::*}
        loop all offline players:
            clear {onboard::%loop-offline player%}
            if {kills.%loop-offline player%} > 10:
                add {kills.%loop-offline player%} to {topkills::*}
        send " "
        set {_sortedtopkills::*} to sorted {topkills::*}
        send "&7&l-----&8&l<&c&lTop Kills in KitWarFare&8&l>&7&l-----"
        send " "
        loop {_sortedtopkills::*}:
            loop all offline players:
                if loop-value-1 = {kills.%loop-offline player%}:
                    if {onboard::%loop-offline player%} is not set:
                        set {onboard::%loop-offline player%} to 1
                        send "&7- &c%loop-offline player% &7- &f%loop-value-1% &7Kills"
        send " "
        send "&7&l--------------&8&l<&c☠&8&l>&7&l--------------"
        send " "

           
command /cleartopkills:
    permission: owner.cleartopkills
    trigger:
        clear {topkills::*}
        send "Done!"


View attachment 7947
Good job for combining the /topkills and /refreshtopkills . I was going to do the same thing, lol. What I do see is that you don't have an on damage: event, but I think you just didn't show it, otherwise it wouldn't work. However, what I think is funny about this is that if you go to SkriptHub, and go to the tutorial for functions (which is right here btw), you will see this:

Code:
function reversed(list: objects) :: objects:
    loop size of {_list::*} times:
        set {_index} to size of {_list::*} - loop-number - 1
        add {_list::%{_index}%} to {_reversed::*}
    return {_reversed::*}

It literally reverses the list, which I think is exactly what you need. (On a side note, it would probably be best to set it as a different list variable, for example:

Code:
command /topkills:
    permission: owner.topkills
    trigger:
        clear {topkills::*}
        loop all offline players:
            clear {onboard::%loop-offline player%}
            if {kills.%loop-offline player%} > 10:
                add {kills.%loop-offline player%} to {topkills::*}
        send " "
        set {_sortedtopkills::*} to sorted {topkills::*}
        set {_lbtopkills::*} to reversed({_sortedtopkills::*})
        send "&7&l-----&8&l<&c&lTop Kills in KitWarFare&8&l>&7&l-----"
        send " "
        loop {_lbtopkills::*}:
            loop all offline players:
                if loop-value-1 = {kills.%loop-offline player%}:
                    if {onboard::%loop-offline player%} is not set:
                        set {onboard::%loop-offline player%} to 1
                        send "&7- &c%loop-offline player% &7- &f%loop-value-1% &7Kills"
        send " "
        send "&7&l--------------&8&l<&c☠&8&l>&7&l--------------"
        send " "

I just changed some code around. Hope this helps!)

P.S. Credits to Blueyescat for the tutorial bc deadass I'm too stupid + lazy to figure this shit out for myself
 
Good job for combining the /topkills and /refreshtopkills . I was going to do the same thing, lol. What I do see is that you don't have an on damage: event, but I think you just didn't show it, otherwise it wouldn't work. However, what I think is funny about this is that if you go to SkriptHub, and go to the tutorial for functions (which is right here btw), you will see this:

Code:
function reversed(list: objects) :: objects:
    loop size of {_list::*} times:
        set {_index} to size of {_list::*} - loop-number - 1
        add {_list::%{_index}%} to {_reversed::*}
    return {_reversed::*}

It literally reverses the list, which I think is exactly what you need. (On a side note, it would probably be best to set it as a different list variable, for example:

Code:
command /topkills:
    permission: owner.topkills
    trigger:
        clear {topkills::*}
        loop all offline players:
            clear {onboard::%loop-offline player%}
            if {kills.%loop-offline player%} > 10:
                add {kills.%loop-offline player%} to {topkills::*}
        send " "
        set {_sortedtopkills::*} to sorted {topkills::*}
        set {_lbtopkills::*} to reversed({_sortedtopkills::*})
        send "&7&l-----&8&l<&c&lTop Kills in KitWarFare&8&l>&7&l-----"
        send " "
        loop {_lbtopkills::*}:
            loop all offline players:
                if loop-value-1 = {kills.%loop-offline player%}:
                    if {onboard::%loop-offline player%} is not set:
                        set {onboard::%loop-offline player%} to 1
                        send "&7- &c%loop-offline player% &7- &f%loop-value-1% &7Kills"
        send " "
        send "&7&l--------------&8&l<&c☠&8&l>&7&l--------------"
        send " "

I just changed some code around. Hope this helps!)

P.S. Credits to Blueyescat for the tutorial bc deadass I'm too stupid + lazy to figure this shit out for myself
This works great and does end up sorting the list in reverse order, but for some reason the top value gets cut off for no reason, not showing _mxmq's 208 kills, do you have any idea why this might be?
 
This works great and does end up sorting the list in reverse order, but for some reason the top value gets cut off for no reason, not showing _mxmq's 208 kills, do you have any idea why this might be?
No, but if it continues happening once you sort it you can make it the first message.