How to get the enchantments of a tool?

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

Status
Not open for further replies.

pepper82

Member
Jan 26, 2017
272
1
18
41
Hi there,
how would I get all enchantments and their levels on a player's tool?
 
Hi there,
how would I get all enchantments and their levels on a player's tool?
You can use the enchantment type and enchantment level syntaxes from searching “enchant” on the sk docs to complete this task, maybe add all enchantments to a list, and loop a function to check the players tool for all of the enchantments you include in the list, then set the enchantments the item has to another variable and then message that variable to you, which dhows each enchantment?
 
code_language.skript:
on script load:
  import "ch.njol.skript.util.EnchantmentType"

function enchantments(item: item) :: enchantment types:
  set {_map} to (try {_item}.getRandom() ? {_item}).getEnchantments()
  loop ...{_map}.keySet():
    add new {EnchantmentType}(loop-value and {_map}.get(loop-value)) to {_enchantments::*}
  return {_enchantments::*}
skript-mirror
 
Status
Not open for further replies.