Custom Enchants

  • 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
21
1
3
24
code_language.skript:
function GetLoreSize(p: player) :: integer:# :: integer :
    set {_Lore::*} to lore of {_p}'s tool
    loop {_Lore::*}:
        return size of {_Lore::*}

# TO-DO LIST

# make commands that will disable enchants/messages
# finish the actual enchanter gui
# figure out how to shorten and optimzie the code so that it looks cleaner
command /ce:
    aliases: /customenchants, /customenchant, /enchants
    trigger:
        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 gray stained glass pane
        set slot 10 of {_gui} to book named "&7&lCommon Enchant"
        set slot 13 of {_gui} to book named "&a&lUncommon Enchant"
        set slot 16 of {_gui} to book named "&1&lRare Enchant"
        set slot 37 of {_gui} to book named "&e&lUnique Enchant"
        set slot 40 of {_gui} to book named "&6&lLegendary Enchant"
        set slot 43 of {_gui} to book named "&d&lMythical Enchant"
        open {_gui} to player

on inventory click:
    if name of event-inventory is "&b&lCustom Enchants":
        if index of event-slot = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52 or 53:
            cancel event
            if index of event-slot = 10:
                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:
                if player's level > 2:
                    remove 2 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:
                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:
                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:
                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:
                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:
        # ╔ーーーーーーーーーーーーーーーーー╗
        # | &6 ╔       COMMON        ╗   |
        # | &6 ╚      ENCHANTS       ╝   |
        # ╚ーーーーーーーーーーーーーーーーー╝      
    if event-item is book named "&7&lCommon Enchant":
        set {custom.enchant} to random integer between 1 and 2
       
        # SMELTER
       
        if {custom.enchant} is 1:
            give player enchanted book named "&7&lSmelter" with lore "&7Smelts the ores that you mine." and "&eTools Enchantment"
            send "&7Received the &eSmelter&7 Enchantment" to player
       
        # CONFUSION
       
        else if {custom.enchant} is 2:
            set {custom.enchant.common.confusion.level} to a random integer between 1 and 3
            give player enchanted book named "&7Confusion {custom.enchant.common.confusion.level}" with lore "&7Chance to apply &eBlindness &7and &eNausea effects", "&7to the enemy!" and "&eSword Enchantment"
            send "&7Received the &eConfusion&7 Enchantment" to player


        # ╔ーーーーーーーーーーーーーーーーー╗
        # | &6 ╔      LEGENDARY      ╗   |
        # | &6 ╚      ENCHANTS       ╝   |
        # ╚ーーーーーーーーーーーーーーーーー╝  
    if event-item is book named "&6&lLegendary Enchant":
        set {custom.enchant} to a random integer between 1 and 2
       
        # OVERLOAD
       
        if {custom.enchant} is 1:
            set {custom.enchant.legendary.overload.level} to a random integer between 1 and 3
            give player enchanted book named "&6&lOverload {custom.enchant.legendary.overload.level}" with lore "&7Gives the player increased maxed health.", "&7Stacks up to 45 hearts", "" and "Armor"  

        if {custom.enchant} is 2:
            set {custom.enchant.legendary.double_strike.level} to a random integer between 1 and 3
            give player enchanted book named "&6&lDouble Strike {custom.enchant.legendary.double_strike.level}" with lore "&7Once activated makes the attacker hit the victim twice"
        # ╔ーーーーーーーーーーーーーーーーー╗
        # | &6 ╔      MYTHICAL       ╗   |
        # | &6 ╚      ENCHANTS       ╝   |
        # ╚ーーーーーーーーーーーーーーーーー╝      
    if event-item is book named "&d&lMythical Enchant":
        set {custom.enchant} to random integer between 1 and 5
       
        # GODLY OVERLOAD
       
        if {custom.enchant} is 1:
            set {custom.enchant.mythical.godly_overload.level} to a random integer between 1 and 3
            give player enchanted book named "&d&lGodly Overload {custom.enchant.mythical.godly_overload.level}" with lore "&d&lDescription:", "&7Gives the player incrased maxed health", "&7Stacks up to 50 hearts", "", "&d&lApplicable To:", "&7Armor" , "", "&d&lRequirements:" and "&7Must have Overload 3 on each piece"          
       
        # HALLUCINATION

        else if {custom.enchant} is 2:
            set {custom.enchant.mythical.hallucination.level} to a random integer between 1 and 5
            give player enchanted book named "&d&lHallucination {custom.enchant.mythical.hallucination.level}" with lore "&d&lDescription:", "&7Puts victim in webs and bedrock. VISUALLY", "&7You can't hit the enemy, but you can be hit.", "", "&d&lApplicable To:", "&7Swords/Axes" , "", "&d&lVISUAL ENCHANT", "&7Visual Enchants mean that the effects that happen" and "&7Will only show for the victim/attacker."

        # GODLY RAGE

        else if {custom.enchant} is 3:
            set {custom.enchant.superior_rage.level} to a random integer between 1 and 3
            give player enchanted book named "&d&lMama's Mad {custom.enchant.superior_rage.level}" with lore "&d&lDescription:", "&7Mama found the grades", "&7Better start running.", "", "&d&lEffects:", "&7Gives the player Strength 2.5", "", "&d&lApplicable To:", "&7Swords/Axes", "", "&d&lRequirements:" and "&7Must have Rage 3 on the item."
       
        # LIGHTNING
       
        else if {custom.enchant} is 4:
            set {custom.enchant.lightning.level} to a random integer between 1 and 3
            give player enchanted book named "&d&lLightning {custom.enchant.lightning.level}" with lore "", "" and ""
       
        # I DONT KNOW WHAT THIS IS
       
        else if {custom.enchant} is 5:
            give player enchanted book named "&d&lFatty" with lore "", "" and ""

on damage:
    if lore of attacker's weapon contains "&d&lHallucination I":
        chance of 100%:
            set block at location 1 meter forward and 1 meter right and 1 meter left and 1 meter backwards location of victim to glass

on inventory click:
    if cursor slot of player is enchanted book:
        if name of cursor slot of player is "&7&lSmelter":
            if event-item is any pickaxe:
                if lore of event-item doesn't contain "&7&lSmelter":
                    GetLoreSize(player)
                    if size of {_Lore::*} = 10:
                        send "You can not put any more enchants onto this item!"
                    else if size of {_Lore::*} <= 10:
                        cancel the event
                        set {_item} to event-item
                        remove {_item} from player
                        add "&7&lSmelter" to lore of {_item}
                        give player {_item}
                        send "&7[&e&lENCHANTER&7] &e&lSmelter&7 successfully applied!" to the player
                        set cursor slot of player to air
                else:
                    send "You already have the &7&lSmelter &renchant on this item!"
                    stop
        else if name of cursor slot of player is "&7Speed":
            if event-item is any boots:
                if lore of event-item doesn't contain "&7Speed":
                    cancel the event
                    set {_item} to event-item
                    remove {_item} from player
                    add "&7Speed" to lore of {_item}
                    give player {_item}
                    send "&7[&e&lENCHANTER&7] &eSpeed&7 successfully applied!" to the player
                    set cursor slot of player to air
        else if name of cursor slot of player is "&7Shockwave":
            if event-item is any chestplate:
                if lore of event-item doesn't contain "&7Shockwave":
                    cancel the event
                    set {_item} to event-item
                    remove {_item} from player
                    add "&7Shockwave" to lore of {_item}
                    give player {_item}
                    send "&7[&e&lENCHANTER&7] &eShockwave&7 successfully applied!" to the player
                    set cursor slot of player to air
        else if name of cursor slot of player is "&7Escapist":
            if event-item is any helmet:
                if lore of event-item doesn't contain "&7Escapist":
                    cancel the event
                    set {_item} to event-item
                    remove {_item} from player
                    add "&7Escapist" to lore of {_item}
                    give player {_item}
                    send "&7[&e&lENCHANTER&7] &eEscapist&7 successfully applied!" to the player
                    set cursor slot of player to air
        else if name of cursor slot of player is "&7Bounce":
            if event-item is any leggings:
                if lore of event-item doesn't contain "&7Bounce":
                    cancel the event
                    set {_item} to event-item
                    remove {_item} from player
                    add "&7Bounce" to lore of {_item}
                    give player {_item}
                    send "&7[&e&lENCHANTER&7] &eBounce&7 successfully applied!" to the player
                    set cursor slot of player to air

command /enchanter [<offline player>]:
    trigger:
        set {_gui} to a new chest inventory with 6 rows with name "&b&lEnchanter"
        set slot (integers between 0 and 53) of {_gui} to black stained glass pane named "&c&lHello"
        set slot 31 of {_gui} 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 11 and 15) of {_gui} to barrier named "&4&lFiller"
        set slot 20 and 24 of {_gui} to barrier named "&4&lFiller"
        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 = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 30, 32, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52 or 53:
            cancel event

# on inventory click:
#     if name of event-inventory is "&b&lEnchanter":
#         if index of event-slot = 31:
#             # cancel event
#             if slot 29 of player's current inventory contains any sword:
#                 # make console execute "/tell Tewahh Hi!"
#                 if slot 33 of player's current inventory contains any book:
#                     broadcast "Hey, %player%, you have a sword in slot 29, and a book in slot 33."
#                     make console execute "/tell Tewahh Hello!"
on inventory click:
    if name of event-inventory is "&b&lEnchanter":
        if index of event-slot = 31:
            if slot 29 of player's current inventory is any sword:
                if slot 33 of player's current inventory is any book:
                    cancel event
                    make console execute "/tell Tewahh Hi!"

on mine:
    if event-block is gold ore, iron ore, ancient debris, sand or cobblestone:
        if lore of player's tool contains "&7&lSmelter":
            send "hey!" to player


# on damage:
#     if lore of attacker's weapon contains "&d&lLightning":
#         if difference between now and {%attacker's uuid%.lightningEnchant.lastUsed} is less than 15 seconds:
#         else:
#             apply slowness 5 to the victim for 5 seconds
#             loop 3 times:
#                 strike lightning effect at the victim
#                 wait 1 second
#             send "&8&lThe &d&lLightning &8&leffect has activated"
#             set {%attacker's uuid%.lightningEnchant.lastUsed} to now

# on damage:
#     if lore of attacker's weapon contains "&7Crippling":
#         chance of 10%:
#             apply blindness 1 to victim for 3 seconds
#             apply slowness 2 to victim for 3 seconds

# on damage:
#     if lore of victim's chestplate contains "&7Shockwave":
#         chance of 12%:
#             apply nausea 2 to attacker for 2 seconds
#             strike lightning effect at the attacker
#             damage attacker by 1 heart
                       
# on damage:
#     if victim's health <= 3:
#         if lore of victim's helmet contains "&7Escapist":
#             apply swiftness 2 to victim for 5 seconds
#             apply invisibility to victim for 5 seconds
#             wait 5 seconds
#             remove swiftness from victim
               
# every 2 seconds:
#     loop all players:
#         if lore of loop-player's boots contains "&7Speed I":
#             apply swiftness 1 to loop-player for 2.01 seconds
#         else if lore of loop-player's boots contains "&7Speed II":
#             apply swiftness 2 to loop-player for 2.01 seconds

# every 2 seconds:
#     loop all players:
#         if lore of loop-player's leggings contains "&7Bounce":
#             apply jump boost 2 to loop-player for 2.01 seconds


So, there's a massive amount of code here, and its very chunky/clunky and hard to read. I want to fix that, someone told me to use functions, but I have no idea how to use functions enough to fix everything, if someone could point me in the right direction, and help me. That would be awesome. (don't spoon-feed me the code, I just want some guidance)
 
A little late here but the first big thing I can suggest is removing all commented/useless code and moving it to a different file. Furthermore, before you start using functions I recommend you organize and then sort the code by event (ie: on inventory click, on right click, commands). I also recommend you space things out. Sections like your "on inventory click" event are filled with else ifs that have absolutely no blank space separating them from the previous line of code. I would suggest you add a few empty lines to help break it up and make it easier to read. Lastly, I would add comments to make using the Find (CTRL + F) feature a lot easier. This will help navigate your code. I see you've done something similar with your large on right click event, sections like
Code:
#lightning
#common enchants
#i dont know what this is
#mythic enchants
#legendary enchants
and more are making it easier to navigate your code, so add more of them.
 
  • Like
Reactions: Luke_Sky_Walker
A little late here but the first big thing I can suggest is removing all commented/useless code and moving it to a different file. Furthermore, before you start using functions I recommend you organize and then sort the code by event (ie: on inventory click, on right click, commands). I also recommend you space things out. Sections like your "on inventory click" event are filled with else ifs that have absolutely no blank space separating them from the previous line of code. I would suggest you add a few empty lines to help break it up and make it easier to read. Lastly, I would add comments to make using the Find (CTRL + F) feature a lot easier. This will help navigate your code. I see you've done something similar with your large on right click event, sections like
Code:
#lightning
#common enchants
#i dont know what this is
#mythic enchants
#legendary enchants
and more are making it easier to navigate your code, so add more of them.
Being late is fine, but, now its my time to be a little late, how would I shorten my code and use functions, loops etc. any tips/sites/information is greatly appreciated.