Crate+Key Skript

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

Fitting

Member
Nov 28, 2020
4
0
1
20
Code:
#                            #
#        Options                #
#                            #
options:
    p: &8[&5Crates&8]&c

#                    #
#        Opening        #
#                    #
on rightclick on chest:
    cancel event
    if {crate::mystery} is location of block:
        if player's held item is a book named "&5Mystery Key!":
            remove 1 book named "&5Mystery Key!" from player's inventory
            set {_tal} to random integer between 0 and 100
            if {_tal} is between 0 and 40:
                add 100000 to player's balance
                send "{@p} You won &e100k &cwith the chance of &840%%"
            if {_tal} is between 41 and 70:
                add 150000 to player's balance
                send "{@p} You won &e150k &cwith the chance of &830%%"
            if {_tal} is between 71 and 90:
                add 250000 to player's balance
                send "{@p} You won &e250k &cwith the chance of &820%%"
            if {_tal} is between 91 and 99:
                add 500000 to player's balance
                send "{@p} You won &e500k &cwith the chance of &89%%"
            if {_tal} is between 99 and 100:
                make console execute command "kit mystery %player%"
                send "{@p} You won &5kit Mystery &cwith the chance of &81%%"
                
#                        #
#       Crate + Keys        #
#                        #
command /givecrate [<text>]:
    permission: *
    trigger:
        if arg-1 is set:
            if arg-1 is "mystery":
                give player 1 chest named "&5Mystery Crate"

on place of chest:
    if player has permission "*":
        if player's tool is chest named "&5Mystery Crate":
            set {crate::mystery} to location of block
            send "{@p} You created a &5Mystery Crate&c!"
            
#                    #
#        Preview        #
#                    #

on leftclick on chest:
    cancel event
    if {crate::mystery} is location of block:
        wait 1 tick
        open virtual chest with 1 row named "&5Mystery Crate" to player
        format slot 0 of player with paper named "&e100k" with lore "&740%% chance" to be unstealable
        format slot 2 of player with paper named "&e150k" with lore "&730%% chance" to be unstealable
        format slot 4 of player with paper named "&e250k" with lore "&720%% chance" to be unstealable
        format slot 6 of player with paper named "&e500k" with lore "&79%% chance" to be unstealable
        format slot 8 of player with book named "&5Kit Mystery!" with lore "&71%% chance" to be unstealable
        
        format slot 1 of player with black stained glass pane named "&3" to be unstealable
        format slot 3 of player with black stained glass pane named "&3" to be unstealable
        format slot 5 of player with black stained glass pane named "&3" to be unstealable
        format slot 7 of player with black stained glass pane named "&3" to be unstealable
Hi guys. I got a problem with this skript, I can't open normal chests, and I can't break normal nor the crates..
 
on rightclick on chest:
cancel event
if {crate::mystery} is location of block:


on leftclick on chest:
cancel event
if {crate::mystery} is location of block:

I'm going to guess that those two rules are whats causing the issue. I am unsure what you need to make your skript work - but if you leave it in this order with no condition its going to apply to every left or right click on a chest (breaking a chest is rapid left clicking etc)

Perhaps swap those last 2 lines over, so the if statement is before cancel event. That way regular chest actions won't be cancelled.
 
I get this error after changing it
[doublepost=1620663972,1620663816][/doublepost]Nvm, just had to tab it.
Thx for the help!
 

Attachments

  • Udklip.PNG
    Udklip.PNG
    100 KB · Views: 119
Status
Not open for further replies.