-
Notifications
You must be signed in to change notification settings - Fork 17
Adding GUI Functionality
Now that we have created a GUI, the next step is to give it some functionality.
The make gui slot effect/section can be used to accomplish that:
(make|format) [the] next gui [slot] (with|to) [[re]mov[e]able|stealable] %itemtype%
(make|format) gui [slot[s]] %integers/texts% (with|to) [[re]mov[e]able|stealable] %itemtype%Tip
Curious about why GUI slots can be text?
Click here to read about custom layouts!
Tip
What does it mean for an item to be removable?
Click here to read about a GUI's lock status!
When used as an effect, make gui slot can be used to add items to the GUI.
By default, items cannot be removed from a GUI.
For example, we can taunt the player with a diamond:
make the next gui slot with a diamond named "<blue>Try and steal me!"
When used as a section, make gui slot can be used to add items to the GUI that run code when clicked.
By adding a colon to turn the line into a section, any code within that section will be run when the item is clicked:
format the next gui slot with a cherry button named "<pink>Press me!":
give the player a diamondskript-gui-make-slot.mov
It's also possible to remove items (and their associated actions) by unformatting a slot.
This is done using the unmake gui slot effect:
(un(make|format)|remove) [the] (next|last) gui slot
(un(make|format)|remove) gui [slot[s]] %integers/texts%
(un(make|format)|remove) [all [[of] the]|the] gui [slots]For example, by nesting this within a make gui slot section, we can add an item that removes all items in the GUI when clicked:
format the next gui slot with a potion of invisibility named "<purple>Magician's Potion":
unformat all of the gui slotsskript-gui-unmake-slot.mov
Tip
Wondering what else you can listen for in a GUI?
Click here to view the other GUI events that can be used!
Now, our full code looks something like this:
create a gui with a virtual chest inventory named "<rainbow>My Awesome GUI" with 3 rows:
make the next gui slot with a diamond named "<blue>Try and steal me!"
format the next gui slot with a cherry button named "<pink>Press me!":
give the player a diamond
format the next gui slot with a potion of invisibility named "<purple>Magician's Potion":
unformat all gui slots
open the last created gui for the player