Block Chains

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

evawwolf

Member
Dec 16, 2020
3
0
1
23
to explain, what i'm trying to do is break a block, and any block of the same block as that block break around it. for example, if you broke tnt, any tnt around it breaks instantly. any direction, and it must be connected. kind of like scaffolding, but no matter where you break it, it all breaks.
 
Here's your code:
Code:
options:
    debug: true
    limit: 5
    delay: 1

function breakBlockRecursive(b: location, t: string, i: number = 0):
    if {_i} is greater than {@limit}:
        if {@debug}:
            broadcast "recursion limit exceeded"
        stop
    if "%type of block at {_b}%" is not {_t}:
        stop
    add 1 to {_i}

    set block at {_b} to air

    if {@delay} is greater than 0:
        wait {@delay} ticks

    breakBlockRecursive(block north {_b}, {_t}, {_i})
    breakBlockRecursive(block south {_b}, {_t}, {_i})
    breakBlockRecursive(block east {_b}, {_t}, {_i})
    breakBlockRecursive(block west {_b}, {_t}, {_i})
    breakBlockRecursive(block above {_b}, {_t}, {_i})
    breakBlockRecursive(block under {_b}, {_t}, {_i})

#Change this to your event handler:
on break of stone:
    breakBlockRecursive(location of event-block, "%type of event-block%")

Since this might be really destructive, there is limit set (you can change it in `options` at the top of code). There is also `delay` option in case you want to visually see breaking blocks one by one (to turn this feature off set value to `0`) and `debug` option (this option should be set to `false` in production environment).
 
  • Like
Reactions: evawwolf
lol. I was confused with the title. I thought you meant like the blockchain. or blockchain.com xd
 
Here's your code:
Code:
options:
    debug: true
    limit: 5
    delay: 1

function breakBlockRecursive(b: location, t: string, i: number = 0):
    if {_i} is greater than {@limit}:
        if {@debug}:
            broadcast "recursion limit exceeded"
        stop
    if "%type of block at {_b}%" is not {_t}:
        stop
    add 1 to {_i}

    set block at {_b} to air

    if {@delay} is greater than 0:
        wait {@delay} ticks

    breakBlockRecursive(block north {_b}, {_t}, {_i})
    breakBlockRecursive(block south {_b}, {_t}, {_i})
    breakBlockRecursive(block east {_b}, {_t}, {_i})
    breakBlockRecursive(block west {_b}, {_t}, {_i})
    breakBlockRecursive(block above {_b}, {_t}, {_i})
    breakBlockRecursive(block under {_b}, {_t}, {_i})

#Change this to your event handler:
on break of stone:
    breakBlockRecursive(location of event-block, "%type of event-block%")

Since this might be really destructive, there is limit set (you can change it in `options` at the top of code). There is also `delay` option in case you want to visually see breaking blocks one by one (to turn this feature off set value to `0`) and `debug` option (this option should be set to `false` in production environment).
thank you!!
 
Status
Not open for further replies.