On break event

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

Tom1222322

Member
Feb 5, 2021
19
0
1
22
Hey, so I'm trying to create some sort of skript to define protected areas. My problem is, how can I tell the game if a certain area is already protected from other players and cancel their breaking events? My code:
1. selecting area which I'll want to protect:
Code:
on rightclick:
    set {_restool} to stick
    set name of {_restool} to "&cRes įrankis"
    if player's held item is {_restool}:
        if clicked block is set:
            set {res.%player%.pos1} to location of event-block
            set {pos1.%player%.x} to x coord of {res.%player%.pos1}
            set {pos1.%player%.y} to y coord of {res.%player%.pos1}
            set {pos1.%player%.z} to z coord of {res.%player%.pos1}

            send "{@prefix} Taškas nustatytas: &c%{pos1.%player%.x}%&a, &c%{pos1.%player%.y}%&a, &c%{pos1.%player%.z}%&a!"
on leftclick:
    set {_restool} to stick
    set name of {_restool} to "&cRes įrankis"
    if player's held item is {_restool}:
        if clicked block is set:
            set {res.%player%.pos2} to location of event-block
            set {pos2.%player%.x} to x coord of {res.%player%.pos2}
            set {pos2.%player%.y} to y coord of {res.%player%.pos2}
            set {pos2.%player%.z} to z coord of {res.%player%.pos2}

            send "{@prefix} Taškas nustatytas: &c%{pos2.%player%.x}%&a, &c%{pos2.%player%.y}%&a, &c%{pos2.%player%.z}%&a!"
2. creating the area:
Code:
        if arg 1 is "create":
            if arg 2 is set:
                if {res.allres::*} does not contain arg-2:
                    if {res.%player%.resai::*} does not contain arg-2:
                        if {res.%player%.pos1} is set:
                            if {res.%player%.pos2} is set:
                                add arg-2 to {res.allres::*}
                                add arg-2 to {res.%player%.resai::*}
                                send "{@prefix} Rezidencija &c%arg-2%&a sukurta!"
                                set {res.%player%.pos1} to {res.%arg-2%.createdpos1}
                                set {res.%player%.pos2} to {res.%arg-2%.createdpos2}
3. on break event
Code:
on break:
    if event-location is within {res.%player%.pos1} and {res.%player%.pos2}:
        cancel event
 
I recommend use worldguard and if you want to protect the area with skript then you can do

Code:
on block break:
    set {_r} to first element of ("%region at event-block%" split at " ")

    if {_r} is "name of protected region" or "name of protected region 2" or "name of protected region 3":
        cancel event
        send "&cYou can't mine blocks here! >:("
 
Status
Not open for further replies.