Chest password

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

David

Member
Jan 31, 2017
16
0
1
20
as I do for when I open a chest I have to put a 3 digit password, but through the gui menu, the example is in this video:
 
as I do for when I open a chest I have to put a 3 digit password, but through the gui menu, the example is in this video:
Is this good?
code_language.skript:
options:
    pin-code-length: 4
    override-permission: admin
       
on right click on chest:
    cancel event
    open virtual chest inventory with 5 rows named "&aChest lock" to player
    loop 9 times:
        make gui slot (loop-number + 3 + (round((loop-number +1)/ 3) * 6)) of player with loop-number of gray concrete named "&e%loop-number%" to run function enterPassNumber(player, loop-number)
    make gui slot 23 of player with red concrete named "&eReset password" to run function resetPassNumbers(player)
    if player has permission "{@override-permission}":
        make gui slot 25 of player with yellow concrete named "&eForce open (Admin only)" to run function forceOpen(player, event-block)
    while name of player's current inventory contains "&aChest lock":
        if size of {enteredpass::%player%::*} >= {@pin-code-length}:
            set {_pass::*} to {enteredpass::%player%::*}
            exit loop
        wait 1 tick
    delete {enteredpass::%player%::*}
    {_pass::*} is set
    set {_inp} to join {_pass::*} with ""
    remove gui slot 23 of player
    remove gui slot 25 of player
    if {_inp} is {chestpassword::%location of event-block%}:
        play sound "UI_BUTTON_CLICK" at location of player for player
        make gui slot 24 of player with chest named "&eOpen chest" to run function openPassChest(player, event-block)
        make gui slot 25 of player with name tag named "&eDelete password" to close then run function deletePassChest(event-block)
    else if {chestpassword::%location of event-block%} is not set:
        make gui slot 24 of player with green concrete named "&eConfirm pass" to close then run function setChestPass(player, event-block, {_inp})
    else:
        play sound "BLOCK_ANVIL_LAND" with volume .5 at location of player for player
        close inventory of player
               
function enterPassNumber(p: player, n: integer):
    add {_n} to {enteredpass::%{_p}%::*}

function resetPassNumbers(p: player):
    delete {enteredpass::%{_p}%::*}

function openPassChest(p: player, b: block):
    open block at {_b} to {_p}
   
function setChestPass(p: player, b: block, pass: text):
    set {_loc} to location of {_b}
    set {chestpassword::%{_loc}%} to {_pass}
    play sound "entity_experience_orb_pickup" at {_p} for {_p}
   
function deletePassChest(b: block):
    set {_loc} to location of {_b}
    delete {chestpassword::%{_loc}%}
   
function forceOpen(p: player, b: block):
    set {_loc} to location of {_b}
    set {_l::*} to split {chestpassword::%{_loc}%} at ""
    set {_i} to size of {_l::*}
    delete {_l::%{_i}%}
    set {enteredpass::%{_p}%::*} to {_l::*}

on break:
    set {_loc} to location of event-block
    delete {chestpassword::%{_loc}%}