-
Notifications
You must be signed in to change notification settings - Fork 17
Creating a GUI
The easiest way to create a GUI is using the virtual inventory expression, which allows creating an inventory of any type with any name.
skript-gui provides a simple expression for creating inventories of any type:
virtual %inventorytype% [with size %-number%] [(named|with (name|title)) %-textcomponent%]
virtual %inventorytype% [with %-number% row[s]] [(named|with (name|title)) %-textcomponent%]
virtual %inventorytype% [(named|with (name|title)) %-textcomponent%] with size %-number%
virtual %inventorytype% [(named|with (name|title)) %-textcomponent%] with %-number% row[s]Simply, you create a GUI using an inventory type, and optionally a name and size. Note that size is only applicable for chest inventories, and it represents the number of rows the chest has (between 1 and 6). A text component is a string with formatting, such as colors and decorations. You can read more about text formatting on Skript's documentation site by clicking here.
In this example, we create a simple chest inventory that we can later use for a GUI:
a virtual chest inventory named "<rainbow>My Awesome GUI" with 3 rowsImportant
A virtual inventory, as you may be able to tell from the name, is not a real inventory.
For example, a virtual furnace inventory cannot actually be used to smelt items.
If you need to create a GUI using a real, working inventory, see the experimental menu type GUI.
You can create a GUI using any kind of inventory, which is why the virtual inventory expression explained above is provided. The syntax for creating a GUI is:
create [a] [new] gui [[with id[entifier]] %-string%] with [a] %inventory% [(and|with) ([re]mov[e]able|stealable) items] [(and|with) (layout|shape) %-strings%]While there are a few different GUI properties available to specify in this syntax, we are only focusing on one for now: the inventory the GUI will use.
Tip
Curious about the other GUI properties? Click here to read more about them!
Now, we can combine this syntax with the virtual inventory expression from above to create a GUI:
create a gui with a virtual chest inventory named "<rainbow>My Awesome GUI" with 3 rowsWhen that statement runs, the GUI will be created and ready to use. It can be accessed using the last created gui expression:
[the] (last[ly] [created|edited]|created|edited) guiAs the name implies, it returns the last gui created (in that trigger) using a create a gui statement.
Opening a GUI is simple: there's no special syntax. You can open a GUI using Skript's regular 'open inventory' effect. Again, we can access the created gui using the last created gui expression. So, our full trigger looks like this:
create a gui with a virtual chest inventory named "<rainbow>My Awesome GUI" with 3 rows
open the last created gui for the playerRunning it in-game, we can see the full results: