Skript Optimizations/Practices Help

  • 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
26
1
3
24
Code:
function giveEnchantBook(player: player, item: item, name: text):
    give {_player} {_item} named "%{_name}%"
function giveCustomEnchantBook(player: player, item: item, name: text, lore1: text = "", lore2: text = "", lore3: text = "", lore4: text = "", lore5: text = "", lore6: text = "", lore7: text = "", lore8: text = ""):
    give {_player} {_item} named "%{_name}%" with lore {_lore1}, {_lore2}, {_lore3}, {_lore4}, {_lore5}, {_lore6}, {_lore7}, {_lore8}
options:
    commonCustomEnchantLevel: 15
    commonEnchantName: &7&lCommon Enchant
 
    uncommonCustomEnchantLevel: 30
    uncommonEnchantName: &a&lUncommon Enchant
 
    rareCustomEnchantLevel: 45
    rareEnchantName: &9&lRare Enchant
 
    uniqueCustomEnchantLevel: 60
    uniqueEnchantName: &e&lUnique Enchant
 
    legendaryCustomEnchantLevel: 75
    legendaryEnchantName: &6&lLegendary Enchant
 
    mythicalCustomEnchantLevel: 100
    mythicalEnchantName: &d&lMythical Enchant
function ceGUI(slot: integer, item: item, name: text):
    set slot {_slot} of {_gui} to {_item} named {_name}
command /ce:
    aliases: /customenchants, /customenchant, /enchants
    trigger:
        set {_gui} to a new chest inventory with 6 rows named "&b&lCustom Enchants"
        set slot (integers between 0 and 53) of {_gui} to gray stained glass pane
        ceGUI(10, glowing book, "{@commonEnchantName}")
        ceGUI(13, glowing book, "{@uncommonEnchantName}")
        ceGUI(16, glowing book, "{@rareEnchantName}")
        ceGUI(37, glowing book, "{@uniqueEnchantName}")
        ceGUI(40, glowing book, "{@legendaryEnchantName}")
        ceGUI(43, glowing book, "{@mythicalEnchantName}")
        open {_gui} to player
function buyCustomEnchantBook(Custom_Enchant_Level: integer, Custom_Enchant_Name: text):
    if {_p}'s level >= "{_Custom_Enchant_Level}":
        remove ("{_Custom_Enchant_Level}" parsed as an integer) from {_p}'s level
        giveEnchantBook({_p}, book, "{_Custom_Enchant_Name}")
        send "You received a {_Custom_Enchant_Name} Book" to {_p}
on inventory click:
    if name of event-inventory is "&x&F&F&F&F&F&F&lC&x&F&5&E&B&F&5&lu&x&E&B&D&8&E&B&ls&x&E&2&C&4&E&2&lt&x&D&8&B&1&D&8&lo&x&C&E&9&D&C&E&lm &x&C&4&8&9&C&4&lE&x&B&B&7&6&B&B&ln&x&B&1&6&2&B&1&lc&x&A&7&4&E&A&7&lh&x&9&D&3&B&9&D&la&x&9&4&2&7&9&4&ln&x&8&A&1&4&8&A&lt&x&8&0&0&0&8&0&ls":
        if index of event-slot = (integers between 0 and 54):
            cancel event
     
        if index of event-slot = 10:
            buyCustomEnchantBook({@commonCustomEnchantLevel}, "{@commonEnchantName}")
     
        else if index of event-slot = 13:
            buyCustomEnchantBook({@uncommonCustomEnchantLevel}, "{@uncommonEnchantName}")
     
        else if index of event-slot = 16:
            buyCustomEnchantBook({@rareCustomEnchantLevel}, "{@rareEnchantName}")
        else if index of event-slot = 37:
            buyCustomEnchantBook({@uniqueCustomEnchantLevel}, "{@uniqueEnchantName}")
     
        else if index of event-slot = 40:
            buyCustomEnchantBook({@legendaryCustomEnchantLevel}, "{@legendaryEnchantName}")
        else if index of event-slot = 43:
            buyCustomEnchantBook({@mythicalCustomEnchantLevel}, "{@mythicalEnchantName}")

on right click:
    if event-item is book named "{@commonEnchantName}":
        set {_enchantInteger} to a random integer between 1 and 2
        if {_enchantInteger} is 1:
            giveCustomEnchantBook(player, enchanted book, "&7&lSmelter", "&l&oDescription:", "&7&lSmelts ores into ingot form.", "", "&l&oAppliable To:", "Tools", "", "&l&oRarity:", "&7&lCommon")
        else if {_enchantInteger} is 2:
            set {_nausea_level} to random integer between 1 and 100
            if {_nausea_level} = (integers between 1 and 75): # 75%
                set {_common::nausea::level} to 1
            else if {_nausea_level} = (integers between 75 and 90):
                set {_common::nausea::level} to 2
            else if {_nausea_level} = (integers between 90 and 100):
                set {_common::nausea::level} to 3
            giveCustomEnchantBook(player, enchanted book, "&7&lNausea %{_common::nausea::level}%", "&l&oDescription:", "&7")
function applyEffectFromCustomEnchant(attacker: player, Enchant_Name: text, chance: integer, Effect_Name: text, Effect_Level: text, victim: player, Effect_Time: text):
    if lore of {_attacker}'s held item contains "{_Enchant_Name}":
        chance of {_chance}%:
            apply ({_Enchant_Name} parsed as potion effect type) ({_Effect_Level} parsed as number) to {_victim} for ({_Effect_Time} parsed as timespan)
on damage:
    if victim is a player:
        # NAUSEA
        applyEffectFromCustomEnchant(attacker, "&7&lNausea III", 6, "nausea", "3", victim, "13 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lNausea II", 10, "nausea", "2", victim, "10 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lNausea I", 14, "nausea", "1", victim, "7 seconds")
        # POISON
        applyEffectFromCustomEnchant(attacker, "&7&lPoison V", 6, "poison", "5", victim, "10 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lPoison IV", 11, "poison", "4", victim, "8 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lPoison III", 16, "poison", "3", victim, "6 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lPoison II", 21, "poison", "2", victim, "4 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lPoison I", 26, "poison", "1", victim, "2 seconds")
        # WITHER
        applyEffectFromCustomEnchant(attacker, "&7&lWither V", 6, "wither", "5", victim, "10 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lWither IV", 11, "wither", "4", victim, "8 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lWither III", 16, "wither", "3", victim, "6 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lWither II", 21, "wither", "2", victim, "4 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lWither I", 26, "wither", "1", victim, "2 seconds")
        # BLINDNESS
        applyEffectFromCustomEnchant(attacker, "&7&lBlindness V", 6, "blindness", "5", victim, "10 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lBlindness IV", 11, "blindness", "4", victim, "8 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lBlindness III", 16, "blindness", "3", victim, "6 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lBlindness II", 21, "blindness", "2", victim, "4 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lBlindness I", 26, "blindness", "1", victim, "2 seconds")
        # SLOWNESS
        applyEffectFromCustomEnchant(attacker, "&7&lSlowness V", 6, "slowness", "5", victim, "10 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lSlowness IV", 11, "slowness", "4", victim, "8 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lSlowness III", 16, "slowness", "3", victim, "6 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lSlowness II", 21, "slowness", "2", victim, "4 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lSlowness I", 26, "slowness", "1", victim, "2 seconds")
        # WEAKNESS
        applyEffectFromCustomEnchant(attacker, "&7&lWeakness V", 6, "weakness", "5", victim, "10 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lWeakness IV", 11, "weakness", "4", victim, "8 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lWeakness III", 16, "weakness", "3", victim, "6 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lWeakness II", 21, "weakness", "2", victim, "4 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lWeakness I", 26, "weakness", "1", victim, "2 seconds")
        # HUNGER
        applyEffectFromCustomEnchant(attacker, "&7&lHunger V", 6, "hunger", "5", victim, "10 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lHunger IV", 11, "hunger", "4", victim, "8 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lHunger III", 16, "hunger", "3", victim, "6 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lHunger II", 21, "hunger", "2", victim, "4 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lHunger I", 26, "hunger", "1", victim, "2 seconds")
        # DARKNESS
        applyEffectFromCustomEnchant(attacker, "&7&lDarkness V", 6, "darkness", "5", victim, "10 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lDarkness IV", 11, "darkness", "4", victim, "8 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lDarkness III", 16, "darkness", "3", victim, "6 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lDarkness II", 21, "darkness", "2", victim, "4 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lDarkness I", 26, "darkness", "1", victim, "2 seconds")


how do I make this more efficient? I'm currently using functions to make this reusable. But, I'm not 100% sure if I'm doing it the best way that I can? Because it just looks very clunky, and unorganized. If you could tell me what I'm doing wrong, ( if anything ), and how I could fix it?[/CODE]
 
Please use proper CODE formatting. What you've used is ICODE (In-line coding). also why are you declaring functions before options?
 
What you can do is edit your applyEffectFromCustomEnchant() function to grab the roman numeral at the end of the name, convert it into an integer, and apply that level of the potion so you don't have to have several different lines every time.
 
Please use proper CODE formatting. What you've used is ICODE (In-line coding). also why are you declaring functions before options?
Yea, I was editing the thread, I accidentally pressed CTRL+Enter. Also, about the functions, I did this because my skript was all over the place, and just haven't moved any of the functions to be after the options.
 
What you can do is edit your applyEffectFromCustomEnchant() function to grab the roman numeral at the end of the name, convert it into an integer, and apply that level of the potion so you don't have to have several different lines every time.
I assume there's more that I can do to make things look better/be more organized & efficient?
 
I assume there's more that I can do to make things look better/be more organized & efficient?
Besides maybe moving some of the other functions/commands to different files, no, not really. I would add linebreaks between your triggers (events, commands, function declarations) so that they look nice. For example:
Code:
on join:
    #stuff

on leave:
    #stuff
 
#as opposed to

on join:
    #stuff
on leave:
    #stuff
Another thing you should do is organize your script. All your commands should be in one spot, all event handlers in one spot, all function declerations in one spot, etc. You shouldn't go like this
Code:
#miscellanous code unrelated to functions and unorganized

function example():
    #do stuff
on death:
    example()
function example2():
    #do stuff
You should instead be declaring them all in the same spot.

Also, why do your functions have so many arguments? Instead of 7 lore variables, just use one and use skript's built in %nl% breaker to add new lines. One argument set to "jsfdufjsioijfosjofJO %nl%jsofjsoidjfiosjeoif" is still easier to make sense of while reading the script than "fusf", "asijdiw", "Aasjd9wa9-f8a", "shifhsiu", "efskfo", "shfyahifhias", "sdfiuhsifh" (aka {_lore1}, {_lore2}, {_lore3}, {_lore4}, {_lore5}, it's just unecessary). You can space out your %nl% from the actual text to make it easier to read, like i did above


Getting rid of your 38 potion effect applying lines is the biggest thing rn though.
 
Besides maybe moving some of the other functions/commands to different files, no, not really. I would add linebreaks between your triggers (events, commands, function declarations) so that they look nice. For example:
Code:
on join:
    #stuff

on leave:
    #stuff
 
#as opposed to

on join:
    #stuff
on leave:
    #stuff
Another thing you should do is organize your script. All your commands should be in one spot, all event handlers in one spot, all function declerations in one spot, etc. You shouldn't go like this
Code:
#miscellanous code unrelated to functions and unorganized

function example():
    #do stuff
on death:
    example()
function example2():
    #do stuff
You should instead be declaring them all in the same spot.

Also, why do your functions have so many arguments? Instead of 7 lore variables, just use one and use skript's built in %nl% breaker to add new lines. One argument set to "jsfdufjsioijfosjofJO %nl%jsofjsoidjfiosjeoif" is still easier to make sense of while reading the script than "fusf", "asijdiw", "Aasjd9wa9-f8a", "shifhsiu", "efskfo", "shfyahifhias", "sdfiuhsifh" (you can space out your %nl% from the actual text to make it easier to read).


Getting rid of your 38 potion effect applying lines is the biggest thing rn though.
Ill get started on doing this now. I notice that ```
What you can do is edit your applyEffectFromCustomEnchant() function to grab the roman numeral at the end of the name, convert it into an integer, and apply that level of the potion so you don't have to have several different lines every time.
```
you said this, but my brain is kinda dead rn lol. could you give me a base starter? I'd do the rest, if not, 100% fine.
 
When making custom enchantments you should use NBT to store the enchantment's level and use lore only to display it.

function giveCustomEnchantBook(player: player, item: item, name: text, lore1: text = "", lore2: text = "", lore3: text = "", lore4: text = "", lore5: text = "", lore6: text = "", lore7: text = "", lore8: text = ""):
the 8 lore parameters can be simplified to 1 plural parameter, lore: texts and then {_lore::*} in the code

You also have lots of unnecessary timespan/integer parsing in your code.



If I were making a custom enchantment script I would start by making an enchantment registry like:
Code:
# showing in multiple lines so it is easier to read, not actual code
function registerEnchantment(
  id: "enchantment-id"       # the id to store in nbt when setting and getting enchantment level, not visible to user
  display: "Enchantment"     # display name of the enchantment visible to user
  max.level: 5               # max level of enchantment
)

Then I would make functions to set and get enchantment levels of items
Code:
function setEnchantmentLevel(
  item: item            # item to enchant
  enchantment: string   # enchantment id used when registering the enchantment, stop if enchantment doesn't exist
  level: int            # level to set, remove enchantment if 0
)
# return the enchanted item in the function (with nbt and lore set)
# you can make an int to roman conversion function if you want to display enchantments in roman numerals

function getEnchantmentLevel(
  item: item              # item to get enchantment level of
  enchantment: string     # enchantment id used when registering enchantment, return -1 if enchantment doesn't exist
)

Now my simple enchantment registry is enough to recreate that whole script.
example:
Code:
on damage:
  set {_level} to getEnchantmentLevel((attacker's tool), "poison")
  stop if {_level} is -1   # item is not enchanted with 'poison'
  set {_duration} to "%{_level} * 2% seconds" parsed as timespan  # non literal timespans must be parsed
  set {_amplifier} to ceil({_level} * 1.5)
 
  # code to apply poison {_amplifier} for {_duration}...
 
When making custom enchantments you should use NBT to store the enchantment's level and use lore only to display it.

function giveCustomEnchantBook(player: player, item: item, name: text, lore1: text = "", lore2: text = "", lore3: text = "", lore4: text = "", lore5: text = "", lore6: text = "", lore7: text = "", lore8: text = ""):
the 8 lore parameters can be simplified to 1 plural parameter, lore: texts and then {_lore::*} in the code

You also have lots of unnecessary timespan/integer parsing in your code.



If I were making a custom enchantment script I would start by making an enchantment registry like:
Code:
# showing in multiple lines so it is easier to read, not actual code
function registerEnchantment(
  id: "enchantment-id"       # the id to store in nbt when setting and getting enchantment level, not visible to user
  display: "Enchantment"     # display name of the enchantment visible to user
  max.level: 5               # max level of enchantment
)

Then I would make functions to set and get enchantment levels of items
Code:
function setEnchantmentLevel(
  item: item            # item to enchant
  enchantment: string   # enchantment id used when registering the enchantment, stop if enchantment doesn't exist
  level: int            # level to set, remove enchantment if 0
)
# return the enchanted item in the function (with nbt and lore set)
# you can make an int to roman conversion function if you want to display enchantments in roman numerals

function getEnchantmentLevel(
  item: item              # item to get enchantment level of
  enchantment: string     # enchantment id used when registering enchantment, return -1 if enchantment doesn't exist
)

Now my simple enchantment registry is enough to recreate that whole script.
example:
Code:
on damage:
  set {_level} to getEnchantmentLevel((attacker's tool), "poison")
  stop if {_level} is -1   # item is not enchanted with 'poison'
  set {_duration} to "%{_level} * 2% seconds" parsed as timespan  # non literal timespans must be parsed
  set {_amplifier} to ceil({_level} * 1.5)
 
  # code to apply poison {_amplifier} for {_duration}...
for example, if someone has an item, with multiple enchants, how would I make the code for that?
 
When making custom enchantments you should use NBT to store the enchantment's level and use lore only to display it.

function giveCustomEnchantBook(player: player, item: item, name: text, lore1: text = "", lore2: text = "", lore3: text = "", lore4: text = "", lore5: text = "", lore6: text = "", lore7: text = "", lore8: text = ""):
the 8 lore parameters can be simplified to 1 plural parameter, lore: texts and then {_lore::*} in the code

You also have lots of unnecessary timespan/integer parsing in your code.



If I were making a custom enchantment script I would start by making an enchantment registry like:
Code:
# showing in multiple lines so it is easier to read, not actual code
function registerEnchantment(
  id: "enchantment-id"       # the id to store in nbt when setting and getting enchantment level, not visible to user
  display: "Enchantment"     # display name of the enchantment visible to user
  max.level: 5               # max level of enchantment
)

Then I would make functions to set and get enchantment levels of items
Code:
function setEnchantmentLevel(
  item: item            # item to enchant
  enchantment: string   # enchantment id used when registering the enchantment, stop if enchantment doesn't exist
  level: int            # level to set, remove enchantment if 0
)
# return the enchanted item in the function (with nbt and lore set)
# you can make an int to roman conversion function if you want to display enchantments in roman numerals

function getEnchantmentLevel(
  item: item              # item to get enchantment level of
  enchantment: string     # enchantment id used when registering enchantment, return -1 if enchantment doesn't exist
)

Now my simple enchantment registry is enough to recreate that whole script.
example:
Code:
on damage:
  set {_level} to getEnchantmentLevel((attacker's tool), "poison")
  stop if {_level} is -1   # item is not enchanted with 'poison'
  set {_duration} to "%{_level} * 2% seconds" parsed as timespan  # non literal timespans must be parsed
  set {_amplifier} to ceil({_level} * 1.5)
 
  # code to apply poison {_amplifier} for {_duration}...
alright so, I was kinda wondering how to make these custom enchants in skript? could you help me?
 
When making custom enchantments you should use NBT to store the enchantment's level and use lore only to display it.

function giveCustomEnchantBook(player: player, item: item, name: text, lore1: text = "", lore2: text = "", lore3: text = "", lore4: text = "", lore5: text = "", lore6: text = "", lore7: text = "", lore8: text = ""):
the 8 lore parameters can be simplified to 1 plural parameter, lore: texts and then {_lore::*} in the code

You also have lots of unnecessary timespan/integer parsing in your code.



If I were making a custom enchantment script I would start by making an enchantment registry like:
Code:
# showing in multiple lines so it is easier to read, not actual code
function registerEnchantment(
  id: "enchantment-id"       # the id to store in nbt when setting and getting enchantment level, not visible to user
  display: "Enchantment"     # display name of the enchantment visible to user
  max.level: 5               # max level of enchantment
)

Then I would make functions to set and get enchantment levels of items
Code:
function setEnchantmentLevel(
  item: item            # item to enchant
  enchantment: string   # enchantment id used when registering the enchantment, stop if enchantment doesn't exist
  level: int            # level to set, remove enchantment if 0
)
# return the enchanted item in the function (with nbt and lore set)
# you can make an int to roman conversion function if you want to display enchantments in roman numerals

function getEnchantmentLevel(
  item: item              # item to get enchantment level of
  enchantment: string     # enchantment id used when registering enchantment, return -1 if enchantment doesn't exist
)

Now my simple enchantment registry is enough to recreate that whole script.
example:
Code:
on damage:
  set {_level} to getEnchantmentLevel((attacker's tool), "poison")
  stop if {_level} is -1   # item is not enchanted with 'poison'
  set {_duration} to "%{_level} * 2% seconds" parsed as timespan  # non literal timespans must be parsed
  set {_amplifier} to ceil({_level} * 1.5)
 
  # code to apply poison {_amplifier} for {_duration}...
Code:
options:
    commonCustomEnchantLevel: 15
    commonEnchantName: &7&lCommon Enchant
    
    uncommonCustomEnchantLevel: 30
    uncommonEnchantName: &a&lUncommon Enchant
    
    rareCustomEnchantLevel: 45
    rareEnchantName: &9&lRare Enchant
    
    uniqueCustomEnchantLevel: 60
    uniqueEnchantName: &e&lUnique Enchant
    
    legendaryCustomEnchantLevel: 75
    legendaryEnchantName: &6&lLegendary Enchant
    
    mythicalCustomEnchantLevel: 100
    mythicalEnchantName: &d&lMythical Enchant

function giveCustomEnchantBook(player: player, item: item, name: text, lore: text = ""):
    give {_player} {_item} named "%{_name}%" with lore {_lore}

function ceGUI(slot: integer, item: item, name: text):
    set slot {_slot} of {_gui} to {_item} named {_name}

function buyCustomEnchantBook(Custom_Enchant_Level: integer, Custom_Enchant_Name: text):
    if {_p}'s level >= "%{_Custom_Enchant_Level}%":
        remove ("%{_Custom_Enchant_Level}%" parsed as an integer) from {_p}'s level
        giveCustomEnchantBook({_p}, book, "%{_Custom_Enchant_Name}%")
        send "You received a %{_Custom_Enchant_Name}% Book" to {_p}

function applyEffectFromCustomEnchant(attacker: player, Enchant_Name: text, chance: integer, victim: player, Effect_Time: text):
    if lore of {_attacker}'s held item contains "%{_Enchant_Name}%":
        chance of {_chance}:
            set {_split::*} to uncoloured line 1 of {_p}'s tool's lore split at " "
            set {_split::2} to {_level} parsed as a number
            apply ({_Enchant_Name} parsed as potion effect type) {_level} to {_victim} for ({_Effect_Time} parsed as timespan)


command /ce:
    aliases: /customenchants, /customenchant, /enchants
    trigger:
        set {_gui} to a new chest inventory with 6 rows named "&b&lCustom Enchants"
        set slot (integers between 0 and 53) of {_gui} to gray stained glass pane
        ceGUI(10, glowing book, "{@commonEnchantName}")
        ceGUI(13, glowing book, "{@uncommonEnchantName}")
        ceGUI(16, glowing book, "{@rareEnchantName}")
        ceGUI(37, glowing book, "{@uniqueEnchantName}")
        ceGUI(40, glowing book, "{@legendaryEnchantName}")
        ceGUI(43, glowing book, "{@mythicalEnchantName}")
        open {_gui} to player

on inventory click:
    if name of event-inventory is "&x&F&F&F&F&F&F&lC&x&F&5&E&B&F&5&lu&x&E&B&D&8&E&B&ls&x&E&2&C&4&E&2&lt&x&D&8&B&1&D&8&lo&x&C&E&9&D&C&E&lm &x&C&4&8&9&C&4&lE&x&B&B&7&6&B&B&ln&x&B&1&6&2&B&1&lc&x&A&7&4&E&A&7&lh&x&9&D&3&B&9&D&la&x&9&4&2&7&9&4&ln&x&8&A&1&4&8&A&lt&x&8&0&0&0&8&0&ls":
        if index of event-slot = (integers between 0 and 54):
            cancel event
        
        if index of event-slot = 10:
            buyCustomEnchantBook({@commonCustomEnchantLevel}, "{@commonEnchantName}")
        
        else if index of event-slot = 13:
            buyCustomEnchantBook({@uncommonCustomEnchantLevel}, "{@uncommonEnchantName}")
        
        else if index of event-slot = 16:
            buyCustomEnchantBook({@rareCustomEnchantLevel}, "{@rareEnchantName}")

        else if index of event-slot = 37:
            buyCustomEnchantBook({@uniqueCustomEnchantLevel}, "{@uniqueEnchantName}")
        
        else if index of event-slot = 40:
            buyCustomEnchantBook({@legendaryCustomEnchantLevel}, "{@legendaryEnchantName}")

        else if index of event-slot = 43:
            buyCustomEnchantBook({@mythicalCustomEnchantLevel}, "{@mythicalEnchantName}")

on right click:
    if event-item is book named "{@commonEnchantName}":
        set {_enchantInteger} to a random integer between 1 and 2

        if {_enchantInteger} is 1:
            giveCustomEnchantBook(player, enchanted book, "&7&lSmelter %nl% &l&oDescription: %nl% &7&lSmelts ores into ingot form %nl%%nl% %nl% &l&oAppliable To: %nl% Tools %nl%%nl% %nl% &l&oRarity: %nl% &7&lCommon")
        else if {_enchantInteger} is 2:
            set {_nausea_level} to random integer between 1 and 100
            if {_nausea_level} = (integers between 1 and 75): # 75%
                set {_common::nausea::level} to 1
            else if {_nausea_level} = (integers between 75 and 90):
                set {_common::nausea::level} to 2
            else if {_nausea_level} = (integers between 90 and 100):
                set {_common::nausea::level} to 3
            giveCustomEnchantBook(player, enchanted book, "&7&lNausea %{_common::nausea::level}% %nl% &l&oDescription: %nl%")

on damage:
    if victim is a player:
        # NAUSEA
        applyEffectFromCustomEnchant(attacker, "&7&lNausea 3", 6, victim, "13 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lNausea 2", 10, victim, "10 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lNausea 1", 14, victim, "7 seconds")
        # POISON
        applyEffectFromCustomEnchant(attacker, "&7&lPoison 5", 6, victim, "10 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lPoison 4", 11, victim, "8 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lPoison 3", 16, victim, "6 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lPoison 2", 21, victim, "4 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lPoison 1", 26, victim, "2 seconds")
        # WITHER
        applyEffectFromCustomEnchant(attacker, "&7&lWither 5", 6, victim, "10 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lWither 4", 11, victim, "8 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lWither 3", 16, victim, "6 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lWither 2", 21, victim, "4 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lWither 1", 26, victim, "2 seconds")
        # BLINDNESS
        applyEffectFromCustomEnchant(attacker, "&7&lBlindness 5", 6, victim, "10 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lBlindness 4", 11, victim, "8 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lBlindness 3", 16, victim, "6 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lBlindness 2", 21, victim, "4 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lBlindness 1", 26, victim, "2 seconds")
        # SLOWNESS
        applyEffectFromCustomEnchant(attacker, "&7&lSlowness 5", 6, victim, "10 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lSlowness 4", 11, victim, "8 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lSlowness 3", 16, victim, "6 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lSlowness 2", 21, victim, "4 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lSlowness 1", 26, victim, "2 seconds")
        # WEAKNESS
        applyEffectFromCustomEnchant(attacker, "&7&lWeakness 5", 6, victim, "10 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lWeakness 4", 11, victim, "8 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lWeakness 3", 16, victim, "6 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lWeakness 2", 21, victim, "4 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lWeakness 1", 26, victim, "2 seconds")
        # HUNGER
        applyEffectFromCustomEnchant(attacker, "&7&lHunger 5", 6, victim, "10 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lHunger 4", 11, victim, "8 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lHunger 3", 16, victim, "6 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lHunger 2", 21, victim, "4 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lHunger 1", 26, victim, "2 seconds")
        # DARKNESS
        applyEffectFromCustomEnchant(attacker, "&7&lDarkness 5", 6, victim, "10 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lDarkness 4", 11, victim, "8 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lDarkness 3", 16, victim, "6 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lDarkness 2", 21, victim, "4 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lDarkness 1", 26, victim, "2 seconds")

this is currently what I have... could you help me out with making it more efficient?
 
lore should be type of texts, not text, so it can be formatted as a list and you can still do easy multiple lines. also you don't need to stringify name.

Also now its even easier just grab the effect and the number from the lore of the item lol you don't have to do anything with numerals.
 
lore should be type of texts, not text, so it can be formatted as a list and you can still do easy multiple lines. also you don't need to stringify name.

Also now its even easier just grab the effect and the number from the lore of the item lol you don't have to do anything with numerals.
I'll do that as well, but I was also wondering how I could simplify
Code:
applyEffectFromCustomEnchant(attacker, "&7&lNausea 3", 6, victim, "13 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lNausea 2", 10, victim, "10 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lNausea 1", 14, victim, "7 seconds")
        # POISON
        applyEffectFromCustomEnchant(attacker, "&7&lPoison 5", 6, victim, "10 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lPoison 4", 11, victim, "8 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lPoison 3", 16, victim, "6 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lPoison 2", 21, victim, "4 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lPoison 1", 26, victim, "2 seconds")
        # WITHER
        applyEffectFromCustomEnchant(attacker, "&7&lWither 5", 6, victim, "10 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lWither 4", 11, victim, "8 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lWither 3", 16, victim, "6 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lWither 2", 21, victim, "4 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lWither 1", 26, victim, "2 seconds")
        # BLINDNESS
        applyEffectFromCustomEnchant(attacker, "&7&lBlindness 5", 6, victim, "10 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lBlindness 4", 11, victim, "8 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lBlindness 3", 16, victim, "6 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lBlindness 2", 21, victim, "4 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lBlindness 1", 26, victim, "2 seconds")
        # SLOWNESS
        applyEffectFromCustomEnchant(attacker, "&7&lSlowness 5", 6, victim, "10 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lSlowness 4", 11, victim, "8 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lSlowness 3", 16, victim, "6 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lSlowness 2", 21, victim, "4 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lSlowness 1", 26, victim, "2 seconds")
        # WEAKNESS
        applyEffectFromCustomEnchant(attacker, "&7&lWeakness 5", 6, victim, "10 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lWeakness 4", 11, victim, "8 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lWeakness 3", 16, victim, "6 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lWeakness 2", 21, victim, "4 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lWeakness 1", 26, victim, "2 seconds")
        # HUNGER
        applyEffectFromCustomEnchant(attacker, "&7&lHunger 5", 6, victim, "10 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lHunger 4", 11, victim, "8 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lHunger 3", 16, victim, "6 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lHunger 2", 21, victim, "4 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lHunger 1", 26, victim, "2 seconds")
        # DARKNESS
        applyEffectFromCustomEnchant(attacker, "&7&lDarkness 5", 6, victim, "10 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lDarkness 4", 11, victim, "8 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lDarkness 3", 16, victim, "6 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lDarkness 2", 21, victim, "4 seconds")
        applyEffectFromCustomEnchant(attacker, "&7&lDarkness 1", 26, victim, "2 seconds")

my initial thought was to change the numbers that determine the level of the enchant, to be a loop value and setting that to be the chances and the amount of time, but I dont know how I would be able to have different chances, and different timespans with loops, or if that's even a good way to do it.