Solved Tree Feller 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!

Heres a basic version of one I have.
The version I use is a bit different (uses gravity rather than just breaking the blocks like that GIF)

code_language.skript:
function chain(b: block, n: number, p: player):
    wait 1 tick
    if {_n} is less than 50:
        add 1 to {_n}
        loop blocks in radius 3 around {_b}:
            if loop-block is any log block:
                if block below loop-block is air or any leaves or any log:
                    set block below loop-block to air
                    chain(loop-block,{_n}, {_p})
                    break loop-block naturally
                    play sound "BLOCK_WOOD_BREAK" with volume 1 at location of loop-block for all players
                    wait 10 tick
                    
on break:
    if gamemode of player is survival:
        if event-block is any log block:
            set {_tree} to false
            loop blocks above event-block:
                if loop-block is any leaves:
                    set {_tree} to true
            if {_tree} is true:
                chain(event-block, 0, player)
 
Hi, I'd like to post an "upgraded" version of this script.
I know this is an old post, but Google still offers this as a search result, so lemme explain:
- this code is great as a base template, but has many issues
- it can easily break whole houses if you have the tree accidentaly touching it (house is within a 3 block radius, which can happen)
- I found the checks pretty much not very reliable and inefficient
- I added condition checks that should prevent breaking huge parts of houses (I tested it and it only had issues with jungle trees right next to the house which will not even grow like that in normal game, I had to use WE)
I know I am looping "blocks above" 2 times, but it was necesarry for the code to not have issues with acacia trees :emoji_grinning:

So here's my "upgrade" on the latest version of Skript up to this date for those who are still curious:
(note- I'm using some addons but none should interfere in this code, so it should be vanilla)
Code:
function chain(b: block, n: integer):
    wait 1 tick
    if {_n} is less than 50:
        add 1 to {_n}
        loop blocks in radius 3 around {_b}:
            if loop-block is any log:
                loop blocks above loop-block:
                    loop-block-2 is air:
                        block above loop-block-2 is air
                        exit 1 loop
                    exit 1 loop
                loop blocks above loop-block:
                    loop-block-2 is any leaves
                    chain(loop-block-1, {_n})
                    break loop-block-1
                    wait 10 tick
              
on break:
    player's gamemode is survival
    if event-block is any log:
        loop blocks above event-block:
            set {_l} to 0
            if loop-block is any leaves:
                loop all blocks in radius 2 of loop-block:
                    loop-block-2 is any leaves
                    add 1 to {_l}
                {_l} > 7
                set {_tree} to true
        if {_tree} is true:
            chain(event-block, 0)

Hope this will come in handy to people in 2023+ :emoji_slight_smile:
 
  • Love
Reactions: _PAPER_PLANE_