Skip to content

2. Modifying the contents of a GUI

APickledWalrus edited this page Aug 11, 2022 · 10 revisions

Adding Items

There are two ways you can add items to a GUI. They are commonly referred to as "GUI Make Sections".

(make|format) [the] next gui [slot] (with|to) [[re]mov[e]able|stealable] %itemtype%
(make|format) gui [slot[s]] %strings/numbers% (with|to) [[re]mov[e]able|stealable] %itemtype%

Just as you can make all of the items in a GUI stealable by the player, you can make specific slots stealable too. Include the removable or stealable word from the pattern above and the player will be able to take it.

TIP! Not sure what an ItemType looks like? Find out here: https://docs.skriptlang.org/classes.html#itemtype

All code modifying a GUI has to go within the GUI creation section or a GUI editing section. You can learn about how to edit a GUI that has been already created here: https://github.com/APickledWalrus/skript-gui/wiki/5.-Using-Global-GUIs

We'll continue from our GUI shown in the last page:

command /opengui:
  trigger:
    create a gui with virtual chest inventory with 3 rows named "My EPIC GUI!" and shape "xxxxxxxxx", "x-------x", and "xxxxxxxxx"
    open the last gui for the player

Now, to add items, all you have to do is put one of the patterns from above within the GUI creation section.

command /opengui:
  trigger:
    create a gui with virtual chest inventory with 3 rows named "My EPIC GUI!" and shape "xxxxxxxxx", "x-------x", and "xxxxxxxxx":
      make gui slot "x" with dirt named "! BORDER !"
    open the last gui for the player

The above code would fill the "x" slot (from the GUI's shape) in the GUI with dirt that's named named "! BORDER !"

Making Items Run Code

The GUI's contents can also be buttons so that code will run when you click on the item. Turning slots into buttons is easy. All you have to do is put the code that you want to run within the slot creation section. Here's an example:

command /opengui:
  trigger:
    create a gui with virtual chest inventory with 3 rows named "My EPIC GUI!" and shape "xxxxxxxxx", "x-------x", and "xxxxxxxxx":
      make gui slot "x" with dirt named "! BORDER !":
        send "Hey %player%! You just clicked a border slot!" to player
    open the last gui for the player

Here's what the GUI looks like now and what happens when you click on one of the dirt border blocks:

image

TIP! GUIs have a bunch of values that you can use when a slot is clicked! Check out https://github.com/APickledWalrus/skript-gui/wiki/4.-GUI-Values for more information.

Removing Items

You can also unformat/remove a GUI slot. The patterns to do that are:

(un(make|format)|remove) [the] next gui [slot]
(un(make|format)|remove) gui [slot[s]] %strings/numbers%
(un(make|format)|remove) all [[of] the] gui [slots]

NOTE: If you ever want to change a GUI slot, you don't have to remove it first! The previous slot will be automatically removed.

Let's say we wanted to remove the border if it was clicked on. This is where we could use the unformat effect.

command /opengui:
  trigger:
    create a gui with virtual chest inventory with 3 rows named "My EPIC GUI!" and shape "xxxxxxxxx", "x-------x", and "xxxxxxxxx":
      make gui slot "x" with dirt named "! BORDER !":
        send "Say goodbye to your GUI border %player%!" to player
        remove gui slot "x"
    open the last gui for the player

Now, if you click the one of the border dirt blocks, it will remove all of them and send a message. Here's what it looks: image

Other Removal Options

There are two other options to remove a GUI slot too.

(un(make|format)|remove) [the] next gui [slot]
  This effect removes the slot before the next available slot.
  For example, if you had a GUI with 27 slots total and 26 of them were set,
  this effect would remove the 26th slot, and the last two slots would now be empty.

(un(make|format)|remove) all [[of] the] gui [slots]
  This effect removes every slot that is set.

TIP! Did you know you can check if a player has a GUI open? See https://github.com/APickledWalrus/skript-gui/wiki/6.-Other-Syntax-and-Information#gui-condition for more information.

That is all there currently is to modifying the contents of a GUI. Check out the other pages to learn about using Global GUIs, GUI Values, and a tutorial on how to edit a GUI that has already been created.