[solved] Sorting list variables. (for ranking script?

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

Feb 16, 2017
8
0
0
26
Actually, it is possible to create ranking script without any addon. (Like below)
However, if the data became too big, such script cause heavy heavy lag. (That is fatal!! ;(

So my suggestion is addon which has sorting functions.

(Or anyone know how to create the faster ranking system, only using existing addon?)
I really wish if I could sort variables in faster way.....

#---- sample of ranking script without addons -----------------------
code_language.skript:
on load:
    set {_players} to 0
    loop {kd.kills::*}:
        if loop-value is greater than 999.5:
            set {_topkills::%loop-index%} to loop-value
            add 1 to {_players}
    set {_high} to 0
    loop {_players} times:
        loop {_topkills::*}:
            if loop-value-2 > {_high}:
                set {_high} to loop-value-2
                set {_highplayeruuid} to loop-index
                set {temp.topkills::%loop-number%} to loop-index
        set {_high} to 0
        delete {_topkills::%{_highplayeruuid}%}
    message "Created Ranking of %{_players}% players." to console
    set {temp.topkills.NumberOfPlayers} to {_players}

command /topkills [<number>]:
    usage: &b/topkills (pages)
    trigger:
        set {_totalpages} to rounded up {temp.topkills.NumberOfPlayers} / 10
        if {_totalpages} is 0:
            message "&b-=-=-=-=- Kill Ranking =-=-=-=-"
            message "&3There is no data to list...."
            stop
        if arg-1 exist:
            if arg-1 is greater than {_totalpages}:
                set {_target} to {_totalpages}
            else if arg-1 is smaller than 1:
                set {_target} to 1
            else:
                set {_target} to rounded down arg-1
        else:
            set {_target} to 1
        set {_start} to (10*{_target}) -9
        if (9+{_start}) is greater than {temp.topkills.NumberOfPlayers}:
            set {_looptimes} to {temp.topkills.NumberOfPlayers} - {_start} + 1
        else:
            set {_looptimes} to 10
        message "&b-=-=-=-=- Kill Ranking =-=-=-=-"
        loop {_looptimes} times:
            message "&b%{_start}%: %{player.lastknownname::%{temp.topkills::%{_start}%}%}%      %{kd.kills::%{temp.topkills::%{_start}%}%}% Kills"
            add 1 to {_start}
        message "&3Viewing page %{_target}%/%{_totalpages}%."

on death:
    if attacker exist:
        add 1 to {kd.kills::%attacker's uuid%}

on join:
    if {player.lastname::%player's uuid%} does not exist:
        set {player.lastknownname::%player's uuid%} to player's name
    else if {player.lastknownname::%player's uuid%} is not player's name:
        set {player.lastknownname::%player's uuid%} to player's name
# * Create data every time Skript launch or when this script reloaded
# Processing times is approximately proportional to the square of the number of datas
# e.g.) 100 data --> loop 5000 times. 14000 datas--> loop 100000000 times. XD
 
Last edited:
Do you want to suggest an expression to addon but without using any addon?
RandomSK used to have this expression, but Bensku's fork has the same one to do this job.
code_language.skript:
sorted %objects% #returns a list of objects sorted from lower to highest value

#Example
set {_top::*} to sorted {TopPlayers::*}
But the problem is that this expression doesn't return the indexes, only values.
 
Plz, use format code... that looks so ugly xD
I fixed. :emoji_stuck_out_tongue:
Do you want to suggest an expression to addon but without using any addon?
RandomSK used to have this expression, but Bensku's fork has the same one to do this job.
code_language.skript:
sorted %objects% #returns a list of objects sorted from lower to highest value

#Example
set {_top::*} to sorted {TopPlayers::*}
But the problem is that this expression doesn't return the indexes, only values.


I need to sort not only values but indexes, to create ranking.
Therefore that example has big problem....
(I forgot to tell that I have already tried RandomSK)

The function I need is sorting value with indexes kept.
Anyone can create the new addon or add the new function to existing addons?
 
Last edited by a moderator:
Hi.
I managed to find out how to make faster ranking script.
And, it does not require any addons!

So addon with a sorting fuction might be unnecessary anymore :O
I will also post this revolutionary script to RESOURCES/Scripts. :emoji_slight_smile:

Thx Tuke_nuke,PuchiGFX.

code_language.skript:
on load:
    set {_players} to 0
    loop {kd.kills::*}:
        if loop-value is greater than 0.5:
            add 1 to {_numberofplayers}
            add 1 to {_topkillsexist::%loop-value%}
            set {_topkillsvalue::%loop-value%::%loop-index%} to loop-index
    set {_processnumber} to {_numberofplayers}
    loop {_topkillsexist::*}:#I used double loop
        loop {_topkillsvalue::%loop-index%::*}:       # (But I don't know why it works well)
            set {temp.topkills::%{_processnumber}%} to loop-value-2 #index = uuid
            remove 1 from {_processnumber}
    message "Created Ranking of %{_players}% players." to console
    set {temp.topkills.NumberOfPlayers} to {_numberofplayers}

# * If you want sort a decimal number, try multiplying x100000  and  then rounding.
# e.g)    set {_kdr::%loop-index%} to (rounded down (10000*{kd.kills::%loop-index%})) / loop-value

command /topkills [<number>]:
    usage: &b/topkills (pages)
    trigger:
        set {_totalpages} to rounded up {temp.topkills.NumberOfPlayers} / 10
        if {_totalpages} is 0:
            message "&b-=-=-=-=- Kill Ranking =-=-=-=-"
            message "&3There is no data to list...."
            stop
        broadcast "%{_totalpages}%"
        if arg-1 exist:
            if arg-1 is greater than {_totalpages}:
                set {_target} to {_totalpages}
            else if arg-1 is smaller than 1:
                set {_target} to 1
            else:
                set {_target} to rounded down arg-1
        else:
            set {_target} to 1
        set {_start} to (10*{_target}) -9
        if (9+{_start}) is greater than {temp.topkills.NumberOfPlayers}:
            set {_looptimes} to {temp.topkills.NumberOfPlayers} - {_start} + 1
        else:
            set {_looptimes} to 10
        message "&b-=-=-=-=- Kill Ranking =-=-=-=-"
        loop {_looptimes} times:
            message "&b%{_start}%: %{player.lastknownname::%{temp.topkills::%{_start}%}%}%      %{kd.kills::%{temp.topkills::%{_start}%}%}% Kills"
            add 1 to {_start}
        message "&3Viewing page %{_target}%/%{_totalpages}%."

on death:
    if attacker exist:
        add 1 to {kd.kills::%attacker's uuid%}
    broadcast "%{kd.kills::%attacker's uuid%}-1% --> %{kd.kills::%attacker's uuid%}%"

on join:
    if {player.lastknownname::%player's uuid%} does not exist:
        set {player.lastknownname::%player's uuid%} to player's name
    else if {player.lastknownname::%player's uuid%} is not player's name:
        set {player.lastknownname::%player's uuid%} to player's name
 
Last edited by a moderator: