Enchant on chat

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

    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!

Aug 28, 2023
3
0
1
I am making a skript that is a item editor with a gui and when I was adding enchanting I came across two different problems. First is closing the gui after the player clicks on enchant with efficiency. The other thing is enchanting the tool I just can't figure out how to transfer the chat from the player to the enchantment level. Here is my code below.

on inventory click:
if event-inventory = (metadata tag "Tools" of player):
cancel event
if index of event-slot is 2:
if player is holding air:
message "&7You need to be holding the item you would like to enchant" to player
else:
message "&7Put the level in chat" to player
set {-enchantlvl::%player%} to true
close (metadata tag "Tools" of player) to player
on chat:
if {-enchantlvl::%player%} is true:
cancel event
clear {-enchantlvl::%player%}
set {_enchant::%player%} to message
enchant player's tool with "efficiency %{_enchant::%player%}%" parsed as enchantment type
 
I am making a skript that is a item editor with a gui and when I was adding enchanting I came across two different problems. First is closing the gui after the player clicks on enchant with efficiency. The other thing is enchanting the tool I just can't figure out how to transfer the chat from the player to the enchantment level. Here is my code below.

on inventory click:
if event-inventory = (metadata tag "Tools" of player):
cancel event
if index of event-slot is 2:
if player is holding air:
message "&7You need to be holding the item you would like to enchant" to player
else:
message "&7Put the level in chat" to player
set {-enchantlvl::%player%} to true
close (metadata tag "Tools" of player) to player
on chat:
if {-enchantlvl::%player%} is true:
cancel event
clear {-enchantlvl::%player%}
set {_enchant::%player%} to message
enchant player's tool with "efficiency %{_enchant::%player%}%" parsed as enchantment type
Hello there! Firstly, you'll want to format your code like I have below. Secondly, check out line 3 of the code below.
Code:
on chat:
   if {-enchantlvl::%player%} is true:
   cancel event
   clear {-enchantlvl::%player%}
   set {_enchant::%player%} to message
   enchant player's tool with "efficiency %{_enchant::%player%}%" parsed as enchantment type
I believe that your issue is the cancel event being a bit too far down in the code. I recently coded a chat cancel to var system and had the same issue, it didn't work. It took me too long to figure out that 'cancel event' is a powerful piece of code that can break/make cool scripts. To fix your issue: Simply put your 'cancel event' part of the code before your if statement (Otherwise it cancels it out which is the likely issue with your code).