Help with "sorting" a list

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

HugeAdventure

New Member
Oct 5, 2023
6
0
1
hey, could ayone help me because im struggeling to do or explain this. i would like a system that takes the last "rarity" <- use as the sorting key. and then the name of the rng and sorts it in a gui sorting from rarest to least rare. i would love if you could add the multiple of a same type too, using like xAmount in the name. well, its a inventory system.

current script:


code_language.skript:
variables:
    {rollstreek} = 0

command roll:
    aliases: rng
    trigger:
        if {roll::%player%} is true:
            send actionbar "&cAlready rolling" to player
        else:
            add 1 to {rolls::%player%}
            roll(player)

command rolls:
    trigger:
        send "%nl%&eTotal rolls: &6%{rolls::%player%}% %nl%" to player

function getluck(p: player, n: integer):
    set {_luck} to ({Luckevent} + {GlobalLuck} + {Equipment::%{_p}%} + {_n})
   
    # Apply a times luck multiplier for times-based rewards or boosts
    set {_timesLuck} to 1 # Default multiplier is 1
    if {timesLuck::%{_p}%} is set:
        set {_timesLuck} to {timesLuck::%{_p}%} # Use the multiplier if it's set

    # Apply the luck to the final outcome
    set {_finalLuck} to {_luck} * {_timesLuck}

    # Send the luck calculation to the player
    send "&7Your Luck: &e%{_finalLuck}%" to {_p}
    set {finalLuck::%{_p}%} to {_finalLuck}

# Times luck multiplier logic (could be triggered by a command or event)
command /settimesluck <integer>:
    permission: "admin.settimesluck"
    trigger:
        if arg-1 is an integer:
            set {timesLuck::%player%} to arg-1
            send "&7Your times luck multiplier is now set to &e%arg-1%" to player
        else:
            send "&cPlease enter a valid multiplier value." to player

every 1 second:
    loop all players:
        send actionbar "&8Double Luck: &e%{rollstreek::%loop-player%}%&6&l/&e5" to loop-player

on rightclick with lime concrete:
    execute player command "/roll"

on quit:
    set {roll::%player%} to false


# Rolling outcome logic using luck values
function roll(p: player):
    set {roll::%{_p}%} to true
    if {rollstreek::%{_p}%} is not set:
        set {rollstreek::%{_p}%} to 1
    else:
        add 1 to {rollstreek::%{_p}%}

    if {rollstreek::%{_p}%} = 6:
        set {rollstreek::%{_p}%} to 0
        send actionbar "&eDouble Luck Roll" to {_p}

    # Perform 5 consecutive rolls
    wait 1 second
    loop 5 times:
        play sound "entity.experience_orb.pickup" at pitch (random number between 1.1 and 1.3) to {_p}
        if {rollstreek::%{_p}%} = 5:
            PickRng({_p}, 2, 2)
        else:
            PickRng({_p}, 1, 2)
        wait 0.4 second
    PickRng({_p}, 1, 1)
    wait 0.5 seconds
    set {roll::%{_p}%} to false


# RNG outcome calculation based on luck (with multiplier)
function PickRng(p: player, n: integer, t: integer):
    set {_luck} to {timesLuck::%{_p}%}
    # Calculate the adjusted roll based on luck.  Clamping to a minimum of 1.
    set {_roll} to random integer between 1 and 100000000
    set {_roll} to {_roll} - {_luck}
    if {_roll} < 1:
        set {_roll} to 1
    if {_roll} is between 50000001 and 100000000:
        set {_outcome} to "<#888888>&lSilent Echo"
        set {_chance} to "1 in 2"
        set {value::{_outcome}}
    else if {_roll} is between 10000001 and 50000000:
        set {_outcome} to "<#AAAAAA>&lDistant Mirage"
        set {_chance} to "1 in 10"
    else if {_roll} is between 1000001 and 10000000:
        set {_outcome} to "<#3ADF00>&lWandering Spirit"
        set {_chance} to "1 in 100"
    else if {_roll} is between 100001 and 1000000:
        set {_outcome} to "<#3a9ad9>&lFrostfire Wisp"
        set {_chance} to "1 in 1,000"
    else if {_roll} is between 50001 and 100000:
        set {_outcome} to "<#b931fc>&lPhantom Ember"
        set {_chance} to "1 in 2,000"
    else if {_roll} is between 10001 and 50000:
        set {_outcome} to "<#ffae42>&lShifting Horizon"
        set {_chance} to "1 in 10,000"
    else if {_roll} is between 5001 and 10000:
        set {_outcome} to "<#ff69b4>&lEclipsing Fate"
        set {_chance} to "1 in 20,000"
    else if {_roll} is between 1001 and 5000:
        set {_outcome} to "<#1f75fe>&lTwilight Shard"
        set {_chance} to "1 in 50,000"
    else if {_roll} is between 501 and 1000:
        set {_outcome} to "<#a1c298>&lDreambound Essence"
        set {_chance} to "1 in 100,000"
    else if {_roll} is between 101 and 500:
        set {_outcome} to "<#a020f0>&lSundown Relic"
        set {_chance} to "1 in 200,000"
    else if {_roll} is between 51 and 100:
        set {_outcome} to "<#2c75ff>&lCrimson Phantom"
        set {_chance} to "1 in 500,000"
    else if {_roll} is between 11 and 50:
        set {_outcome} to "<#fdfd96>&lStarlit Enigma"
        set {_chance} to "1 in 1,000,000"
    else if {_roll} is between 6 and 10:
        set {_outcome} to "<#ff4500>&lEldritch Nova"
        set {_chance} to "1 in 5,000,000"
    else if {_roll} is between 1 and 5:
        set {_outcome} to "<#ff1493>&lEthereal Whisper"
        set {_chance} to "1 in 10,000,000"
    else:
        set {_outcome} to "Impossible???"

    set {RNGOutcome::%{_p}%} to {_outcome}
    set {RNGRoll::%{_p}%} to {_chance}
    if {_t} = 1:
        add 1 to {RNGCount::%{_p}%::%{_outcome}%}
        add 1 to {totalrng::%{_outcome}%}
        send "%{_outcome}%&r &8[%{_chance}%]&7 x%{RNGCount::%{_p}%::%{_outcome}%}%" to {_p}
        broadcast "exists: %{totalrng::%{_outcome}%}%"
    set {RNGRarity::%{_p}%::%{_outcome}%} to {_roll}
    send title "&l%{RNGOutcome::%{_p}%}%" with subtitle "&6%{RNGRoll::%{_p}%}%" to {_p}

command testall:
    trigger:
        broadcast {RNGCount::%{_p}%::%{_outcome}%}

command /inv:
    trigger:
        set {_gui} to a chest inventory with 3 rows named "&7Your RNG Items"
        set {_slot} to 0
        open {_gui} to player
        send "%{_sorted::*}%" to player
        function sort()