Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

GUI Manager

Tuke-Nuke edited this page May 28, 2017 · 5 revisions

GUI Manager

About:

GUI Manager is a simple API that allows you to easily make guis using the best performance possible. There is two types avaliable: simple and advanced gui. If you are new or wanted a simple gui, choose the first one, and if you already know that, you can try the advanced gui.

Simple GUI - Most basic features, but enough to make yours guis easily

Syntax:

Open inventory

#Effect
open (virtual %inventory type% inventory [with size %integer%] [(named|with (name|title)) %string%]) to %players%

#Only the expression between parentheses is from TuSKe, which returns a blank inventory.
#The rest is just the effect from vanilla Skript.
Create a GUI

#Effects
(format|create|make) [a] gui slot %integers% of %players% with %item stack% [to [do] nothing]

(format|create|make) [a] gui slot %integers% of %players% with %item stack% to close [(using|with) %click action% [(button|click|action)]]

(format|create|make) [a] gui slot %integers% of %players% with %item stack% to [close then] (run|exe[cute]) %sender% command %string% [with permission %string%] [(using|with) %click action% [(button|click|action)]] [(using|with) cursor [item] %item stack%]

(format|create|make) [a] gui slot %integers% of %players% with %item stack% to [close then] (run|exe[cute]) function %function% [(using|with) %click action% [(button|click|action)]] [(using|with) cursor [item] %item stack%]

#DEPRECATED: See about it below
(format|create|make) [a] gui slot %integers% of %players% with %item stack% to (run|exe[cute]) [gui [click]] event

#New in 1.7.5: See about it below
(format|create|make) [a] gui slot %numbers% of %players% with %itemstack% to (run|exe[cute]) [(using|with) %click action% [(button|click|action)]]
Remove a GUI

#Effects
(unformat|remove) [the] gui slot %integers% of %players%

(unformat|remove) [all] [the] gui slots of %players%
Conditions

%player% has [a] gui
%player% does(n't| not) have [a] gui

slot %number% of %player% is [a] gui
slot %number% of %player% is(n't| not) [a] gui

What the effects do:

There is 4 types of actions: do nothing (aka as unstealable from SkQuery), run command, run function and run code.

The first 3 types have an option to close the GUI when you click on it, just include the to close. And it also has an option to only do the action with certain click type, just include the using %clicktype%. Possible click types:

Click Types

left [mouse button]
right [mouse button]
(shift left|left mouse button with shift)
(shift right|right mouse button with shift)
double click [using mouse]
middle [mouse button]
number key
drop [key]
(control drop|drop key with control)

The run command and run function have a possibility to only do the action if the the player clicks on it using a specific item in his cursor. Just include the (using|with) cursor [item] %itemstack%.

Run command allows you to run a command when a player clicks on it, you can choose between console and player for the sender, you also have with permission %string% and it will make the player execute the command with given permission (the permission is gone after the command).

Run function allows you to run a function when a player clicks on it, the format is just the same as calling a simple function in Skript <function's name>(<given paremeter's if any>).

The Run code is more simpler: It executes a code that is inside a format gui slot effect, which means that it's not necessary to create a function/command to make some action. But for that, the to run gui click event should be avoided since it is a better option now. You can use event-values from event on inventory click or use TuSKe own expressions for it (see GUI Expressions in Advanced GUI). It requires TuSKe 1.7.5+.

Example
open virtual chest to player
format gui slot 0 of player with stone to run:
    send "This message will be sent when player clicks on gui"
format gui slot 1 of player with arrow to close with middle click:
    send "This will be sent after closing a gui"
format gui slot 2 of player with diamond to run using left click:
    if gui-cursor-item is a stone:
        set gui-clicked-item to gui-cursor-item
        set gui-cursor-item to air

Basic structure:

To make a gui, you just need two simple steps:

  • Use any effect that opens an inventory.
  • Use any of effects above to format a gui.

That's a basic example of what your code will need to be.

Examples:

Testing all effects

command /gui:
    trigger:
        if sender is console:
            broadcast "This was executed by console!"
            stop
        if player has permission "*":
            send "Player executed this command with permission ""*"""
            wait a tick
            if player doesn't have permission "*":
                send "Player doesn't have that permission anymore."
            else:
                send "Well, player still has this permission, but maybe is he an op?"
        else:
            send "Player execute this command without permission"
                        
command /guiExample:
    trigger:
        open virtual chest inventory to player
        format gui slot 0 of player with stone named "It won't do anything"
        format gui slot 1 of player with stone named "It will just close" to close
        format gui slot 2 of player with stone named "It will just close but only with pressing a number key" to close using number key
        format gui slot 3 of player with stone named "It will make the player execute a command, but he might not have permission" to run player command "/gui"
        format gui slot 4 of player with stone named "It will make the player execute a command with ""*"" permission" to run player command "/gui" with permission "*"
        format gui slot 5 of player with stone named "It will make the console execute a command" to run console command "/gui"
        format gui slot 6 of player with stone named "It will run the function doSomething()" to run function doSomething()
        format gui slot 7 of player with stone named "It will close and then run the function doSomething()" to close then run function doSomething()
        format gui slot 8 of player with stone named "It will run doSomething() if you click on it with a stone" to run function doSomething() with cursor stone
        format gui slot 9 of player with stone named "It will run the gui event" to run gui event
        format gui slot 10 of player with stone named "It will execute the code below":
            send "Hi" to player
            give a stone to player
            heal player
        
function doSomething(i: int = 0): #TuSKe will run this function even if it was loaded after the command above. Need 1.7.2+ for it.
    broadcast "And it did"
                
on gui click:
    send "It was executed in a separated event"
Multi-action example

function changeName(p: Player, clicktype: String):
    set {_number} to name of slot 4 of {_p}'s current inventory parsed as number #Requires SkQuery or Bensku's fork
    if {_clicktype} is "left":
        remove 1 from {_number}
    else if {_clicktype} is "shift left":
        remove 100 from {_number}
    else if {_clicktype} is "right":
        add 1 to {_number}
    else if {_clicktype} is "shift right":
        add 100 to {_number}
    set name of slot 4 of {_p}'s current inventory to "%{_number}%"

command /multiactionExample:
    trigger:
        open virtual dispenser inventory named "Multi-action example" to player
        set {_item} to diamond named "1"
        set line 1 of lore of {_item} to "&7Left click: remove 1"
        set line 2 of lore of {_item} to "&7Shift left click: remove 100"
        set line 3 of lore of {_item} to "&7Right click: add 1"
        set line 4 of lore of {_item} to "&7Shift right click: add 100"
        format gui slot 4 of player with {_item} to run function changeName(player, "left") with "left" click
        format gui slot 4 of player with {_item} to run function changeName(player, "shift left") with "shift left" click
        format gui slot 4 of player with {_item} to run function changeName(player, "right") with "right" click
        format gui slot 4 of player with {_item} to run function changeName(player, "shift right") with "shift right" click
Multi-pages gui

function openMenu(p: Player, type: String):
    if {_type} is "page 1":
        open virtual chest inventory with size 1 named "Page 1" to {_p}
        make a gui slot 0 of {_p} with stone named "Go to page 2" to run function openMeny({_p}, "page 2")
    else if {_type} is "page 2":
        open virtual chest inventory with size 1 named "Page 2" to {_p}
        make a gui slot 0 of {_p} with stone named "Go to page 3" to run function openMeny({_p}, "page 3")
   #And so on until ends of page...
    else if {_type} is "page 3":
        open virtual chest inventory with size 1 named "Page 3" to {_p}
        make a gui slot 0 of {_p} with stone named "Go back to page 1" to run function openMeny({_p}, "page 1")

Things you should know:

  • If you want to only change the item after already formatted a slot, you don't need to format it again, just use any expression to change the slot of a inventory, like set slot 0 of player's current inventory to {_newItem}.
  • If you format the inventory with an air item, it will make a locked slot. The player can't place any items in that slot.
  • You can format the same slot with more than one action, like to run a command when using the left click and a function when using the right click.
  • In gui click event, you will need to check the name of event-inventory is the gui name that you want, since more scripts can have this event.
  • If you use uncancel event in gui click event, it will allow the player to remove the item and it will lock the slot after that (because of reason above), so you can just use unformat the gui event-number of player if you don't want it to be locked.
  • Starting from 1.7.2, you can use functions that isn't loaded yet or is below the code, TuSKe will get that function when the gui is opened, but if it couldn't find any function, it won't do anything obviously.
  • Starting from 1.7.5, you can execute codes belows a format gui slot effect. See more about it above. The click-type shares same values between bensku's fork and TuSKe now, which means it accepts left or left mouse button.

Advanced GUI - With more resources, which allows you to make your guis faster and smoother.

Syntaxes:

Meeting the syntaxes.

Create/Edit a gui

#Expression to create a virtual inventory
#They all do the same thing, the many syntaxes is just to fit all usages of syntax.
virtual %inventorytype% [inventory] [with size %-number%] [(named|with (name|title)) %-string%]
virtual %inventorytype% [inventory] [with %-number% row[s]] [(named|with (name|title)) %-string%]
virtual %inventorytype% [inventory] [(named|with (name|title)) %-string%] with size %-number%
virtual %inventorytype% [inventory] [(named|with (name|title)) %-string%] with %-number% row[s]

#Effects
create [a] [new] gui [[with id] %-string%] with %inventory% [and shape %-strings%]
(change|edit) %guiinventory%
Make GUI

(make|format) next gui [slot] (with|to) %itemstack%
(make|format) gui [slot] %strings/numbers% (with|to) %itemstack%
Close GUI

#This is an effect that will execute some code when a gui is closed.
run (when|while) clos(e|ing) [gui]
Change GUI Properties

#Change properties of a gui, like name and size of a inventory or reorder the items in a gui.
change gui inventory to name %string% and size %number%
change gui shape [of (items|actions)] to %strings%
change gui properties of inventory to name %string% [with %-number% row[s]] and shape [of (items|actions)] to %strings%
GUI Expressions

#General expressions
last[ly] [created] gui #Returns the last created GUI, only works per event (like a local variable)
gui [with id] %string% #Returns a gui from a given string id.

#GUI expressions (see about them later)
# Returns the clicked slot number
gui-slot 

# Returns the raw clicked slot number in both inventories.
# Numbers from 0 to <size of top inventory> means it is from the top inventory
# Numbers from <size of top inventory + 1> to higher means the slot from player's inventory.
# Not used in any expressions so far, but just an option.
gui-raw-slot 

# The hotbar slot number if the click type is 'number key'
gui-hotbar-slot

# The gui inventory involved in that action
gui-inventory

# The inventory actions, see values below.
gui-inventory-action

# The click type, see values below.
gui-click-(type|action)

# The item in cursor and the item in clicked slot, these expressions can be added/removed/setted/cleared.
gui-cursor
gui-[(clicked|current)-]item

# The slot type of slot. Not useful, just an extra value.
gui-slot-type

# The player that clicked in slot
gui-player

# A list of all players that have this gui currently open.
gui-players

# The name of inventory, basically is 'name of event-inventory'
gui-inventory-name

# The slot string ID, see more about it below
gui-slot-id

# The gui object itself, where you can change options about it.
gui
Types

gui inventory: Represents a gui inventory, this type is only used to edit an alreaddy created gui.

click (type|action): It represents a click type in a inventory click event. Starting from 1.7.4-beta/1.7.5, it uses Bensku's values too for compatibility.
Values: left [mouse button], (shift left|left mouse button with shift), right [mouse button], (shift right|right mouse button with shift), middle [mouse button], number key, double click [using mouse], drop [key], (control drop|drop key with control)

inventory action: It represents a action in a inventory click event. Starting from 1.7.4-beta/1.7.5, it uses Bensku's values too for compatibility.
Values: nothing, pickup all, pickup some, pickup half, pickup one [item], place all, place some, place one, swap with cursor, drop all [from] cursor, drop one [from] cursor, drop all [from] slot, drop one [from] slot, (move to other inventory|instant move), hotbar move and readd, (hotbar swap|swap with hotbar), clone stack, collect to cursor, unknown

slot type: It represents a type of clicked slot in a inventory click event.
Values: armor, container, crafting, fuel, outside, quickbar, result

In case you have Bensku, you need to check the values for click action and inventory action in his documentation. TuSKe only uses the same values in case you are running an old fork version.

How to make a gui

First off, this new gui system use a different format to make guis (instead of openning the inventory + formatting the slot), now you need to create a gui:

#syntax: create [a] [new] gui [[with id] %-string%] with %inventory% [and shape %-strings%]
create a gui with virtual chest with 6 rows named "&4Select the server"

Then, now comes one of new things: effects inside effects. Basically it is effects that can run codes in it, (MundoSk has some effects that uses that and they are called Scopes, for example). Using this idea, you need to use the Make GUI effect inside of it:

create a gui with virtual chest with 6 rows named "&4Select the server":
    #Syntaxes:
    # (make|format) next gui [slot] (with|to) %itemstack%
    # (make|format) gui [slot] %strings/numbers% (with|to) %itemstack%
    make next gui with diamond sword named "&4PvP server" # It will format the next free slot that is not formatted yet.
    make next gui with grass named "&aSkyBlock"

So far, it will do nothing more than just set a unstealable item (like the to do nothing from previous version). Now, instead of executing functions/commands, you can use skript code directly in it (effects inside effects inside effects? What effectception is this?). To do it, just indent the code below the effect make gui, and then it will run when the player clicks on it.

create a gui with virtual chest with 6 rows named "&4Select the server":
    make next gui with diamond sword named "&4PvP server":
        send "You will be teleported to the Pvp server"
        execute player command "/server pvp"
    make next gui with grass named "&aSkyBlock":
        send "You will be teleported to the Skyblock server"
        execute player command "/server skyblock"

Now, you only need to open a gui to player, you can use last[ly] [created] gui expression + Skript effect open inventory:

open last gui to player

And that's done, the most basic gui is that. Your code should be like:

command /servers:
    trigger:
        create a gui with virtual chest with 6 rows named "&4Select the server":
            make next gui with diamond sword named "&4PvP server":
                send "You will be teleported to the Pvp server"
                execute player command "/server pvp"
            make next gui with grass named "&aSkyBlock":
                send "You will be teleported to the Skyblock server"
                execute player command "/server skyblock"
        open last gui to player

You also have an effect to run a code when a gui closes.

create new gui with virtual chest named "Backpack":
    run when close the gui: #This code below will be executed before cleaning a gui
        set {Variable::%gui-player%::*} to all items of gui-inventory

Inventory click's event values

Now, you can use any event values even if it is not the proper event, in case you do have an addon that supports it.

create a gui with virtual chest with 6 rows named "&4Select the server":
    make next gui with diamond sword named "&4PvP server":
        send "%clicked item%" #Umbaska

But, to not let you depend them, TuSKe has it owns expressions that covers it (see the GUI Expressions above). So:

create a gui with virtual chest with 6 rows:
    make next gui with glass:
        if gui-click-action is left mouse buttom or right mouse buttom:
            set gui-clicked-item to gui-cursor-item
            set gui-cursor-item to air
            #Only these two expressions can be changed.

Global GUIs.

Now you can create global GUIs with given string ID.

on skript load:
    create a gui with id "HUB" with virtual chest with 6 rows named "&4Select the server":
        make next gui with diamond sword named "&4PvP server":
            send "You will be teleported to the Pvp server"
            execute player command "/server pvp"
        make next gui with grass named "&aSkyBlock":
            send "You will be teleported to the Skyblock server"
            execute player command "/server skyblock"

command /servers:
    trigger:
        open gui "HUB" to player

Note: All GUIs (global GUIs or local GUIs) shares the same inventory. Which means that if you change a item for one player, it will change for the others players too.

The best usage of Global GUIs are for static guis (like a server selector or gui to show values from a faction), where it doesn't have values that changes per player. But you also can create global GUIs for players, so you don't need to create them everytime, but **don't forget to remove unused guis, like when a player quits or when it is not used anymore:

on quit:
    delete gui "PlayerStats.%player%"
    #It will close the GUI if open for some player and removes it in case it is a global GUI.

Editing a GUI

In case you want to edit a gui, like reformat a slot or change a gui properties (see about it below). You can just use the effect to edit instead of create.

command /edit:
    trigger:
        edit gui "HUB":
            #It will automatically change in case it is open for some player
            make gui 0 with diamond sword named "The PvP server is down for maintence." 

String based slot

To make your guis looks simple and easy to change, now you can create GUIs using shapes. Shapes are the same concept from shaped recipes: A single char to represent a slot in a inventory. With this, is more helpfull to make custom dinamic guis

#syntax: create [a] [new] gui [[with id] %string%] with %inventory% [and shape %strings%]
add "xxxxxxxxx" to {_shape::*}
add "x--------x" to {_shape::*}
add "xxxxxxxxx" to {_shape::*}
create a gui with virtual chest and shape {_shape::*}

Imagine that the strings above are a representation of a inventory. Each slots that has char in common will be the same, so when they will be formated or a player clicks on it, it will have same item and do same action.

add "xxxxxxxxx" to {_shape::*}
add "x--------x" to {_shape::*}
add "xxxxxxxxx" to {_shape::*}
create a gui with virtual chest and shape {_shape::*}:
    make gui slot "x" with iron ingot
    make gui slot "-" with diamond

See some examples below of how it is useful.

Change GUI properties.

This effects will help you how to change the gui inventory smoothly. You need to use them in (edit|change) %gui inventory% (It doesn't has necessity to change when creating).

#Syntaxes:
change gui inventory to name %string% and size %number%
change gui shape [of (items|actions)] to %strings%
change gui properties of inventory to name %string% [with %-number% row[s]] and shape [of (items|actions)] to %strings%

The first one is to only edit the name and size (in case it is a chest type) of a gui. Nothing much to say. The second is more complex: It is used to change the positions of items, actions or both in a gui. For example, let's use this gui:

create new gui with id "Example" with virtual hopper and shape "ABCDE": #You can set the shape in a single line
    loop 9 times:
        make next gui with a random item of all items
open last gui to player

When using change gui shape of items <...>, you need tu use a shape where it will get a item from slot X and put at slot Y. So using the shape EABCD, you will note that the E was changed to the first slot and the other one were moved on slot to the right. So:

edit last gui:
    loop 10 times:
        wait 1 second
        change gui shape of items to "EABCD"

And it will make a effect as the items is moved to the right slot.

When using change gui shape of actions <...> it will only change the actions of it, so:

  • If we have a gui with two slots using shape AB and we change the shape of actions to BA, it will execute in slot 0 where it was executing in slot 1 previously.

When using change gui shape to <...> it will change both together: items and actions

For the last syntax, it basically will change both syntaxes above together.

Things you need to know:

  • You can't use event values inside the code to run when the player clicks on it.
    • To avoid that, you need to set a variable them use the variable:
      command /example <text>:
          trigger:
              set {_arg} to arg
              create new gui with virtual chest:
                  make gui slot 0 with diamond:
                      send "%{_arg}%"
    • Variables inside the code will work as "local slot variable". What does it mean? It will keep the same variable everytime the player clicks on it:
      create gui with virtual chest:
          make gui slot 0 with diamond:
              add 1 to {_count}
              send "%{_count}%"
              #It will increase everytime a player clicks on it
    • The variables is not shared between slots, unless it was formatted with same String id.
      command /example2:
          trigger:
              set {_var} to 1
              create new gui with virtual chest:
                  loop integers from 0 to 35:
                      make gui slot loop-integer with diamond:
                          add 1 to {_var}
                          send "%{_var}%"
                          #All slots will start with '1', but they will be increased individually per slot.

Code examples:

TODO
Not done yet. If you have a good example, you can PM me with it.

If you found any issue, with this tutorial or with guis, you can contact me in avaliable links here. You can send me your suggestions and example codes to add to the tutorial too.