Solved hey can i optimize this skript? if so how?

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

Slightly longer, heres the code, should work (had to specify the nbt for gapple because its the only one I could find that didn't match the name of the item)
AppleScript:
local function itemreset():
    delete {items::*}
    set {_names::*} to "ENDER", "HASTE", "HOVER", "INVISBILITY", "SPEED", "STRENGTH", "FIREBALL", "BOOMERANG", "SATURATION", "GLOW", "GOD APPLE", "WOLF", "SPECTATOR" and "JUGGERNAUT"
    loop size of {_names::*} times:
        {_names::%loop-number%} is not "GOD APPLE":
            set {_d} to nbt compound from "{%{_names::%loop-number%}%:1b}"
        else:
            set {_d} to nbt compound from "{GAPPLE:1b}"
        add command block named "&6%{_names::%loop-number%}% &6GEM" with nbt {_d} with lore "&6hold in offhand to get effect" to {items::*}

local function randogem(p: player):
    if any:
        {items::*} is not set
        size of {items::*} is 0
    then:
        kick {_p} due to "No available gems"
    else:
        set {_i} to random item out of {items::*}
        remove {_i} from {items::*}
        give {_p} 1 of {_i}

local function reroll(p: player):
    {reroll::%{_p}'s uuid%} < 3:
        randogem({_p})
        add {_p}'s held item to {items::*}
        remove {_p}'s held item from {_p}
        add 1 to {reroll::%{_p}'s uuid%}
    else:
        send "&cYou've already rerolled 3 times!" to {_p}

command gems_reset:
    permission: gems.reset
    trigger:
        itemreset()

command reroll:
    permission: gems.reroll
    trigger:
        name of player's tool contains " &6GEM":
            reroll(player)
        else:
            send "&cYou can't reroll if you aren't holding your gem!"

command gems_random:
    permission: gems.random
    trigger:
        randogem(player)

Would you like me to break down the code?
 
Slightly longer, heres the code, should work (had to specify the nbt for gapple because its the only one I could find that didn't match the name of the item)
AppleScript:
local function itemreset():
    delete {items::*}
    set {_names::*} to "ENDER", "HASTE", "HOVER", "INVISBILITY", "SPEED", "STRENGTH", "FIREBALL", "BOOMERANG", "SATURATION", "GLOW", "GOD APPLE", "WOLF", "SPECTATOR" and "JUGGERNAUT"
    loop size of {_names::*} times:
        {_names::%loop-number%} is not "GOD APPLE":
            set {_d} to nbt compound from "{%{_names::%loop-number%}%:1b}"
        else:
            set {_d} to nbt compound from "{GAPPLE:1b}"
        add command block named "&6%{_names::%loop-number%}% &6GEM" with nbt {_d} with lore "&6hold in offhand to get effect" to {items::*}

local function randogem(p: player):
    if any:
        {items::*} is not set
        size of {items::*} is 0
    then:
        kick {_p} due to "No available gems"
    else:
        set {_i} to random item out of {items::*}
        remove {_i} from {items::*}
        give {_p} 1 of {_i}

local function reroll(p: player):
    {reroll::%{_p}'s uuid%} < 3:
        randogem({_p})
        add {_p}'s held item to {items::*}
        remove {_p}'s held item from {_p}
        add 1 to {reroll::%{_p}'s uuid%}
    else:
        send "&cYou've already rerolled 3 times!" to {_p}

command gems_reset:
    permission: gems.reset
    trigger:
        itemreset()

command reroll:
    permission: gems.reroll
    trigger:
        name of player's tool contains " &6GEM":
            reroll(player)
        else:
            send "&cYou can't reroll if you aren't holding your gem!"

command gems_random:
    permission: gems.random
    trigger:
        randogem(player)

Would you like me to break down the code?
hey for some reason when i do gems_random it kicks me because it says theres no gems left
 
Line 6: (cool/idk.sk)
"{%{_names::%loop-number%}%:1b}" is not a date
Line: set {_d} to nbt compound from "{%{_names::%loop-number%}%:1b}"

Line 8: (cool/idk.sk)
"{GAPPLE:1b}" is not a date
Line: set {_d} to nbt compound from "{GAPPLE:1b}"

Line 9: (cool/idk.sk)
Can't understand this expression: 'command block named "&6%{_names::%loop-number%}% &6GEM" with nbt {_d} with lore "&6hold in offhand to get effect"'
Line: add command block named "&6%{_names::%loop-number%}% &6GEM" with nbt {_d} with lore "&6hold in offhand to get effect" to {items::*}