Skript Review/Optimze/Shorten

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

Tewahh

Member
Aug 18, 2023
16
1
3
24
Code:
command /crates:

    description: The laziest best way of doing something.

    trigger:

        open chest inventory with 4 rows named "&b&lCrates" to player

        set slot 0 of player's current inventory to stone named "&b&lCustom Crate"

on inventory click:

    #check if the clicked inventory is the one we just created

    if name of event-inventory is "&b&lCrates":

        #cancel the clicking. This makes the Item unstealable

        cancel event

        if index of event-slot is 0:

            if event-click type is right mouse button:

                set {_gui} to a new chest inventory with 2 row named "&a&lCustom Crate Rewards"

                set slot 0 of {_gui} to 1 tripwire hook named "&a&lCustom Crate Key" with lore "&a&lThis reward gives ", " ", "1 Custom Crate Key ", " " and "With a Chance of: 15%%"

                set slot 1 of {_gui} to 2 tripwire hook named "&a&lCustom Crate Key" with lore "&a&lThis reward gives ", " ", "2 Custom Crate Keys ", " " and "With a Chance of: 10%%"

                set slot 2 of {_gui} to 3 tripwire hook named "&a&lCustom Crate Key" with lore "&a&lThis reward gives ", " ", "3 Custom Crate Keys ", " " and "With a Chance of: 5%%"

                set slot 3 of {_gui} to 1 emerald named "&a&lMoney" with lore "&a&lThis reward gives ", " ", "$100k ", " " and "With a Chance of: 50%%"

                set slot 4 of {_gui} to 1 emerald named "&a&lMoney" with lore "&a&lThis reward gives ", " ", "$150k ", " " and "With a Chance of: 25%%"

                set slot 5 of {_gui} to 1 emerald named "&a&lMoney" with lore "&a&lThis reward gives ", " ", "$250k ", " " and "With a Chance of: 16%%"

                set slot 6 of {_gui} to 1 emerald named "&a&lMoney" with lore "&a&lThis reward gives ", " ", "$500k ", " " and "With a Chance of: 8%%"

                set slot 7 of {_gui} to 1 emerald named "&a&lMoney" with lore "&a&lThis reward gives ", " ", "$1M ", " " and "With a Chance of: 1%%"

              

                set slot 8 of {_gui} to 1 red dye named "&4&lHea&c&lrt" with lore "&a&lThis reward gives ", " ", "1 Heart ", " " and "With a Chance of: 15%%"

                set slot 9 of {_gui} to 2 red dye named "&4&lHea&c&lrt" with lore "&a&lThis reward gives ", " ", "2 Hearts ", " " and "With a Chance of: 5%%"

              

                set slot 10 of {_gui} to 1 ghast tear named "&4&lHeart &c&lFragment" with lore "&a&lThis reward gives ", " ", "1 Heart Fragment", " " and "With a Chance of: 15%%"

                set slot 11 of {_gui} to 3 ghast tear named "&4&lHeart &c&lFragment" with lore "&a&lThis reward gives ", " ", "3 Heart Fragments", " " and "With a Chance of: 5%%"

                if player's inventory contains tripwire hook named "&a&lCustom Crate Key":

                    set {_chance} to a random integer from 1 to 50

                  

                    # KEYS

                  

                    if {_chance} is 1:

                        give player 1 tripwire hook named "&a&lCustom Crate Key"

                  

                    if {_chance} is 2:

                        give player 2 tripwire hook named "&a&lCustom Crate Key"

                  

                    if {_chance} is 3:

                        give player 3 tripwire hook named "&a&lCustom Crate Key"

                  

                    # MONEY

                    if {_chance} is 4:

                        add 100000 to {economy::balance::%player%}

                  

                    if {_chance} is 5:

                        add 150000 to {economy::balance::%player%}

                  

                    if {_chance} is 6:

                        add 250000 to {economy::balance::%player%}

                  

                    if {_chance} is 7:

                        add 500000 to {economy::balance::%player%}

                  

                    if {_chance} is 8:

                        add 1000000 to {economy::balance::%player%}

                  

                    # HEARTS

                    if {_chance} is 9:

                        give player 1 red dye named "&4&lHea&c&lrt"

                    if {_chance} is 10:

                        give player 2 red dye named "&4&lHea&c&lrt"

                    # HEART FRAGMENTS

                    if {_chance} is 11:

                        give player 1 ghast tear named "&4&lHeart &c&lFragment"

                  

                    if {_chance} is 12:

                        give player 3 ghast tear named "&4&lHeart &c&lFragment"
I'm not asking for anyone to do it for me, because that wouldn't be helping me at all. But, if someone could point me in the right direction of how I can make my code shorter whilst still keeping the same functionality of the code, that would be nice. I don't really know if there is a better way to do this, but this is how i did it, and it's very clunky and unorganized... I want to make the code shorter and more optimized.
 
Code:
command /crates:

    description: The laziest best way of doing something.

    trigger:

        open chest inventory with 4 rows named "&b&lCrates" to player

        set slot 0 of player's current inventory to stone named "&b&lCustom Crate"

on inventory click:

    #check if the clicked inventory is the one we just created

    if name of event-inventory is "&b&lCrates":

        #cancel the clicking. This makes the Item unstealable

        cancel event

        if index of event-slot is 0:

            if event-click type is right mouse button:

                set {_gui} to a new chest inventory with 2 row named "&a&lCustom Crate Rewards"

                set slot 0 of {_gui} to 1 tripwire hook named "&a&lCustom Crate Key" with lore "&a&lThis reward gives ", " ", "1 Custom Crate Key ", " " and "With a Chance of: 15%%"

                set slot 1 of {_gui} to 2 tripwire hook named "&a&lCustom Crate Key" with lore "&a&lThis reward gives ", " ", "2 Custom Crate Keys ", " " and "With a Chance of: 10%%"

                set slot 2 of {_gui} to 3 tripwire hook named "&a&lCustom Crate Key" with lore "&a&lThis reward gives ", " ", "3 Custom Crate Keys ", " " and "With a Chance of: 5%%"

                set slot 3 of {_gui} to 1 emerald named "&a&lMoney" with lore "&a&lThis reward gives ", " ", "$100k ", " " and "With a Chance of: 50%%"

                set slot 4 of {_gui} to 1 emerald named "&a&lMoney" with lore "&a&lThis reward gives ", " ", "$150k ", " " and "With a Chance of: 25%%"

                set slot 5 of {_gui} to 1 emerald named "&a&lMoney" with lore "&a&lThis reward gives ", " ", "$250k ", " " and "With a Chance of: 16%%"

                set slot 6 of {_gui} to 1 emerald named "&a&lMoney" with lore "&a&lThis reward gives ", " ", "$500k ", " " and "With a Chance of: 8%%"

                set slot 7 of {_gui} to 1 emerald named "&a&lMoney" with lore "&a&lThis reward gives ", " ", "$1M ", " " and "With a Chance of: 1%%"

             

                set slot 8 of {_gui} to 1 red dye named "&4&lHea&c&lrt" with lore "&a&lThis reward gives ", " ", "1 Heart ", " " and "With a Chance of: 15%%"

                set slot 9 of {_gui} to 2 red dye named "&4&lHea&c&lrt" with lore "&a&lThis reward gives ", " ", "2 Hearts ", " " and "With a Chance of: 5%%"

             

                set slot 10 of {_gui} to 1 ghast tear named "&4&lHeart &c&lFragment" with lore "&a&lThis reward gives ", " ", "1 Heart Fragment", " " and "With a Chance of: 15%%"

                set slot 11 of {_gui} to 3 ghast tear named "&4&lHeart &c&lFragment" with lore "&a&lThis reward gives ", " ", "3 Heart Fragments", " " and "With a Chance of: 5%%"

                if player's inventory contains tripwire hook named "&a&lCustom Crate Key":

                    set {_chance} to a random integer from 1 to 50

                 

                    # KEYS

                 

                    if {_chance} is 1:

                        give player 1 tripwire hook named "&a&lCustom Crate Key"

                 

                    if {_chance} is 2:

                        give player 2 tripwire hook named "&a&lCustom Crate Key"

                 

                    if {_chance} is 3:

                        give player 3 tripwire hook named "&a&lCustom Crate Key"

                 

                    # MONEY

                    if {_chance} is 4:

                        add 100000 to {economy::balance::%player%}

                 

                    if {_chance} is 5:

                        add 150000 to {economy::balance::%player%}

                 

                    if {_chance} is 6:

                        add 250000 to {economy::balance::%player%}

                 

                    if {_chance} is 7:

                        add 500000 to {economy::balance::%player%}

                 

                    if {_chance} is 8:

                        add 1000000 to {economy::balance::%player%}

                 

                    # HEARTS

                    if {_chance} is 9:

                        give player 1 red dye named "&4&lHea&c&lrt"

                    if {_chance} is 10:

                        give player 2 red dye named "&4&lHea&c&lrt"

                    # HEART FRAGMENTS

                    if {_chance} is 11:

                        give player 1 ghast tear named "&4&lHeart &c&lFragment"

                 

                    if {_chance} is 12:

                        give player 3 ghast tear named "&4&lHeart &c&lFragment"
I'm not asking for anyone to do it for me, because that wouldn't be helping me at all. But, if someone could point me in the right direction of how I can make my code shorter whilst still keeping the same functionality of the code, that would be nice. I don't really know if there is a better way to do this, but this is how i did it, and it's very clunky and unorganized... I want to make the code shorter and more optimized.
One of the best ways to shorten/optimize code is with functions! In my opinion, functions are extremely helpful and honestly extremely convenient to use if you wanna optimize your code. You should also look into loops too. If you have multiple lines of code doing pretty similar things, you can likely loop it, add/change a variable to have it adjust when looping and then instead of 10 lines doing similar things down you just a few lines via loops.
 
One of the best ways to shorten/optimize code is with functions! In my opinion, functions are extremely helpful and honestly extremely convenient to use if you wanna optimize your code. You should also look into loops too. If you have multiple lines of code doing pretty similar things, you can likely loop it, add/change a variable to have it adjust when looping and then instead of 10 lines doing similar things down you just a few lines via loops.
Alright, Thank you for your help. Ill look into making functions and loops.
 
  • Like
Reactions: Luke_Sky_Walker
One of the best ways to shorten/optimize code is with functions! In my opinion, functions are extremely helpful and honestly extremely convenient to use if you wanna optimize your code. You should also look into loops too. If you have multiple lines of code doing pretty similar things, you can likely loop it, add/change a variable to have it adjust when looping and then instead of 10 lines doing similar things down you just a few lines via loops.

Code:
function openCrateInventory(p: player):
    open chest inventory with 4 rows named "&b&lCrates" to {_p}
    set slot 0 of {_p}'s current inventory to stone named "&b&lCustom Crate"

function openRewardsInventory(p: player):
    set {_gui} to a new chest inventory with 2 row named "&a&lCustom Crate Rewards"
    # Set up reward slots in the inventory

function givePlayerCrateKeys(p: player, times: number):
    give {_p} {_times} of tripwire hook named "&a&lCustom Crate Key"

function givePlayerRewards(p: player, c: number):
    if {_c} = 4:
        add 100000 to {economy::balance::%{_p}%}
    else if {_c} = 5:
        add 150000 to {economy::balance::%{_p}%}
    else if {_c} = 6:
        add 250000 to {economy::balance::%{_p}%}
    else if {_c} = 7:
        add 500000 to {economy::balance::%{_p}%}
    else if {_c} = 8:
        add 1000000 to {economy::balance::%{_p}%}
    else if {_c} = 9:
        give {_p} 1 red dye named "&4&lHea&c&lrt"
    else if {_c} = 10:
        give {_p} 2 red dye named "&4&lHea&c&lrt"
    else if {_c} = 11:
        give {_p} 1 ghast tear named "&4&lHeart &c&lFragment"
    else if {_c} = 12:
        give {_p} 3 ghast tear named "&4&lHeart &c&lFragment"

command /crates:
    description: The laziest best way of doing something.
    trigger:
        openCrateInventory(player)

on inventory click:
    if name of event-inventory is "&b&lCrates":
        cancel event
        if index of event-slot is 0:
            if event-click type is right mouse button:
                openRewardsInventory(player)

                if player's inventory contains tripwire hook named "&a&lCustom Crate Key":
                    set {_chance} to random integer from 1 to 50

                    if {_chance} <= 3:
                        givePlayerCrateKeys(player, {_chance})
                    else:
                        givePlayerRewards(player, {_chance})

I don't really know if this is a good substitute, but this is what i came up with.
 
Code:
function openCrateInventory(p: player):
    open chest inventory with 4 rows named "&b&lCrates" to {_p}
    set slot 0 of {_p}'s current inventory to stone named "&b&lCustom Crate"

function openRewardsInventory(p: player):
    set {_gui} to a new chest inventory with 2 row named "&a&lCustom Crate Rewards"
    # Set up reward slots in the inventory

function givePlayerCrateKeys(p: player, times: number):
    give {_p} {_times} of tripwire hook named "&a&lCustom Crate Key"

function givePlayerRewards(p: player, c: number):
    if {_c} = 4:
        add 100000 to {economy::balance::%{_p}%}
    else if {_c} = 5:
        add 150000 to {economy::balance::%{_p}%}
    else if {_c} = 6:
        add 250000 to {economy::balance::%{_p}%}
    else if {_c} = 7:
        add 500000 to {economy::balance::%{_p}%}
    else if {_c} = 8:
        add 1000000 to {economy::balance::%{_p}%}
    else if {_c} = 9:
        give {_p} 1 red dye named "&4&lHea&c&lrt"
    else if {_c} = 10:
        give {_p} 2 red dye named "&4&lHea&c&lrt"
    else if {_c} = 11:
        give {_p} 1 ghast tear named "&4&lHeart &c&lFragment"
    else if {_c} = 12:
        give {_p} 3 ghast tear named "&4&lHeart &c&lFragment"

command /crates:
    description: The laziest best way of doing something.
    trigger:
        openCrateInventory(player)

on inventory click:
    if name of event-inventory is "&b&lCrates":
        cancel event
        if index of event-slot is 0:
            if event-click type is right mouse button:
                openRewardsInventory(player)

                if player's inventory contains tripwire hook named "&a&lCustom Crate Key":
                    set {_chance} to random integer from 1 to 50

                    if {_chance} <= 3:
                        givePlayerCrateKeys(player, {_chance})
                    else:
                        givePlayerRewards(player, {_chance})

I don't really know if this is a good substitute, but this is what i came up with.
That's definitely a step in the right direction. Your code is now shorter than the original version and imo is a bit easier to read.
 
That's definitely a step in the right direction. Your code is now shorter than the original version and imo is a bit easier to read.
You also said something about loops. I have a keyall skript but i have no idea how to use functions/loops to make it more optimized.
Code:
options:
    keyallPermission: SupremeCore.Staff.Crates.Keyall
    noPermissionMessage: &cYou don't have the required permissions to use this command. Please contact a developer if you think that this is a mistake

command /keyall <text> <integer>:
    permission: {@keyallPermission}
    permission message: {@noPermissionMessage}
    trigger:
        loop all players:
            if arg-1 is set:
                if arg-1 is "Custom Rank Key":
                    set {_item} to tripwire hook named "&1&lCustom Rank Key"
                    set {_amount} to arg 2 ? 1
                    give {_amount} of {_item} to loop-player

                if arg-1 is "Starter Key":
                    set {_item} to tripwire hook named "&7&lStarter Key"
                    set {_amount} to arg 2 ? 1
                    give {_amount} of {_item} to loop-player

                if arg-1 is "Daily Key":
                    set {_item} to tripwire hook named "&7&lDaily Key"
                    set {_amount} to arg 2 ? 1
                    give {_amount} of {_item} to loop-player

                if arg-1 is "Supreme Core Key":
                    set {_item} to tripwire hook named "&4&lSupreme Core Key"
                    set {_amount} to arg 2 ? 1
                    give {_amount} of {_item} to loop-player

                if arg-1 is "Refund Key":
                    set {_item} to tripwire hook named "&6&lRefund Key"
                    set {_amount} to arg 2 ? 1
                    give {_amount} of {_item} to loop-player
            if arg-1 is not set:
                send "&7You need to specify a key to give to a player!"
            if arg-2 is not set:
                set {_amount} to 1
                
on tab complete of "/keyall":
    if player has permissions "{@keyallPermission}":
        set tab completions for position 1 to "[Key Name]", "Custom Rank Key", "Starter Key", "Daily Key", "Supreme Core Key" and "Refund Key"
        set tab completions for position 2 to "[Number]"
 
You also said something about loops. I have a keyall skript but i have no idea how to use functions/loops to make it more optimized.
Code:
options:
    keyallPermission: SupremeCore.Staff.Crates.Keyall
    noPermissionMessage: &cYou don't have the required permissions to use this command. Please contact a developer if you think that this is a mistake

command /keyall <text> <integer>:
    permission: {@keyallPermission}
    permission message: {@noPermissionMessage}
    trigger:
        loop all players:
            if arg-1 is set:
                if arg-1 is "Custom Rank Key":
                    set {_item} to tripwire hook named "&1&lCustom Rank Key"
                    set {_amount} to arg 2 ? 1
                    give {_amount} of {_item} to loop-player

                if arg-1 is "Starter Key":
                    set {_item} to tripwire hook named "&7&lStarter Key"
                    set {_amount} to arg 2 ? 1
                    give {_amount} of {_item} to loop-player

                if arg-1 is "Daily Key":
                    set {_item} to tripwire hook named "&7&lDaily Key"
                    set {_amount} to arg 2 ? 1
                    give {_amount} of {_item} to loop-player

                if arg-1 is "Supreme Core Key":
                    set {_item} to tripwire hook named "&4&lSupreme Core Key"
                    set {_amount} to arg 2 ? 1
                    give {_amount} of {_item} to loop-player

                if arg-1 is "Refund Key":
                    set {_item} to tripwire hook named "&6&lRefund Key"
                    set {_amount} to arg 2 ? 1
                    give {_amount} of {_item} to loop-player
            if arg-1 is not set:
                send "&7You need to specify a key to give to a player!"
            if arg-2 is not set:
                set {_amount} to 1
               
on tab complete of "/keyall":
    if player has permissions "{@keyallPermission}":
        set tab completions for position 1 to "[Key Name]", "Custom Rank Key", "Starter Key", "Daily Key", "Supreme Core Key" and "Refund Key"
        set tab completions for position 2 to "[Number]"
You can use a function for the key all and use options. Here‘s what I was able to write as an example (No errors but untested in game):

Code:
options:
   k1: tripwire hook named "&1&lCustom Rank Key" # Use this for each key

function givekey(p: player, name: text, am: integer): # Takes a player name, a text and then can check/give a selected player a key (Can be loop-player)
   if {_name} contains "Custom":
      give {_p} {_am} of {@k1}

command keyall <text> <integer>:
   trigger:
      if arg-1 and arg-2 are set:
         givekey(player, arg-1, arg-2) # How we would use this in the command
 
You can use a function for the key all and use options. Here‘s what I was able to write as an example (No errors but untested in game):

Code:
options:
   k1: tripwire hook named "&1&lCustom Rank Key" # Use this for each key

function givekey(p: player, name: text, am: integer): # Takes a player name, a text and then can check/give a selected player a key (Can be loop-player)
   if {_name} contains "Custom":
      give {_p} {_am} of {@k1}

command keyall <text> <integer>:
   trigger:
      if arg-1 and arg-2 are set:
         givekey(player, arg-1, arg-2) # How we would use this in the command
Thank you! You are helping me out a ton!
 
So, I made custom enchants like 2 months ago, and I haven't updated anything, it shows no errors. but it has a lot of lines. I want to turn it into functions and stuff that would make it better and more optimized. I also have an idea for a custom enchant but have no idea how to implement it. It would be using armor stands, and here is the idea "it would put the victim in a 3 by 3 box of bedrock, which they cant move, hit anyone. But, they can be hit. it would disappear after 5-10 seconds"
Also, i want to make it so that whenever the player has enchants on their weapons/items. they can only have 10 enchants max unless they put a weapon or armor orb on the item. If you could help me with this, that would be GREAT!!

Code:
options:
    maxCustomEnchantsOnAnItem: 10 # 10 lore

command /ce:
    aliases: /customenchants, /customenchant, /enchants
    trigger:
        set {_item} to gray stained glass pane
        set {_enchantmentsList} to book named "&eList Of All The Enchants"
        set line 1 of lore of {_enchantmentsList} to ""
        set {_commonEnchant} to book named "&7&lCommon Enchant"
        set {_uncommonEnchant} to book named "&a&lUncommon Enchant"
        set {_rareEnchant} to book named "&1&lRare Enchant"
        set {_uniqueEnchant} to book named "&e&lUnique Enchant"
        set {_legendaryEnchant} to book named "&6&lLegendary Enchant"
        set {_mythicalEnchant} to book named "&d&lMythical Enchant"
        # set {_executiveEnchant} to book named "&b&lExecutive Enchant"
        set {_gui} to a new chest inventory with 6 rows with name "&b&lCustom Enchants"
        set slot (integers between 0 and 53) of {_gui} to {_item}
        set slot 10 of {_gui} to {_commonEnchant}
        set slot 13 of {_gui} to {_uncommonEnchant}
        set slot 16 of {_gui} to {_rareEnchant}
        set slot 37 of {_gui} to {_uniqueEnchant}
        set slot 40 of {_gui} to {_legendaryEnchant}
        set slot 43 of {_gui} to {_mythicalEnchant}
        set slot 53 of {_gui} to {_enchantmentsList}
        open {_gui} to player

on inventory click:
    if name of event-inventory is "&b&lCustom Enchants":
        if index of event-slot = 10: # Check if the clicked slot is in the common enchant book range
            cancel event
            if player's level > 1:
                remove 1 from player's level
                give player book named "&7&lCommon Enchant"
                send "You received a &7&lCommon Enchant Book"
        else if index of event-slot = 13:
            cancel event
            if player's level > 2:
                remove 1 from player's level
                give player book named "&a&lUncommon Enchant"
                send "You received a &a&lUncommon Enchant Book"
        else if index of event-slot = 16:
            cancel event
            if player's level > 3:
                remove 3 from player's level
                give player book named "&1&lRare Enchant"
                send "You received a &1&lRare Enchant Book"
        else if index of event-slot = 37:
            cancel event
            if player's level > 4:
                remove 4 from player's level
                give player book named "&e&lUnique Enchant"
                send "You received a &e&lUnique Enchant Book"
        else if index of event-slot = 40:
            cancel event
            if player's level > 5:
                remove 5 from player's level
                give player book named "&6&lLegendary Enchant"
                send "You received a &6&lLegendary Enchant Book"
        else if index of event-slot = 43:
            cancel event
            if player's level > 6:
                remove 6 from player's level
                give player book named "&d&lMythical Enchant"
                send "You received a &d&lMythical Enchant Book"

on right click:
    if event-item is book named "&7&lCommon Enchant":
        set {custom.enchant} to random integer between 1 and 2
        if {custom.enchant} is 1:
            set {_book} to enchanted book named "&7&lSmelter"
            set line 1 of lore of {_book} to "&7Smelts the ores that you mine."
            set line 2 of lore of {_book} to "&eTool Encahntment"
            give player {_book}
            send "&7Received the &eSmelter&7 Enchantment" to player
        else if {custom.enchant} is 2:
            set {_book} to enchanted book named "&7Confusion"
            set line 1 of lore of {_book} to "&7Chance to apply &eBlindness &7and &eNausea effects"
            set line 2 of lore of {_book} to "&7to the enemy!"
            set line 3 of lore of {_book} to "&eSword Enchantment"
            give player {_book}
            send "&7Received the &eConfusion&7 Enchantment" to player
        else if event-item is book named "&6&lLegendary Enchant":
            chance of 100%:
                set {custom.enchant} to random integer between 1 and 1
                if {custom.enchant} is 1:
                    set {_book} to enchanted book named "&6&lOverload"
                    set line 1 of lore of {_book} to "&7Gives the player increased maxed health"
                    set line 2 of lore of {_book} to "&7Stacks up to 45 hearts"
                    set line 3 of lore of {_book} to ""
                    set line 4 of lore of {_book} to "Armor"
                else if event-item is book named "&d&lMythical Enchant":
                    chance of 100%:
                        set {custom.enchant} to random integer between 1 and 5
                        if {custom.enchant} is 1:
                            set {_book} to enchanted book named "&d&lGodly Overload"
                            set line 1 of lore of {_book} to "&d&lDescription:"
                            set line 2 of lore of {_book} to "&7Gives the player incrased maxed health"
                            set line 3 of lore of {_book} to "&7Stacks up to 50 hearts"
                            set line 4 of lore of {_book} to ""
                            set line 5 of lore of {_book} to "&d&lApplicable To:"
                            set line 6 of lore of {_book} to "&7Armor"
                            set line 7 of lore of {_book} to ""
                            set line 8 of lore of {_book} to "&d&lRequirements:"
                            set line 9 of lore of {_book} to "&7Must have Overload 3 on each piece"
                if {custom.enchant} is 2:
                    set {_book} to enchanted book named "&d&lHallucination"
                    set line 1 of lore of {_book} to "&d&lDescription:"
                    set line 2 of lore of {_book} to "&7Puts victim in webs and bedrock. VISUALLY"
                    set line 3 of lore of {_book} to "&7You can't hit the enemy, but you can be hit."
                    set line 4 of lore of {_book} to ""
                    set line 5 of lore of {_book} to "&d&lApplicable To:"
                    set line 6 of lore of {_book} to "&7Swords/Axes"
                    set line 7 of lore of {_book} to ""
                    set line 8 of lore of {_book} to "&d&lVISUAL ENCHANT"
                    set line 9 of lore of {_book} to "&7Visual Enchants mean that the effects that happen"
                    set line 10 of lore of {_book} to "&7Will only show for the victim/attacker."
                    if {custom.enchant} is 3:
                        set {_book} to enchanted book named "&d&lMama's Mad"
                        # maybe add a blank line of lore to each new line. Description "", effects: "" applicable to ""
                        set line 1 of lore of {_book} to "&d&lDescription:"
                        set line 2 of lore of {_book} to "&7Mama found the grades"
                        set line 3 of lore of {_book} to "&7Better start running."
                        set line 4 of lore of {_book} to ""
                        set line 5 of lore of {_book} to "&d&lEffects:"
                        set line 6 of lore of {_book} to "&7Gives the player Strength 2.5"
                        set line 7 of lore of {_book} to ""
                        set line 8 of lore of {_book} to "&d&lApplicable To:"
                        set line 9 of lore of {_book} to "&7Swords/Axes"
                        set line 10 of lore of {_book} to ""
                        set line 11 of lore of {_book} to "&d&lRequirements:"
                        set line 12 of lore of {_book} to "&7Must have Rage 3 on the item."
                        set line 13 of lore of {_book} to ""
                        set line 14 of lore of {_book} to "&d&lJOKE ENCHANT"
                        set line 15 of lore of {_book} to "&7While this is a joke enchant, it still gives effects."
                        if {custom.enchant} is 4:
                            set {_book} to enchanted book named "&d&lLightning"
                            set line 1 of lore of {_book} to ""
                            set line 2 of lore of {_book} to ""
                            set line 3 of lore of {_book} to ""
                            if {custom.enchant} is 5:
                                set {_book} to enchanted book named "&d&lFatty"
                                set line 1 of lore of {_book} to ""
                                set line 2 of lore of {_book} to ""
                                set line 3 of lore of {_book} to ""

on inventory click:
    if cursor slot of player is book named "&7Confusion", "&f&lEfficiency" or "&a&lFortune":
        set {_nm} to name of cursor slot of player
        if event-item is any sword:
            if event-item's lore doesn't contain "%{_nm}%":
                set {_a} to event-item
                cancel event
                set lore of {_a} to "%lore of {_a}%" and "%{_nm}%"
                wait 2 ticks
                set cursor slot of player to air
                set event-slot to {_a}
            else:
                cancel event
                send "&7You already have that enchantment!"


command /enchanter [<player>]:
    trigger:
        set {_gui} to a new chest inventory with 6 rows with name "&b&lEnchanter"
        set {_lbsg} to light blue stained glass pane named "&c&lHello"
        set {_barrier} to barrier named "&4&lFiller" # or change the barrier to red stained glass
        set {_air} to air
        set {_anvil} to anvil named "&f&lClick Me!" with lore "&7&lPut an item on the left side,", "&7&lPut an enchant book on the right side" and "Then click me and it will put the enchant on the item"
        set slot (integers between 0 and 53) of {_gui} to {_lbsg}
        set slot 31 of {_gui} to {_anvil}
        set slot (integers between 11 and 15) of {_gui} to {_barrier}
        set slot 20 and 24 of {_gui} to {_barrier}
        set slot 29 and 33 of {_gui} to {_air}
        open {_gui} to player
on inventory click:
    if name of event-inventory is "&b&lEnchanter":
        if index of event-slot = 31:
            cancel event
            if index of event-slot = 29:
                if event-slot contains any sword:
                    send "Hey!!!" to player
                    

command /customEnchantItemShop [<player>]:
    aliases: /ceis, /customenchantis, /ceitemshop
    trigger:
        set {_gui} to a new chest inventory with 4 rows named "&eCustom Enchant Item Shop"
        set slot 0 of {_gui} to paper named "&4&lKill Counter" with lore "Right-Click me onto an item to add a", "" and "Kill Counter to the item"
        set slot 1 of {_gui} to paper named "&4&lBlocks Mined Counter" with lore "Right-Click me onto an item to add a", "" and "Blocks Mined Counter to the item"
        set slot 2 of {_gui} to gunpowder named "&0&lBlack Scroll" with lore "Right-Click me onto an item to have a", "" and "Chance of removing a random enchant off of the item"
        set slot 3 of {_gui} to paper named "Transmog Scroll" with lore "Right-Click me onto an item to", "" and "Organize every enchant in order of rarity"
        set slot 4 of {_gui} to ink sac named "&d&lMythical Black Scroll" with lore "Right-Click me onto an item to remove", "", "A random &d&lMythical Enchant&r"       
        open {_gui} to player
on inventory click:
    if name of event-inventory is "&b&lEnchanter":
        cancel event

on death of player:
    loop drops:
        if lore of loop-item contains "&7Soulbound III":
            remove loop-item from drops
            set {_i} to loop-item
            set {_s} to size of lore of {_i}
            set line {_s} of lore of {_i} to "&7Soulbound II"
            add {_i} to {_to.give::*}
    wait 5 ticks
    add {_to.give::*} to victim's inventory

on death of player:
    loop drops:
        if lore of loop-item contains "&7Soulbound II":
            remove loop-item from drops
            set {_i} to loop-item
            set {_s} to size of lore of {_i}
            set line {_s} of lore of {_i} to "&7Soulbound I"
            add {_i} to {_to.give::*}
    wait 5 ticks
    add {_to.give::*} to victim's inventory

on death of player:
    loop drops:
        if lore of loop-item contains "&7Soulbound I":
            remove loop-item from drops
            set {_i} to loop-item
            set {_s} to size of lore of {_i}
            delete line {_s} of lore of {_i}
            add {_i} to {_to.give::*}
    wait 5 ticks
    add {_to.give::*} to victim's inventory


# I HAVE NO IDEA IF THIS ACTUALLY WORKS!!
on inventory click:
    if event-item is paper named "Transmog Scroll":
        set {_item} to event-item
        
        set {_lores::*} to lore of {_item}
        
        set {_rarityList::*} to "Common", "Uncommon", "Rare", "Epic" and "Legendary"
        set {_sortedLores::*} to sorted {_rarityList::*}
        
        set lore of {_item} to {_sortedLores::*}