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.

Vanilla GUI Border+ Functions

Discussion in 'Snippets' started by WrexBG, May 6, 2020.

  1. WrexBG

    Supporter

    Joined:
    Mar 3, 2020
    Messages:
    2
    Likes Received:
    0
    These are functions you may find useful when working with GUI's. It's just an easy way to add border, border with preset pattern, and fill or clear the inventory.

    Some things to know beforehand:
    - These are functions
    - Required addons: none
    - Tested on Minecraft 1.15.2 and Skript 2.4.1
    - There are default values for the functions mention after each one
    - It automatically gets the GUI size

    ★ Borders​
    Code (Text):
    1. function addGUIBorder(p: player, item: item = stained glass pane, itemName: string = "&7"):
    2.     set {_menuSize} to (rows of {_p}'s current inventory)
    3.     set {_slot} to 0
    4.     loop 9 times: #Top
    5.         set slot {_slot} of {_p}'s current inventory to {_item} named {_itemName}
    6.         add 1 to {_slot}
    7.     set {_slot} to 9
    8.     loop {_menuSize}-2 times: #Sides
    9.         set slot {_slot} of {_p}'s current inventory to {_item} named {_itemName}
    10.         set slot {_slot}+8 of {_p}'s current inventory to {_item} named {_itemName}
    11.         add 9 to {_slot}
    12.     set {_slot} to ({_menuSize}-1)*9
    13.     loop 9 times: #Bottom
    14.         set slot {_slot} of {_p}'s current inventory to {_item} named {_itemName}
    15.         add 1 to {_slot}
    Usage:
    addGUIBorder(player, red stained glass pane, "&7")
    addGUIBorder(player) #Default values for the name is "&7" and for the item is a random colored glass pane

    Code (Text):
    1. function addGUIBorder2(p: player, item: item = stained glass pane, item2: item = stained glass pane, itemName: string = "&7"):
    2.     set {_menuSize} to (rows of {_p}'s current inventory)
    3.     set {_slot} to 0
    4.     loop 9 times: #Top
    5.         set slot {_slot} of {_p}'s current inventory to {_item} named {_itemName}
    6.         set slot {_slot} of {_p}'s current inventory to {_item2} named {_itemName} if floor({_slot}/2) != ({_slot}/2)
    7.         add 1 to {_slot}
    8.     set {_slot} to 9
    9.     loop {_menuSize}-2 times: #Sides
    10.         set slot {_slot} of {_p}'s current inventory to {_item} named {_itemName}
    11.         set slot {_slot} of {_p}'s current inventory to {_item2} named {_itemName} if floor({_slot}/2) != ({_slot}/2)
    12.         set slot {_slot}+8 of {_p}'s current inventory to {_item} named {_itemName}
    13.         set slot {_slot}+8 of {_p}'s current inventory to {_item2} named {_itemName} if floor(({_slot}+8)/2) != (({_slot}+8)/2)
    14.         add 9 to {_slot}
    15.     set {_slot} to ({_menuSize}-1)*9
    16.     loop 9 times: #Bottom
    17.         set slot {_slot} of {_p}'s current inventory to {_item} named {_itemName}
    18.         set slot {_slot} of {_p}'s current inventory to {_item2} named {_itemName} if floor({_slot}/2) != ({_slot}/2)
    19.         add 1 to {_slot}
    Note: A GUI with odd number of rows is recommended
    Usage:
    addGUIBorder2(player, red stained glass pane, orange stained glass pane, "&7")
    addGUIBorder2(player) #Default values for the name is "&7" and for both items is a random colored glass pane

    ★ Other (Misc)​
    Code (Text):
    1. function fillGUI(p: player, item: item = light gray stained glass pane, itemName: string = "&7", keepItems: boolean = true):
    2.     set {_menuSize} to (rows of {_p}'s current inventory)
    3.     set {_slot} to 0
    4.     loop 9*{_menuSize} times:
    5.         if {_keepItems} is true:
    6.             set slot {_slot} of {_p}'s current inventory to {_item} named {_itemName} if slot {_slot} of {_p}'s current inventory is air
    7.         else:
    8.             set slot {_slot} of {_p}'s current inventory to {_item} named {_itemName}
    9.         add 1 to {_slot}
    Usage:
    fillGUI(player, white stained glass pane, "&7", false)
    fillGUI(player) #Default values for the name is "&7", for the item is light gray glass pane, and whether to keep or overwrite items in the GUI: true(keep). Setting the last value or false will overwrite

    Code (Text):
    1. function clearGUI(p: player):
    2.     delete all items in {_p}'s current inventory
    Usage:
    clearGUI(player)

    This is work I felt like sharing. If you are looking for something simpler but more efficient I strongly recommend the following function by Blue:
    Code (Text):
    1. function border(size: integer) :: integers:
    2.   stop if {_size} is 1 or 2
    3.   add (integers between 0 and 8) to {_r::*}
    4.   add (integers between ({_size}-1)*9 and ({_size}-1)*9+8) to {_r::*}
    5.   loop integers from 1 to {_size}:
    6.    add loop-value*9 to {_r::*} if {_r::*} doesn't contain loop-value*9
    7.    add loop-value*9+8 to {_r::*} if {_r::*} doesn't contain loop-value*9+8
    8.   return {_r::*}
    Usage:
    Code (Text):
    1. set {_i} to chest inventory with 3 rows
    2. set slots border(3) of {_i} to red wool
    3. open {_i} to player
     

Share This Page

Loading...