-
Notifications
You must be signed in to change notification settings - Fork 14
3. GUI Events
APickledWalrus edited this page Aug 11, 2022
·
2 revisions
There is also a GUI event that is fired when the GUI is opened or closed. You can listen to it within the GUI creation section. Patterns:
run (when|while) (open[ing]|clos(e|ing)) [[the] gui]
run (when|while) [the] gui (opens|closes)
run on gui (open[ing]|clos(e|ing))
If you wanted to send the player a message when they opened and closed the GUI, you could do:
command /opengui:
trigger:
create a gui with virtual chest inventory with 3 rows named "My EPIC GUI!" and shape "xxxxxxxxx", "x-------x", and "xxxxxxxxx":
run on gui open:
send "Welcome to this GUI %player%!" to player
run on gui close:
send "Thanks for visiting this GUI %player%!" to player
open the last gui for the player
A GUI Close Event may also be cancelled. Pattern:
(cancel|uncancel) [the] gui clos(e|ing)
Using this in your GUIs is as simple as putting the effect within the section.
command /opengui:
trigger:
create a gui with virtual chest inventory with 3 rows named "Your New Home":
run on gui close:
cancel gui close
send "You will never escape this GUI %player%!" to player
open the last gui for the player