Custom Enchantments Tutorial (weapons)

To make CEs (Custom Enchantments), you have to use the itemtags if you want them to be stackable. You can view the tags on the item you're currently holding with this code:
cmd create gettags
cmd add gettags %hand% = playerhand(%p%)
cmd add gettags %tags% = %hand%[\"tags\"]
cmd add gettags message %p% %tags%
Those tags are actually NBT tags in hexadecimals. If you want to know more about it, you can DM me on discord (ChinaGirlNL#5723) or google it yourself.

The code for your CE has to check if the damage was caused by another player, so start like this:
cmd create damage
cmd add damage %d% = %args%[3]
cmd add damage if %d% = %p% then exit
cmd add damage %on% = onlineplayers()
cmd add damage if %d% notin %on% then exit
Then you need the tags of the weapon:
cmd add damage %h% = playerhand(%d%)
cmd add damage %t% = %h%[\"tags\"]
Then you check if the name of your enchantment is in your item's tags (usually in the item lore). As I mentioned earlier, it's written in hexadecimals. You can just search a hexadecimal translator to translate your CE's name into tags. Because you only want to know if parts of the tags contain your CE's name, you use in instead of =. If the item has the right tags, your code will execute the enchantment part.
cmd add damage if \"466c79\" in %t% then goto 100
cmd add damage if \"46616c6c\" in %t% then goto 200
cmd add damage exit
I made for example the CEs Fly and Fall, but you can do whatever you want. I would recommend not to use sleep, because the enchantments aren't executed all at once. Make sure your enchantment's code doesn't end with exit, but with a goto to the next check for a CE:
cmd edit damage 99 #Fly
cmd add damage %c% = random(1, 2)
cmd add damage if %c% = 1 then goto 8
cmd add damage ascon /effect %p% levitation 2 1 true
cmd add damage goto 8

cmd edit damage 199 #Fall
cmd add damage %c% = random(1, 2)
cmd add damage if %c% = 1 then goto 9
cmd add damage %yy% = %y% + 10
cmd add damage move %p% %level% %x% %yy% %z%
cmd add damage goto 9