search
View the thread on skUnity Forums
You are looking for a good way of making GUIs in Skript? Without having to update an Addon or possibly risk that it's going to get unmaintained? Well, you cant stop searching now!
Because vanilla GUIs are integrated into Skript. That's how the name origins from. It's a vanilla feature from Skript. I will introduce you to the basic mechanichs of vanilla GUIs and show you multiple ways on how to set them up.
(PS: Best practice would be to go with metadata-values. You'll get what that is in a few minutes.)
In order to use vanilla GUIs it's always good to use the latest Skript version for your respective Minecraft version.
add
addSpoiler: Versions
If you're still using 1.8.8 (Why? Update. Seriously. Gross.) you should be using dev36.
Link: https://github.com/SkriptLang/Skript/releases/download/dev36/Skript.jar
Link: https://github.com/Matocolotoe/Skript-1.8/releases/tag/2.5.3
(You may be wondering why there are 2 link! Gios fork (the bottom one) is recommended since it provides more features. Both work though.)
If you're using anything above 1.8.8 but below 1.13, so up to 1.12 you should be using Skript 2.6:
Link: https://github.com/SkriptLang/Skript/releases/tag/2.6
(this may be changed as of now this is the latest working version. It's going to be discontinued working for 1.12 on the next update.)
For anything above 1.12 the latest Skript version is recommended.
Link: https://github.com/SkriptLang/Skript/releases
Let me first describe to you in words how vanilla guis work.
Open an inventory
Set the slots however you like
Check every time a user clicks within the inventory, and do something based on that.
Open an inventory
Set the slots however you like
Check every time a user clicks within the inventory, and do something based on that.
There are 3 ways to set up vanilla GUIs that basically work the same.
addSpoiler: First way: Metadata
The first method that should be prioritized is using metadata.
Spoiler: What is Metadata?
You can learn a bit more about the inventory click event,
addSpoiler: 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
The event-values for this event are:
Spoiler: Event-Values
Remember how I said there are 3 different ways to make vanilla GUIs? I will not describe them much since as I said, they are very similar.
You still open an inventory and see within the inventory click event if it's the desired one.
addSpoiler: Second way: Using variables
Instead of using metadata we're using variables. Same thing basically.
- command /vanillaGUI:
- description: The second best way of doing something.
- trigger:
- set {Inventory::%player%} to chest inventory with 1 row named "Vanilla!"
- set slot 0 of {Inventory::%player%} to stone named "&6General Kenobi"
- open {Inventory::%player%} to player
- on inventory click:
- #check if the clicked inventory is the one we just created
- if event-inventory is {Inventory::%player%}:
- #cancel the clicking. This makes the Item unstealable
- cancel event
addSpoiler: Third way: Just using inventory names
You know if you're lasy, this is perfectly fine to use. Instead of setting a holder (variable or metadata) to an inventory, you just open it.
- command /vanillaGUI:
- description: The laziest best way of doing something.
- trigger:
- open chest inventory with 4 rows named "&cLazy gurl." to player
- set slot 0 of player's current inventory to stone named "&6General Kenobi"
- on inventory click:
- #check if the clicked inventory is the one we just created
- if name of event-inventory is "&cLazy gurl.":
- #cancel the clicking. This makes the Item unstealable
- cancel event
The following code is just an example on how to use this system.
- 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

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