-
Notifications
You must be signed in to change notification settings - Fork 17
GUI Events
There are two sections available that allow you to run code whenever the GUI is opened and whenever it is closed:
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))For example, we could prevent the player from being damaged while they have the GUI open:
command /protectedgui:
trigger:
create a gui with a virtual chest inventory named "Protected GUI":
run on open:
make the player invulnerable
run on close:
make the player vulnerable
open the last created gui for the playerIt is also possible to prevent the user from closing the GUI by using the cancel gui close effect:
(cancel|uncancel) [the] gui clos(e|ing)For example, we could make a game that requires the user to click five times before they can close the GUI:
command /cookieclicker:
trigger:
set {-clicks::%player%} to 0
create a gui with a virtual dispenser inventory named "<brown><bold>Cookie Clicker":
make gui slot 4 with a cookie named "<brown>Clicks: %{-clicks::%player%}%":
add 1 to {-clicks::%player%}
set the name of the gui clicked item to "<brown>Clicks: %{-clicks::%player%}%"
run on close:
if {-clicks::%player%} is less than 5:
cancel the gui closing
open the last created gui for the playerskript-gui-cookie-clicker.mov
The slot change section can be used for listening to any kind of change in a slot, not just a click.
For example, when a player drags items (to spread them across multiple slots), an inventory click is normally only triggered for the slot where the drag started.
However, the slot change section will be triggered once for every changed slot.
We could use this to create a command that detects when certain shapes are made in a GUI by the player dragging an item out. The example below replaces the dragged items with diamonds if the player makes a specific smile-like shape:
command /transmutationgui:
trigger:
clear {-%player%::changing::*}
create a gui with a virtual dispenser inventory named "Transmutation Table" with stealable items:
run when slots (integers from 0 to 8) changes:
add gui slot to {-%player%::changing::*}
if {-%player%::changing::*} is 3, 5, 6, 7, and 8:
wait 1 tick
set slots 3, 5, 6, 7, and 8 of the gui to a diamond
wait 1 tick
remove gui slot from {-%player%::changing::*}
show the last gui to the player