TuSKe GUI Manager Tutorial

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

Tuke_Nuke

Retired Staff
Addon Developer
Dec 9, 2016
150
87
3
About:

GUI Manager is a feature of TuSKe to help you to make your GUIs easily, making automatically to handle any possible way the player has to get the item out.

Syntax:

code_language.skript:
#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.
code_language.skript:
#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%]

(format|create|make) [a] gui slot %integers% of %players% with %item stack% to (run|exe[cute]) [gui [click]] event
code_language.skript:
#Effects
(unformat|remove) [the] gui slot %integers% of %players%

(unformat|remove) [all] [the] gui slots of %players%
code_language.skript:
%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 event.

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:

code_language.skript:
left
right
shift left
shift right
double click
middle
number key
drop
control drop
code_language.skript:
left mouse button
right mouse button
left mouse button with shift
right mouse button with shift
double click using mouse
middle mouse button
number key
drop key
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 paremeters if any>).

The last one, Run event, is just in case you want to execute more codes and still want your gui be safe against stole items. This one doesn't have any detaills and it will run an event only when click on gui slots that uses this effect:

code_language.skript:
[on] gui (action|click)

#Values:
player : the player who clicked on item.

event-inventory : The inventory (can only be the top inventory until this moment)

event-number : The slot number

event-item : the item in cursor of the player
#Note: it isn't the item in the slot, is the cursor. If you want the item in slot, use the two values above: 'slot event-number of event-inventory'

event-type : the click type (left, right ...)
#In case you have Bensku's fork, is prefered that you use 'event-string', which returns the same thing but in string form.

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 create a gui.

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

Examples:

code_language.skript:
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
  
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"
code_language.skript:
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
code_language.skript:
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.
Thank's for all, if you found something wrong or have a suggestion/example to give, just contact me somewhere else and I will be glad.
 
  • Like
Reactions: sklake and SwiKZiiK
Why, when i use this GUI manager my scripts are loaded 5x times longer?
Because Skript reloads a bit longer when parsing long syntaxes. The only way to fix it is switching to Advanced GUI from 1.7.5+. Currently this tutorial wasn't updated with new gui, so you can check in my github. The advanced gui has smaller syntaxes so it loads a lot faster.
 
  • Like
Reactions: GlobooX
Is it possible to not show the hover over a glass pane?

something like "glass pane without name"? I don't want to show the hover over the guy when it's a glass pane.
 
  • Like
Reactions: Chief_Cman
I still have no idea how to use the multi page GUI please explain or someone make a vid we arn't all smart ass's here
It doesn't need to be "smart ass". In the example was a simple thing: open another gui when clicking in one item to the next page.
Of course that example was manually, but depending of your needs, you can make it automatically.
For example, make a list of online players:
code_language.skript:
command /players [<number=1>]:
    trigger:
        #Open a inventory to a player, that's basic
        open virtual chest with 6 rows named "Online players - Page %arg%" to player

        # The '7 times' is a Skript expression to return a list of number (yes, it is the same one used for loops in 'loop x times')
        #It basically returns a list of integers from 1 to 7
        #So, it will format the top line slots, because the effect accepts a list of slots
        format gui slot 7 times of player with cyan glass pane named " "

        #This will be the first slot of player, where the player's skull will be placed
        set {_slot} to 9

        #That's a simple tuske expression which splits a list into pages
        # with x lines (in this case, x players each page) and to get a number page
        loop page arg of all players with 45 lines:
            format gui slot {_slot} of player with loop-value's skull named "%loop-value%"
            add 1 to {_slot} #Then we increase the slot

        #Now we need to set up the next/previous page button

        #The previous button is simple, if the page is more than 1, then it has a previous page
        if arg is more than 1:
            format gui slot 0 of player with arrow named "Previous page" to run player command "/players %arg - 1%"
        #If it's not, so format a glass pane instead
        else:
            format gui slot 0 of player with cyan glass pane named " "

        #The next button will use the same expression above. The expression above returns null in case
        #There isn't any avaliable values for a page
        if page arg + 1 of all players with 45 lines is set:
            format gui slot 8 of player with arrow named "Next page" to run player command "/players %arg + 1%"
        else:
            format gui slot 8 of player with cyan glass pane named " "


Any way to loop the slots to check if they are not set, format it to 0 instead of having to format the empty slots one by one?

You can use a condition to check if a gui is set
code_language.skript:
loop 54 times:
    if slot loop-integer - 1 is not a gui:
        format gui slot loop-integer - 1 of player with air
I will add a reminder to add an options to lock slots that aren't formated (so players can't place items in it)
 
Ok, thanks for the help - i was annoyed when i posted it i tried for hours but yeah thanks
Not a problem. I tried to make the tutorial as simple as possible, but if someone doesn't understando something, is just to ask it here (or any avaliable places for it)
 
How can lore be added to an item when setting it? I thought this would work:

format gui slot 21 of player with shears named "&2Default Kit" with lore "hi"

It doesn't seem to work though.