mathhulk's Snippets (Paginated GUI, Typing GUI, Armor Stand Editor, ...)

  • 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!

mathhulk

Member
Jan 29, 2017
55
15
0
California, USA
mathhulk.com
I currently only have a few, but more will be coming soon.

Paginated GUI
Today, I embarked on a project to create a very manageable and easy-to-use GUI for both players and server administrators. After fiddling around with a pagination system for my tag GUI, I finally got it working by using a system similar to grabbing pagination with PHP.

I've explained each part of the script pretty well using comments, hoping that you'll be able to edit and fill in the rest yourself.
code_language.skript:
command /gui [<integer=1>]:
    trigger:
        set {_list::*} to integers from 1 to 215
        # This is just an example of a list variable that would be used.
        # Make sure to change the other parts of the script where this variable is used and not just this list variable.
       
        set {_page::rows} to 3
        # This is the amount of rows in the GUI.

        set {_page::max} to arg 1 * (({_page::rows} - 1) * 9)
        set {_page::min} to (arg 1 - 1) * (({_page::rows} - 1) * 9)
        set {_page::posts} to 0
        set {_page::count} to 0
        set {_page::number} to arg 1
        # These specify the amount of items that should be displayed on each page.

        set {_pages} to size of {_list::*} / (({_page::rows} - 1) * 9)
        set {_pages} to "%{_pages}%"
        set {_pages::*} to {_pages} split at "."
        # The only reason I have to set a variable to itself is because Skript won't allow me to do this any other way.

        set {_page::total} to {_pages::1}
        if {_pages::2} is set:
            set {_page::total} to {_page::total} parsed as an integer
            add 1 to {_page::total}
        # This will grab the total amount of pages.

        if inventory name of player's current inventory does not contain "&8GUI | ":
            open chest with {_page::rows} rows named "&8GUI | %{_page::number}%/%{_page::total}%" to player
        # Only open a new chest if the player isn't already in the GUI.

        else:
            loop ({_page::rows} * 9) times:
                set slot (loop-number - 1) of player's current inventory to air
            set inventory name of player's current inventory to "&8GUI | %{_page::number}%/%{_page::total}%"
        # Reset the GUI if the player is already in it.


        if {_page::number} is greater than 1:
            set slot (({_page::rows} - 1) * 9) of player's current inventory to piston named "&dPrevious Page"
        # Display a previous page button only if the user is not on the first page.

        loop {_list::*}:
            if {_page::count} is less than {_page::max}:
                if {_page::count} is greater than or equal to {_page::min}:
                    # Only display an item if certain page specifications are met.
         
                    set slot {_page::posts} of player's current inventory to stone named "&b%loop-value%"
                    add 1 to {_page::posts}
            add 1 to {_page::count}

        if {_page::number} is less than {_page::total}:
            set slot ({_page::rows} * 9 - 1) of player's current inventory to piston named "&dNext Page"
        # Display a next page button if the current page is not the last page.

on inventory click:
    if inventory name of player's current inventory contains "&8GUI | ":
        cancel the event
       
        set {_page::rows} to 3
        # This is the amount of rows in the GUI.

        set {_page} to "%inventory name of player's current inventory%"
        replace all "&8GUI | " in {_page} with ""
        set {_pages::*} to {_page} split at "/"
        # Grab the page that the player is currently on.

        if clicked slot is (({_page::rows} - 1) * 9):
            if clicked item name is "&dPrevious Page":
                if {_pages::1} parsed as an integer is greater than 1:
                    execute player command "/gui %{_pages::1} parsed as an integer - 1%"
                    # Open the previous page to the user if they are not already on it.
                else:
                    close inventory of player
                    send "You are already on the first page."
        else if clicked slot is ({_page::rows} * 9 - 1):
            if clicked item name is "&dNext Page":
                execute player command "/gui %{_pages::1} parsed as an integer + 1%"
                # Open the next page to the user.


Typing GUI
With the typing GUI, you can allow your players to type uppercase and lowercase letters, along with spaces, in a GUI and have it outputted via a message. You can integrate this into other scripts that might require some form of typing (clan names, etc.) where you might not want to use chat.
...Possibly a replacement for the anvil GUI?
code_language.skript:
command /type:
    trigger:
        open chest with 5 rows named "&8Text: _" to player
        # Open a chest to the player with enough rows to handle the alphabet and numbers, along with a space.
 
        set slot 41 of player's current inventory to green stained glass pane named "&aDone"
        set slot 39 of player's current inventory to red stained glass pane named "&cCancel"
        set slot 35 of player's current inventory to white stained glass pane named "&7Space"
        set slot 44 of player's current inventory to gray stained glass pane named "&9Backspace"
        set slot 36 of player's current inventory to gray stained glass pane named "&9Uppercase"
        # Adds a done and cancel button, along with the space character and uppercase letters.
 
        set {_slot} to 36
        loop 9 times:
            if {_slot} is not 39 or 44 or 41 or 36:
                set slot {_slot} of player's current inventory to black stained glass pane named "&8"
            add 1 to {_slot}
        # Set the empty slots of the bottom row to black stained glass pane.
    
        set {_letters::*} to split "abcdefghijklmnopqrstuvwxyz123456789" at ""
        set {_slot} to 0
        loop {_letters::*}:
            if {_slot} is greater than 34:
                stop
            set slot {_slot} of player's current inventory to name tag named "&7%loop-value%"
            add 1 to {_slot}
        # Loop through the letters of the alphabet and add them in to the GUI.
 
on inventory click:
    if inventory name of player's current inventory contains "&8Text: ":
        cancel the event
 
        set {_text} to "%inventory name of player's current inventory%"
        replace all "&8Text: " and "_" in {_text} with ""
        # Grab the name of the GUI (their text).
 
        if clicked slot is less than 36:
            if length of {_text} is greater than 64:
                send "You cannot add anymore letters to your text."
            # Set the maximum number of letters to 64, as I am not sure what the maximum GUI title length is.
        
            else:
                set {_name} to "%{_text}%%clicked item name%_"
                replace all "&7" in {_name} with ""
                # Grab the letter clicked.
        
                if clicked slot is 35:
                    set {_name} to "%{_text}% _"
                # Set the letter to a space if the space block is clicked.
            
                if length of {_text} is greater than 62:
                    replace all "_" in {_name} with ""
                # Remove the _ from the title to inform users that they are no longer able to add letters.
            
                set inventory name of player's current inventory to "&8Text: %{_name}%"
                # Set the name of the inventory to the new text.
        else if clicked slot is 39:
            close inventory of player
            send "Your text has been removed from memory."
        else if clicked slot is 41:
            close inventory of player
            if {_text} is not "":
                send "Your text is: %{_text}%"
                # Send the text to the user if there is any.
            else:
                send "No text had been added."
        else if clicked slot is 44:
            if length of {_text} is greater than 1:
                set {_name} to subtext of "%{_text}%" from 1 to (length of {_text} - 1)
            else:
                set {_name} to ""
            # Grab the text and remove the last letter, or set the text to empty if there is no text after removal.
    
            set inventory name of player's current inventory to "&8Text: %{_name}%_"
            # Set the name of the inventory to the new text.
        else if clicked slot is 36:
            if clicked item name is "&9Uppercase":
                set {_letters::*} to split "ABCDEFGHIJKLMNOPQRSTUVWXYZ" at ""
                set {_slot} to 0
                loop {_letters::*}:
                    if {_slot} is greater than 34:
                        stop
                    set slot {_slot} of player's current inventory to name tag named "&7%loop-value%"
                    add 1 to {_slot}
                set slot 36 of player's current inventory to gray stained glass pane named "&9Lowercase"
                # Set the letters to uppercase and the case button to lowercase.
            else if clicked item name is "&9Lowercase":
                set {_letters::*} to split "abcdefghijklmnopqrstuvwxyz" at ""
                set {_slot} to 0
                loop {_letters::*}:
                    if {_slot} is greater than 34:
                        stop
                    set slot {_slot} of player's current inventory to name tag named "&7%loop-value%"
                    add 1 to {_slot}
                set slot 36 of player's current inventory to gray stained glass pane named "&9Uppercase"
                # Set the letters to lowercase and the case button back to uppercase.


Armor Stand Editor
As suggested by one of the users on the official skUnity Discord server, I have made a very simple armor stand editor. I am calling such a snippet simple because it still requires basic knowledge of NBT and the values they support. For example, for true and false statements, you would have to input 1 or 0. However, for rotations, you don't need to add an f after the degree, as it is automatically entered.
code_language.skript:
command /editas [<text>] [<text>] [<text>] [<text>] [<text>]:
    trigger:
        if "%targeted entity%" is "armor stand":
            # Force the player to be looking at an armor stand.
     
            if arg 1 is "NoGravity" or "ShowArms" or "Invisible" or "Small" or "NoBasePlate":
                # Check if the first value is a piece of true/false NBT.
         
                if arg 2 is "1" or "0":
                    # Force the user to input either 1 (true) or 0 (false).
                 
                    add "{%arg 1%:%arg 2%}" to nbt of targeted entity
                    send "An NBT value of {%arg 1%:%arg 2%} has been added to the targeted armor stand."
                    # Add the NBT to the armor stand.
                 
                    stop
                send "You must specify 1 or 0. (true/false)"
            else if arg 1 is "Pose":
                if arg 2 is "Head" or "Body" or "LeftArm" or "RightArm" or "LeftLeg" or "RightLeg":
                    # Check if the second value is a correct part of the armor stand.
                 
                    if "%arg 3%%arg 4%%arg 5%" does not contain "<none>":
                        # Force the player to enter integers for the rotations.
                     
                        add "{%arg 1%:{%arg 2%:[%arg 3%f,%arg 4%f,%arg 5%f]}}" to nbt of targeted entity
                        send "An NBT value of {%arg 1%:{%arg 2%:[%arg 3%f,%arg 4%f,%arg 5%f]}} has been added to the targeted armor stand."
                        # Add the NBT to the armor stand.
                     
                        stop
                    send "You must specify three rotations."
                    stop
                send "You must specify a part of the armor stand to modify."
            else if arg 1 is "ArmorItems":
                if "%arg 2%%arg 3%%arg 4%%arg 5%" does not contain "<none>":
                    # Check if all of the arguments are filled in.
                 
                    set {_armor::head} to ""
                    set {_armor::chest} to ""
                    set {_armor::legs} to ""
                    set {_armor::boots} to ""
                    # Set the variables to empty, so that they won't return <none> if they aren't changed.
                 
                    if arg 2 is not "none":
                        set {_armor::head} to "Count:1,id:""%arg 2%"""
                        set targeted entity's helmet to (arg 2 parsed as an item)
                        # Change the NBT if the value isn't none.
                     
                    if arg 3 is not "none":
                        set {_armor::chest} to "Count:1,id:""%arg 3%"""
                        set targeted entity's chestplate to (arg 3 parsed as an item)
                        # Change the NBT if the value isn't none.
                     
                    if arg 4 is not "none":
                        set {_armor::legs} to "Count:1,id:""%arg 4%"""
                        set targeted entity's leggings to (arg 4 parsed as an item)
                        # Change the NBT if the value isn't none.
                     
                    if arg 5 is not "none":
                        set {_armor::boots} to "Count:1,id:""%arg 5%"""
                        set targeted entity's boots to (arg 5 parsed as an item)
                        # Change the NBT if the value isn't none.
                     
                    send "An NBT value of {ArmorItems:[{%{_armor::boots}%}, {%{_armor::legs}%}, {%{_armor::chest}%}, {%{_armor::head}%}]} has been added to the targeted armor stand."
                    send "&cskStuff is currently having problems with armor NBT, which is why we are using effects from Skript instead of adding NBT."
                    # Add the NBT to the armor stand.
                 
                    stop
                send "You must specify an item for each slot, or none."
            else:
                send "You must specify an NBT value to alter."
            stop
        send "You must be looking at an armor stand to edit it."
 
Last edited:
  • Like
Reactions: KingAlterIV
I know that adding the numbers to the list is an example but you could just do:
code_language.skript:
set {_list::*} to integers from 1 to 32
 
I know that adding the numbers to the list is an example but you could just do:
code_language.skript:
set {_list::*} to integers from 1 to 32
Yeah, the example was mostly focused on the pagination itself. As I was expecting users to replace the example list variable with a variable that was already set, I didn't really pay any attention to it.
[doublepost=1485826569,1485740371][/doublepost]Update:
  • Cleaned up a few parts of the snippet as noted above
  • Switching between pages is now seamless as the script no longer opens a new GUI for each page
    • check's if the user is already in the GUI
    • resets the GUI if the user is already in the GUI
[doublepost=1486174332][/doublepost]More Updates
  • Paginated GUI
    • Added more comments so that newer scripters might be able to understand the inventory click events better
    • The inventory click events are now only triggered if an item exists in the slot
  • Typing GUI
    • Support for uppercase and lowercase letters
    • Support for spaces and backspace
    • The text is sent to the user when they are finished
    • Smooth transitions between clicking items
    • The text is all saved in the title of the GUI
    • Supports text up to 64 letters long (this can be edited easily, as I wasn't sure if there was a title limit)
    • Supports a-b, A-B, 1-9, space, and backspace

[doublepost=1486189545][/doublepost]If anyone has suggestions for snippets, feel free to let me know!
[doublepost=1486278335][/doublepost]Armor Stand Editor
  • Easily edit the armor and other functionalities and customizations of armor stands through a single command
  • Supports true/false data tags for NoGravity, ShowArms, Invisible, Small and NoBasePlate
    • /editas NoGravity 1 (true)
  • Also supports Pose and ArmorItems data tags
    • /editas Pose Head 100 100 100
    • /editas ArmorItems iron_helmet iron_chestplate iron_leggings iron_boots
  • Must be looking at the Armor Stand
 
  • Like
Reactions: KingAlterIV
If any of you want/need to test the Snippets, they are live and on my server to test with the latest version (maths test server).
The IP is in my signature.
#ShamelessSelfPromotion
 
Updates
  • Removed the need to have to change the amount of rows everywhere
  • Added a variable to specify the amount of rows your GUI has
  • All equations now factor in the amount of rows variable instead of a number
  • Only have to change the rows variable now
 
Hello @mathhulkI know this thread is more than 1 Month old, but I need help.
Code
code_language.skript:
command /bans [<integer=1>]:
    trigger:
        set {_bans::*} to {bans::*}
        set {_sizeofbans::*} to size of {_bans::*}
        set {_page::max} to arg 1 * ((6 - 1) * 9)
        set {_page::min} to (arg 1 - 1) * ((6 - 1) * 9)
        set {_page::posts} to 0
        set {_page::count} to 0
        set {_page::number} to arg 1
        set {_pages} to size of {_bans::*} / ((6 - 1) * 9)
        set {_pages} to "%{_pages}%"
        set {_pages::*} to {_pages} split at "."
        set {_page::total} to {_pages::1}
        if {_pages::2} is set:
            set {_page::total} to {_page::total} parsed as an integer
            add 1 to {_page::total}
        if inventory name of player's current inventory does not contain "&0List of banned players":
            open chest with 6 rows named "&0List of banned players %{_page::number}%/%{_page::total}%" to player
        else:
            loop (6 * 9) times:
                set slot (loop-number - 1) of player's current inventory to air
            set inventory name of player's current inventory to "&0List of banned players %{_page::number}%/%{_page::total}%"
        if {_page::number} is greater than 1:
            set slot (6 * 9 - 9) of player's current inventory to arrow named "&ePrevious Page"
            set slot (6 * 9 - 8) of player's current inventory to black stained glass pane named "&7"
            set slot (6 * 9 - 7) of player's current inventory to black stained glass pane named "&7"
            set slot (6 * 9 - 6) of player's current inventory to black stained glass pane named "&7"
            set slot (6 * 9 - 5) of player's current inventory to anvil named "&eSearch players" with lore "||&7Click here to &csearch &7banned players.||&7You will need to type it's name in chat."
            set slot (6 * 9 - 4) of player's current inventory to book named "&eBasic information" with lore "||&7Banned users &8» &c%{_sizeofbans::*}%||"
            set slot (6 * 9 - 3) of player's current inventory to black stained glass pane named "&7"
            set slot (6 * 9 - 2) of player's current inventory to black stained glass pane named "&7"
            set slot (6 * 9 - 1) of player's current inventory to red stained glass pane named "&7"
        else:
            set slot (6 * 9 - 9) of player's current inventory to red stained glass pane named "&7"
            set slot (6 * 9 - 8) of player's current inventory to black stained glass pane named "&7"
            set slot (6 * 9 - 7) of player's current inventory to black stained glass pane named "&7"
            set slot (6 * 9 - 6) of player's current inventory to black stained glass pane named "&7"
            set slot (6 * 9 - 5) of player's current inventory to anvil named "&eSearch players" with lore "||&7Click here to &csearch &7banned players.||&7You will need to type it's name in chat."
            set slot (6 * 9 - 4) of player's current inventory to book named "&eBasic information" with lore "||&7Banned users &8» &c%{_sizeofbans::*}%||"
            set slot (6 * 9 - 3) of player's current inventory to black stained glass pane named "&7"
            set slot (6 * 9 - 2) of player's current inventory to black stained glass pane named "&7"
            set slot (6 * 9 - 1) of player's current inventory to red stained glass pane named "&7"
        loop {_bans::*}:
            if {_page::posts} is less than {_page::max}:
                if {_page::count} is greater than or equal to {_page::min}:
                    set slot {_page::posts} of player's current inventory to loop-value's skull named "&7Player &8» &c%loop-value%" with lore "||&7Ban ID &8» &7(&c##%loop-index%&7)||||&7Is Banned &8» &c%{sban.banned.%loop-value%}%||&7Banned by &8» &c%{sban.bannedby.%loop-value%}%||&7Banned on &8» &c%{sban.time.%loop-value%}%||"
                    add 1 to {_page::posts}
            add 1 to {_page::count}
        if {_page::number} is less than {_page::total}:
            set slot (6 * 9 - 1) of player's current inventory to arrow named "&eNext Page"
        if {_page::count} is 0:
            open chest with 1 row named "&0There are %{_page::count}% banned players" to player
            set slot 0 of player's current inventory to black stained glass pane named "&7"
            set slot 1 of player's current inventory to black stained glass pane named "&7"
            set slot 2 of player's current inventory to black stained glass pane named "&7"
            set slot 3 of player's current inventory to black stained glass pane named "&7"
            set slot 4 of player's current inventory to book named "&eThere aren't banned players" with lore "||&7Banned players will apear in this||&7gui. You will be able to manage||&7SuperBan's commands from here!"
            set slot 5 of player's current inventory to black stained glass pane named "&7"
            set slot 6 of player's current inventory to black stained glass pane named "&7"
            set slot 7 of player's current inventory to black stained glass pane named "&7"
            set slot 8 of player's current inventory to black stained glass pane named "&7"
on inventory click:
    if inventory name of player's current inventory contains "&0There are":
        cancel event
    if inventory name of player's current inventory contains "&0List of banned players":
        cancel event
        set {_page} to "%inventory name of player's current inventory%"
        replace all "&0List of banned players " in {_page} with ""
        set {_pages::*} to {_page} split at "/"
        if clicked slot is ((6 - 1) * 9):
            if clicked item's name is "&ePrevious Page":
                if {_pages::1} parsed as an integer is greater than 1:
                    execute player command "/bans %{_pages::1} parsed as an integer - 1%"
                else:
                    close player's inventory
                    send "You are already on the first page."
        else if clicked slot is (6 * 9 - 1):
            if clicked item's name is "&eNext Page":
                execute player command "/bans %{_pages::1} parsed as an integer + 1%"
        if clicked slot is less than 45:
            if clicked item is player head:
                if name of item contains "&7Player":
                    set {_playername} to "%clicked item's name%"
                    replace all "&7Player &8» &c" in {_playername} with ""
                    execute player command "/unban %{_playername}%"
                    execute player command "/bans %{_pages::1} parsed as an integer%"
        if clicked slot is 49:
            if clicked item's name is "&eSearch players":
                close player's inventory
                set {bans.chat::%player%} to true
                send "&8[&c&lBANS&8] &7You must write the player's name in chat. Type &ccancel &7to annullate the search."
on chat:
    if {bans.chat::%player%} is true:
        cancel event
        set {_search} to "%message%" parsed as offline player
        if {_search} is "cancel":
            delete {bans.chat::%player%}
            send "&8[&c&lBANS&8] &7You have succesfully annullated the search."
        else:
            if {sban.banned.%{_search}%} is not set:
                send "&8[&c&lBANS&8] &a%{_search}% &7is not banned."
                delete {bans.chat::%player%}
            else:
                if {sban.banned.%{_search}%} is true:
                    delete {bans.chat::%player%}
                    send "&8[&c&lBANS&8] &a%{_search}% &7is banned."
                    send "&9Obrir GUI per desbanejar a &a%{_search}%&9."
                else:
                    delete {bans.chat::%player%}
                    send "&8[&c&lBANS&8] &a%{_search}% &7is not banned."
All it's running well, it creates well the pages, but the Next page is not running. Why?

I'm using Skript 2.2 dev-27, SkQuerry 3 and Skellet.
 
Last edited by a moderator: