search
View the thread on skUnity Forums
Vanilla GUIs ~ Create your own little world in a prison called inventory
Are you looking for a good way of making GUIs in Skript? Then you're more than welcome to read this tutorial. If you have used vanilla GUIs before I recommend to read this page again since it will include some useful information and will only require vanilla Skript now since we're approaching them differently now. No need for Skript-mirror, SkQuery or Sk-Bee to get the inventory name. We don't need them. Not even on 1.8! The only thing you need on 1.8 is to see a doctor.
If Metadata comparison does not work for you and you're on 1.12, you need to use a snippet that's provided at the bottom of the tutorial!
Preperation
addSpoiler: 1.8
To get started you need following Skript versions:
Using Vanilla Skript is possible by having the Skript version 2.2dev36. They can be used earlier on but since 2.2dev36 is recommended for 1.8, use that. Since we will focus on Metadata however, dev36 is needed. If you need it to work on earlier versions, use the name of event-inventory effect. You can still use metadata though! Try metadata and just use it.
Link: https://github.com/SkriptLang/Skript/releases/download/dev36/Skript.jar
addSpoiler: 1.9+
Just use the latest version of skript and you're fine.
Link: https://github.com/SkriptLang/Skript/releases
- command /vanillaGUI:
- description: The best way of doing something.
- trigger:
- set metadata tag "vanillaGUI" of player to chest inventory with 3 rows named "&7Hello There"
- set slot 0 of metadata tag "vanillaGUI" of player to stone named "&6General Kenobi"
- open (metadata tag "vanillaGUI" of player) to player
What is metadata?
Metadata means data within data. So basically it is like using variables. The only difference is that metadata have a holder that's usually an entity or a block and it gets deleted when the server stops since it's saved in RAM. Skript's metadata implementation can only store single values per metadata key per holder. So no lists are possible. It is great for saving information shor-term based of a single entity or block.
In our case we use it to distinguish inventories.
Inventory Click Event
To perform different actions you use the Inventory click event, add some conditions and based on that build your own little actions for individual slots OR the entire inventory!
Let's say you want to cancel every click in an inventory without checking each individual slot every time. Simply use this:
- on inventory click:
- if event-inventory = (metadata tag "vanillaGUI" of player):
- #check if the clicked inventory is the one we just created
- cancel event
- #cancel the clicking. This makes the Item unstealable
Pretty self-explanatory, right? Cancel the event, cancel stealing.
The event-values for this event are:
addSpoiler: Event-Values
Event-item:
Get the TYPE of an Item. If you click on a stone named "General Kenobi" this will only return stone.
Event-slot:
Get the clicked item including name etc.
Index of event-slot:
The index effect is universal but we use it to get the clicked slot. Numbers rangin from 0-54
Event-click type:
This is by far the most interesting one. Get the way a player clicked on an Item! All of them can be found here:
https://docs.skunity.com/syntax/search/id:5297
Event-inventory action:
Basically the same as event-click type, just with more options and possibilities such as detecting if a player picked up all of the items or half of the stack etc. List can be found here:
https://docs.skunity.com/syntax/search/id:5153
Event-Inventory:
Get the type of the event-inventory. Ranging from Hoppers to Chests up to Brewing stands etc. A list of them can be found here:
https://docs.skunity.com/syntax/search/id:5321
Let's make a bit of code!
- command /vanillaGUI:
- description: The best way of doing something.
- trigger:
- set metadata tag "vanillaGUI" of player to chest inventory with 3 rows# named "&7Hello There"
- set slot 0 of metadata tag "vanillaGUI" of player to stone named "&6General Kenobi"
- set slot 1 of metadata tag "vanillaGUI" of player to player's skull named "&6%player%" with lore "&7Right click me to receive my head!"
- open (metadata tag "vanillaGUI" of player) to player
- on inventory click:
- if event-inventory = (metadata tag "vanillaGUI" of player):
- #check if the clicked inventory is the one we just created
- cancel event
- #cancel the clicking. This makes the Item unstealable
- if index of event-slot is 0:
- #check if the clicked slot is the stone, so 0
- give event-slot to player
- #give the clicked item to the player.
- else if index of event-slot is 1:
- #check if the clicked slot is the skull, so 1
- if event-click type is right mouse button:
- #check if the player right clicks the item
- set {_playerHead} to uncolored name of event-slot parsed as player
- give event-slot to player
- send "&6Player %player% has received a skull of you!" to {_playerHead}
- #since we can't use arguments, we just parse the name of the event-slot and get the skull by doing that.
- #you can use the variable as you like. I simply sent a plain text to the player.
- #ban {_playerHead} would also work
- #using NBT will work as well!
If you have any questions let me know in the comment section.
Some Snippets. Some of them require skript-reflect Since it's the most superior add-on you should have it installed anyway. The metadata fix doesn't require skript-reflect.
(Skript-reflect is a fork of skript-mirror)
addSpoiler: Get Hotkey Clicking
- import:
- org.bukkit.event.inventory.InventoryClickEvent
- expression [event( |-)]([number ]key|hot[[ ]bar][ key])[ button]:
- return type: integer
- get:
- return event.getHotbarButton() + 1 if event.getHotbarButton() != -1
- return -1
- expression [event( |-)]([number ]key|hot[[ ]bar][ key])[ button]( |-)slot:
- return type: integer
- get:
- return event.getHotbarButton() if event.getHotbarButton() != -1
- return -1
addSpoiler: 1.12 metadata fix
- function compare(1: inventory, 2: inventory) :: boolean:
- return false if (name of {_1}) != (name of {_2})
- return false if (rows of {_1}) != (rows of {_2})
- return false if type of {_1} != type of {_2}
- return true
- command /gui:
- trigger:
- set metadata tag "vanillaGUI" of player to chest inventory with 3 rows named "Best GUIs"
- set slot 1 of (metadata tag "vanillaGUI" of player) to diamond hoe named "&d:("
- open (metadata tag "vanillaGUI" of player) to player
- on inventory click:
- if compare(metadata tag "vanillaGUI" of player, event-inventory) = true:
- cancel event
- [/COLOR]

RESOURCES
skUnity ©2013-2021. Site created by Wrong and BaeFell