Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Paginated GUI Example
- # Made by AsuDev
- # Requirements
- # Skript 2.3.6+
- # Tested on Paper Spigot 1.13.2
- # Function that returns true or false based on if the player can open a specific page
- function checkForSpecifiedPage(slot: number, guiSize: number, list: objects) :: boolean:
- set {_counter} and {_format} to 0
- loop {_list::*}:
- if {_counter}+1 is between {_slot} and {_slot}+({_guiSize}-1):
- add 1 to {_format}
- add 1 to {_counter}
- if {_format} is 0:
- return false
- else:
- return true
- # Example Paginated GUI
- command /pagtest [<integer=1>]:
- trigger:
- # Make sure to block anhything below 0 as a page
- if arg 1 is less than or equal to 0:
- message "&c0 &7is not a valid page."
- stop
- # Example size of the inventory / Must be divisible by 9 and up to 53
- # In the example I am using, I cannot use 53 size because I am going to
- # dedicate 1 row for the page switchers, therefore the max size in this
- # example can only be 45
- set {_guiSize} to 9
- # List to use as an example for the GUI
- set {_c} to 0
- loop 14 times:
- add 1 of apple named "&cApple %{_c}%" to {_list::*}
- add 1 to {_c}
- # Gets the slot to start at on specified page
- set {_slot} to ((arg 1 * {_guiSize}) + 1) - {_guiSize}
- # Checks if the specified page has anything in it / Gets how many available pages there are
- if checkForSpecifiedPage({_slot}, {_guiSize}, {_list::*}) is false:
- set {_availablePages} to ceil(size of {_list::*}/{_guiSize})
- message "&7Invalid page. &7You have &c%{_availablePages}% &7available pages."
- stop
- # Open the Gui to the player / I used +1 because I want a row dedicated for the page turners
- open chest with ({_guiSize}/9) + 1 rows named "&cApples &8(&9Page %arg 1%&8)" to the player
- # Example buttons to switch to different pages / The last row in this case is dedicated to these
- set slot {_guiSize}+2 of player's current inventory to 1 of feather named "&c&l<- PREVIOUS PAGE&r"
- set slot {_guiSize}+6 of player's current inventory to 1 of feather named "&a&lNEXT PAGE ->&r"
- # Formats the gui
- set {_counter} and {_format} to 0
- loop {_list::*}:
- if {_counter}+1 is between {_slot} and {_slot}+({_guiSize}-1):
- set slot {_format} of player's current inventory to loop-value
- add 1 to {_format}
- add 1 to {_counter}
- # You need some kind of identifier to know what inventory your clicking in.
- # In this examples case, I will use the GUI name.
- # You also need an identifier to get what page you are currently on. I also used the name for this.
- on inventory click:
- name of player's current inventory contains "&cApples &8(&9Page "
- if name of clicked item is "&a&lNEXT PAGE ->&r" or "&c&l<- PREVIOUS PAGE&r":
- cancel event
- # Gets the page you are on
- set {_getCurrentPage} to name of player's current inventory
- # Removes all text other than page number from name of the GUI / This is one method
- # of getting the page they are on
- replace all "&cApples &8(&9Page " and "&8)" with "" in {_getCurrentPage}
- set {_getCurrentPage} to {_getCurrentPage} parsed as integer
- # Adds 1 or removes 1 based on if your clicking next page or previous page
- if name of clicked item is "&a&lNEXT PAGE ->&r":
- add 1 to {_getCurrentPage}
- else:
- remove 1 from {_getCurrentPage}
- # Makes sure the player doesn't open page 0
- if {_getCurrentPage} is 0:
- message "&c0 &7is not a valid page."
- stop
- # Open the new page to the player by command
- # You can also create a function if you do not want
- # to use a command for this
- make player execute command "pagtest %{_getCurrentPage}%"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement