Solved if event block is in list

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

    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.

fireyburst

Member
Apr 22, 2022
4
0
1
Hello, I am trying to make a script that whitelists specific blocks to be breakable. Since the blocks are all in one list I want it to check it from there. There are optimizations on the way but for now I'm just trying to figure out how. Could anyone help?

Here's my script if that helps:
Code:
on skript load:
    set {whitelist.blocks::*} to gray glazed terracotta, white glazed terracotta, yellow glazed terracotta, blue glazed terracotta, green glazed terracotta, light blue glazed terracotta, black glazed terracotta

on block break:
    if event-block is in region "gens":
        if event-block isn't an element out of {whitelist.blocks::*}:
            if player doesn't have permission "builder.bypass":
                cancel event
                message "&c&lHey!&r &7Sorry, but you can't break that block here."
        else:
            cancel event
            set event-block to air
            player's gamemode is survival
            if event-block is gray glazed terracotta:
                drop 1 gray glazed terracotta named "&8Coal generator" at event-block's location
            if event-block is white glazed terracotta:
                drop 1 white glazed terracotta named "&fIron generator" at event-block's location
            if event-block is yellow glazed terracotta:
                drop 1 yellow glazed terracotta named "&6Gold Generator" at  event-block's location
            if event-block is blue glazed terracotta:
                drop 1 blue glazed terracotta named "&9Lapis Lazuli Generator" at event-block's location
            if event-block is green glazed terracotta:
                drop 1 green glazed terracotta named "&aEmerald Generator" at event-block's location
            if event-block is light blue glazed terracotta:
                drop 1 light blue glazed terracotta named "&bDiamond Generator" at event-block's location
            if event-block is black glazed terracotta:
                drop 1 black glazed terracotta named "&8&lNetherite Generator" at event-block's location
[CODE]
[doublepost=1651170736,1651165506][/doublepost]Oh and I forgot to add, my addons are:

skript-gui
Skellett
skRayFall
SkQuery
Ticker
 
On skript load will run when skript starts not when your script loads. If you want to run the code when the script loads use on script load. You should add a 'variables' section to your script instead of defining variables every time a script loads.

Code:
variables:
    {whitelist::blocks::*} = gray glazed terracotta, white glazed terracotta, yellow glazed terracotta, blue glazed terracotta, green glazed terracotta, light blue glazed terracotta, black glazed terracotta

Regions are in this form: regionName in world worldName. So to check if the block is in the region "gens" in the world "world" do this:

Code:
"%region at event-block%" is "gens in world world"

The expression element of wouldn't work on this occasion. It gives the first, the last, or a random element. Use the contains condition like this.

Code:
{whitelist::blocks::*} doesn't contain event-block

Here's the full code

Code:
variables:
    {whitelist::blocks::*} = gray glazed terracotta, white glazed terracotta, yellow glazed terracotta, blue glazed terracotta, green glazed terracotta, light blue glazed terracotta, black glazed terracotta
 
on block break:
    "%region at event-block%" is "gens in world world"
    if {whitelist::blocks::*} doesn't contain event-block:
        player doesn't have permission "builder.bypass"
        cancel event
        message "&c&lHey!&r &7Sorry, but you can't break that block here."
    else:
        cancel event
        set event-block to air
        player's gamemode is survival
        if event-block is gray glazed terracotta:
            drop 1 gray glazed terracotta named "&8Coal generator" at event-block's location
        if event-block is white glazed terracotta:
            drop 1 white glazed terracotta named "&fIron generator" at event-block's location
        if event-block is yellow glazed terracotta:
            drop 1 yellow glazed terracotta named "&6Gold Generator" at  event-block's location
        if event-block is blue glazed terracotta:
            drop 1 blue glazed terracotta named "&9Lapis Lazuli Generator" at event-block's location
        if event-block is green glazed terracotta:
            drop 1 green glazed terracotta named "&aEmerald Generator" at event-block's location
        if event-block is light blue glazed terracotta:
            drop 1 light blue glazed terracotta named "&bDiamond Generator" at event-block's location
        if event-block is black glazed terracotta:
            drop 1 black glazed terracotta named "&8&lNetherite Generator" at event-block's location
 
Status
Not open for further replies.