Create a GUI with as many pages it needs.

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

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

KroterPvP

Active Member
Apr 10, 2017
178
7
18
22
Hello. I'm working on a smart inventory to show bans. I want it to create as many pages it needs. The gui has 6 rows, but the 6th row is used to manage aspects of the gui like changing the page and those things. So the bans are only sown in the first 5th rows. If the gui has more than 5 rows of bans, it must add a new page to show more bans. I don't know how to code it.

Skript Version: Skript 2.2-dev27
Skript Author: Bensku
Minecraft Version: 1.8.8
Addons I'm using: SkQuerry 3 and Skellet
I have tried searching the docs, and I found nothing.
I've also tried to search in the forums. Yes
What other methods have you tried to fix it? I don't need to do it
Skript code:
code_language.skript:
command /bans:
    trigger:
        player has permission "sb.bans":
            clear {bans1::%player%::*}
            open chest with 6 rows named "&0List of banned players" to player
            wait 0.5 ticks
            set slot 45 of player's current inventory to book named "&eMain Page"
            wait 0.5 ticks
            set slot 46 of player's current inventory to black stained glass pane named "&7"
            wait 0.5 ticks
            set slot 47 of player's current inventory to black stained glass pane named "&7"
            wait 0.5 ticks
            set slot 48 of player's current inventory to black stained glass pane named "&7"
            wait 0.5 ticks
            set slot 49 of player's current inventory to anvil named "&eSearch players" with lore "||&7Click here to &csearch &7banned players.||&7You will need to type it in chat."
            wait 0.5 ticks
            set slot 50 of player's current inventory to black stained glass pane named "&7"
            wait 0.5 ticks
            set slot 51 of player's current inventory to black stained glass pane named "&7"
            wait 0.5 ticks
            set slot 52 of player's current inventory to black stained glass pane named "&7"
            wait 0.5 ticks
            set slot 53 of player's current inventory to arrow named "&eNext Page"
            set {_slot} to 0
            wait 1 tick
            loop {bans::*}:
                if {_slot} is less than 45:
                    set slot {_slot} 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%}%||"
                    set {bans1::%player%::*} to true
                    add 1 to {_slot}
        else:
            send "&8[&c&lBANS&8] &cYou don't have permission to do this!"
on inventory click:
    if name of player's current inventory is "&0List of banned players":
        cancel event
        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"
        if clicked slot is 45:
            close player's inventory
            execute player command "/bans"
        if clicked slot is 49:
            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."
        if clicked slot is 53:
            set {_slot} to -1
            loop 44 times:
                add 1 to {_slot}
                set slot {_slot} of player's current inventory to air
            set {_slot} to 0
            loop {bans::*}:
                if {_slot} is less than 45:
                    if {bans1::%player%::%loop-index%} is not set:
                        set slot {_slot} of player's current inventory to loop-value's skull named "&7Player &8» &c%loop-value% &7(&c##%loop-index%&7)." with lore "||&7Is Banned &8» &c%{sban.banned.%loop-value%}%&7.||&7Banned by &8» &c%{sban.bannedby.%loop-value%}%&7.||&7Ban reason &8» &c%{sban.reason.%loop-value%}%&7.||&7Banned on &8» &c%{sban.time.%loop-value%}%&7.||&7"
                        set {bans1::%player%::%loop-index%} to true
                        add 1 to {_slot}
Errors loading this skript: No errors
 
I had to do something of the sort for a minigame invitation system, so I believe I can help you. In addition, if you plan to see yourself coding with Skript- or any basic language for that matter, I suggest you familiarize yourself with some basic coding practices, as they will help you in the future. We'll need to use recursive programming in order to achieve this; there may be different ways to do it, but I find this the easiest. We'll need to define a function, to then have that function call itself.

Here's my code; I didn't touch the inventory clicking stuff, just the dynamic chest menu.
code_language.skript:
function bansPage(p: player, page: number):
    set {_pageStart} to 45*{_page}
    set {_i} to 1
    set {_a} to 0
    open chest with 6 rows named "&3Page %{_page}%" to {_p}
    wait 2 ticks
    loop {bans::*}:
        (loop-index parsed as integer) > {_pageStart}
        set {_player} to "%loop-value%" parsed as offline player
        set slot {_a} of {_p}'s current inventory to skull of {_player} 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 {_a}
        if {_a} = ((45*{_i})):
            exit loop
    format slot 49 of {_p} with book named "&eMain Page" to run [bansPage({_p}, 0)]
    if (amount of {bans::*}) > {_pageStart} + 45:
        format slot 53 of {_p} with arrow named "&9Next Page" to run [bansPage({_p}, ({_page} + 1))]
    if {_page} > 0:
        format slot 45 of {_p} with arrow named "&9Previous Page" to run [bansPage({_p}, ({_page} - 1))]

command /bans:
    permission: sb.bans
    permission message: &8[&c&lBANS&8] &cYou don't have permission to do this!
    trigger:
        bansPage(player, 0)
 
I had to do something of the sort for a minigame invitation system, so I believe I can help you. In addition, if you plan to see yourself coding with Skript- or any basic language for that matter, I suggest you familiarize yourself with some basic coding practices, as they will help you in the future. We'll need to use recursive programming in order to achieve this; there may be different ways to do it, but I find this the easiest. We'll need to define a function, to then have that function call itself.

Here's my code; I didn't touch the inventory clicking stuff, just the dynamic chest menu.
code_language.skript:
function bansPage(p: player, page: number):
    set {_pageStart} to 45*{_page}
    set {_i} to 1
    set {_a} to 0
    open chest with 6 rows named "&3Page %{_page}%" to {_p}
    wait 2 ticks
    loop {bans::*}:
        (loop-index parsed as integer) > {_pageStart}
        set {_player} to "%loop-value%" parsed as offline player
        set slot {_a} of {_p}'s current inventory to skull of {_player} 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 {_a}
        if {_a} = ((45*{_i})):
            exit loop
    format slot 49 of {_p} with book named "&eMain Page" to run [bansPage({_p}, 0)]
    if (amount of {bans::*}) > {_pageStart} + 45:
        format slot 53 of {_p} with arrow named "&9Next Page" to run [bansPage({_p}, ({_page} + 1))]
    if {_page} > 0:
        format slot 45 of {_p} with arrow named "&9Previous Page" to run [bansPage({_p}, ({_page} - 1))]

command /bans:
    permission: sb.bans
    permission message: &8[&c&lBANS&8] &cYou don't have permission to do this!
    trigger:
        bansPage(player, 0)
Thanks!
 
Status
Not open for further replies.