1. 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!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

TuSKe GUI Manager Tutorial

Discussion in 'Tutorials' started by Tuke_Nuke, Feb 23, 2017.

  1. Tuke_Nuke

    Retired Staff Addon Developer

    Joined:
    Dec 9, 2016
    Messages:
    150
    Likes Received:
    87
    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 (Skript):
    1. #Effect
    2. open (virtual %inventory type% inventory [with size %integer%] [(named|with (name|title)) %string%]) to %players%
    3.  
    4. #Only the expression between parentheses is from TuSKe, which returns a blank inventory.
    5. #The rest is just the effect from vanilla Skript.
    Code (Skript):
    1. #Effects
    2. (format|create|make) [a] gui slot %integers% of %players% with %item stack% [to [do] nothing]
    3.  
    4. (format|create|make) [a] gui slot %integers% of %players% with %item stack% to close [(using|with) %click action% [(button|click|action)]]
    5.  
    6. (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%]
    7.  
    8. (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%]
    9.  
    10. (format|create|make) [a] gui slot %integers% of %players% with %item stack% to (run|exe[cute]) [gui [click]] event
    Code (Skript):
    1. #Effects
    2. (unformat|remove) [the] gui slot %integers% of %players%
    3.  
    4. (unformat|remove) [all] [the] gui slots of %players%
    Code (Skript):
    1. %player% has [a] gui
    2. %player% does(n't| not) have [a] gui
    3.  
    4. slot %number% of %player% is [a] gui
    5. 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 (Skript):
    1. left
    2. right
    3. shift left
    4. shift right
    5. double click
    6. middle
    7. number key
    8. drop
    9. control drop
    Code (Skript):
    1. left mouse button
    2. right mouse button
    3. left mouse button with shift
    4. right mouse button with shift
    5. double click using mouse
    6. middle mouse button
    7. number key
    8. drop key
    9. 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 (Skript):
    1. [on] gui (action|click)
    2.  
    3. #Values:
    4. player : the player who clicked on item.
    5.  
    6. event-inventory : The inventory (can only be the top inventory until this moment)
    7.  
    8. event-number : The slot number
    9.  
    10. event-item : the item in cursor of the player
    11. #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'
    12.  
    13. event-type : the click type (left, right ...)
    14. #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 (Skript):
    1. command /gui:
    2.     trigger:
    3.         if sender is console:
    4.             broadcast "This was executed by console!"
    5.             stop
    6.         if player has permission "*":
    7.             send "Player executed this command with permission ""*"""
    8.             wait a tick
    9.             if player doesn't have permission "*":
    10.                 send "Player doesn't have that permission anymore."
    11.             else:
    12.                 send "Well, player still has this permission, but maybe is he an op?"
    13.         else:
    14.             send "Player execute this command without permission"
    15.                  
    16. command /guiExample:
    17.     trigger:
    18.         open virtual chest inventory to player
    19.         format gui slot 0 of player with stone named "It won't do anything"
    20.         format gui slot 1 of player with stone named "It will just close" to close
    21.         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
    22.         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"
    23.         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 "*"
    24.         format gui slot 5 of player with stone named "It will make the console execute a command" to run console command "/gui"
    25.         format gui slot 6 of player with stone named "It will run the function doSomething()" to run function doSomething()
    26.         format gui slot 7 of player with stone named "It will close and then run the function doSomething()" to close then run function doSomething()
    27.         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
    28.         format gui slot 9 of player with stone named "It will run the gui event" to run gui event
    29.  
    30. 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.
    31.     broadcast "And it did"
    32.          
    33. on gui click:
    34.     send "It was executed in a separated event"
    Code (Skript):
    1. function changeName(p: Player, clicktype: String):
    2.     set {_number} to name of slot 4 of {_p}'s current inventory parsed as number #Requires SkQuery or Bensku's fork
    3.     if {_clicktype} is "left":
    4.         remove 1 from {_number}
    5.     else if {_clicktype} is "shift left":
    6.         remove 100 from {_number}
    7.     else if {_clicktype} is "right":
    8.         add 1 to {_number}
    9.     else if {_clicktype} is "shift right":
    10.         add 100 to {_number}
    11.     set name of slot 4 of {_p}'s current inventory to "%{_number}%"
    12.  
    13. command /multiactionExample:
    14.     trigger:
    15.         open virtual dispenser inventory named "Multi-action example" to player
    16.         set {_item} to diamond named "1"
    17.         set line 1 of lore of {_item} to "&7Left click: remove 1"
    18.         set line 2 of lore of {_item} to "&7Shift left click: remove 100"
    19.         set line 3 of lore of {_item} to "&7Right click: add 1"
    20.         set line 4 of lore of {_item} to "&7Shift right click: add 100"
    21.         format gui slot 4 of player with {_item} to run function changeName(player, "left") with "left" click
    22.         format gui slot 4 of player with {_item} to run function changeName(player, "shift left") with "shift left" click
    23.         format gui slot 4 of player with {_item} to run function changeName(player, "right") with "right" click
    24.         format gui slot 4 of player with {_item} to run function changeName(player, "shift right") with "shift right" click
    Code (Skript):
    1. function openMenu(p: Player, type: String):
    2.     if {_type} is "page 1":
    3.         open virtual chest inventory with size 1 named "Page 1" to {_p}
    4.         make a gui slot 0 of {_p} with stone named "Go to page 2" to run function openMeny({_p}, "page 2")
    5.     else if {_type} is "page 2":
    6.         open virtual chest inventory with size 1 named "Page 2" to {_p}
    7.         make a gui slot 0 of {_p} with stone named "Go to page 3" to run function openMeny({_p}, "page 3")
    8.    #And so on until ends of page...
    9.     else if {_type} is "page 3":
    10.         open virtual chest inventory with size 1 named "Page 3" to {_p}
    11.         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.
     
    • Informative Informative x 6
    • Like Like x 2
  2. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,088
    Likes Received:
    146
    Very nice tutorial ! I'll link it when I recommend using the GUI Manager instead of format slot :emoji_stuck_out_tongue_closed_eyes:
     
    • Agree Agree x 3
  3. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,088
    Likes Received:
    146
    best gui ever, thanks for making best things :emoji_blush:
     
    • Agree Agree x 1
  4. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,088
    Likes Received:
    146
    Why, when i use this GUI manager my scripts are loaded 5x times longer?
     
  5. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,088
    Likes Received:
    146
    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 Like x 1
  6. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,088
    Likes Received:
    146
    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.
     
  7. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,088
    Likes Received:
    146
    just put the name as " "
     
  8. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,088
    Likes Received:
    146
    I'm doing this already, but thanks.
     
    • Creative Creative x 1
  9. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,088
    Likes Received:
    146
    Like no hover (name/lore) thing at all when you move the cursor to the item? Just non-existence?
     
  10. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,088
    Likes Received:
    146
    Yep.
     
  11. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,088
    Likes Received:
    146
    As far as I know, I do not think this is physically possible.
     
  12. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,088
    Likes Received:
    146
    Sadly not, it is something that it's triggered by client side only.
     
  13. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,088
    Likes Received:
    146
    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
     
    • Agree Agree x 1
  14. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,088
    Likes Received:
    146
    Don't use it then.
     
  15. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,088
    Likes Received:
    146
    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?
     
    • Like Like x 1
  16. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,088
    Likes Received:
    146
    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 (Skript):
    1. command /players [<number=1>]:
    2.     trigger:
    3.         #Open a inventory to a player, that's basic
    4.         open virtual chest with 6 rows named "Online players - Page %arg%" to player
    5.  
    6.         # 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')
    7.         #It basically returns a list of integers from 1 to 7
    8.         #So, it will format the top line slots, because the effect accepts a list of slots
    9.         format gui slot 7 times of player with cyan glass pane named " "
    10.  
    11.         #This will be the first slot of player, where the player's skull will be placed
    12.         set {_slot} to 9
    13.  
    14.         #That's a simple tuske expression which splits a list into pages
    15.         # with x lines (in this case, x players each page) and to get a number page
    16.         loop page arg of all players with 45 lines:
    17.             format gui slot {_slot} of player with loop-value's skull named "%loop-value%"
    18.             add 1 to {_slot} #Then we increase the slot
    19.  
    20.         #Now we need to set up the next/previous page button
    21.  
    22.         #The previous button is simple, if the page is more than 1, then it has a previous page
    23.         if arg is more than 1:
    24.             format gui slot 0 of player with arrow named "Previous page" to run player command "/players %arg - 1%"
    25.         #If it's not, so format a glass pane instead
    26.         else:
    27.             format gui slot 0 of player with cyan glass pane named " "
    28.  
    29.         #The next button will use the same expression above. The expression above returns null in case
    30.         #There isn't any avaliable values for a page
    31.         if page arg + 1 of all players with 45 lines is set:
    32.             format gui slot 8 of player with arrow named "Next page" to run player command "/players %arg + 1%"
    33.         else:
    34.             format gui slot 8 of player with cyan glass pane named " "

    You can use a condition to check if a gui is set
    Code (Skript):
    1.  
    2. loop 54 times:
    3.     if slot loop-integer - 1 is not a gui:
    4.         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)
     
    • Useful Useful x 1
  17. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,088
    Likes Received:
    146
    Ok, thanks for the help - i was annoyed when i posted it i tried for hours but yeah thanks
     
  18. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,088
    Likes Received:
    146
    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)
     
  19. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,088
    Likes Received:
    146
    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.
     
  20. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,088
    Likes Received:
    146
    Check multi action spoiler
     
Loading...