Solved Explosions moving blocks

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

ShaneBee

Supporter +
Addon Developer
Sep 7, 2017
2,248
241
73
Vancouver, Canada
Hello team

Ok, so im working on doing a little C4 skript, where players can place c4 and detonate it remotely.
I have that part all worked out perfectly, now i want to make it so rather than a general explosion, it will throw the blocks up and out a bit.

I came across this code
code_language.skript:
on explosion:
    cancel event
    create a fake explosion at event-location
    loop exploded blocks:
        spawn falling block of loop-block at loop-block
        set loop-block to air
        push last spawned entity direction from event-location to last spawned entity with force 2

Problem is, i can't pop that into my skript, because my explosion is caused by clicking on a book (the remote trigger) and it tells me this error

"Boom Boomed Blocks can only be used in an explode event. (arrow.sk, line 66: loop exploded blocks:')"

When i write it like this: (in game i put a c4 on the ground)
code_language.skript:
on right-click holding a book:
    if name of player's tool contains "&9Detonator":
        if {explode.%player%.1} is set:
            wait 2 seconds
            create a fake explosion at {explode.%player%.1}
            loop blocks in radius 5 around {explode.%player%.1}:
                spawn falling block of loop-block at loop-block
                set loop-block to air
                push last spawned entity direction from event-location to last spawned entity with force 1

it SORT OF works, except when i detonate the c4 sitting on the ground, the ground kind of just jumps up about half a block, nothing moves, and it looks like nothing happened. I would like to see the blocks jump up a bit (maybe no more than 15 blocks high) and outwards at a decent radius (not toooo far, but a nice blast radius)

Help me if you can :emoji_slight_smile:
 
Here you go, an accurate physics explosion, because I'm bored and I haven't done help threads in awhile. It's all commented so you can understand the more complicated portions. Make sure to mark as solved if this solved your issue, Enjoy.

Functions:
code_language.skript:
# Creates an explosion where the outline of the explosion only explodes.
function fallingOutlineExplosion(location: location, radius: number, velocity: number):
    create a fake explosion at {_location}
    loop blocks in radius {_radius} around {_location}:
        # This below will check that the block is in the outline of the radius.
        # The random numbers are to make the explosion more realistic. That's optional. Larger numbers makes it less of a sphere/circle.
        if distance between loop-block and {_location} > {_radius} - random number between 1 and 3:
            # Checks if the y-coordinate of the exploded block is near a set y-coordinate. For some neat effect. Not really needed though.
            if difference between y-coordinate of loop-block and y-coordinate of {_location} < random number between 0 and 2:
                spawn falling block of loop-block at loop-block
                set loop-block to air
                # Push the block upwards so it doesn't get stuck and glitched in it's original spawn location.
                push last spawned falling block up with force 1
                # To pust the falling block at a velocity in a radius around the explosion at a explosion type direction.
                push last spawned falling block direction from {_location} to last spawned falling block with force {_velocity}


# Same as above just the whole sphere explodes. This is show in the video I provided with this.
function fallingExplosion(location: location, radius: number, velocity: number):
    create a fake explosion at {_location}
    loop blocks in radius {_radius} around {_location}:
        spawn falling block of loop-block at loop-block
        set loop-block to air
        push last spawned falling block up with force 1
        push last spawned falling block direction from {_location} to last spawned falling block with force {_velocity}

To stop the blocks from becoming blocks when they land, you will need to cancel the [on] block land event from SkQuery.

If you want to only cancel the explosion blocks, you will need to add metadata (Skellett syntax) to the falling block entities or keep track of the entities (There are multiple ways to do this in Skript aside from variables), then test when they land if that storage contains the falling block entity, and cancel event. (Metadata is like a variable database that is stored on entities, objects etc, Spigot handled)

Example:
code_language.skript:
on right-click holding a book:
    if name of player's tool contains "&9Detonator":
        fallingExplosion(location of target block, 3, 0.5)

Video (As much fun as it is):

Tags for the public's future searches: Block explosions, sphere explosions, loop explosions, TNT explosion, skquery loop exploded blocks, explode blocks, exploded, explode, explodes.
 
Last edited:
Here you go, an accurate physics explosion, because I'm bored and I haven't done help threads in awhile. It's all commented so you can understand the more complicated portions. Make sure to mark as solved if this solved your issue, Enjoy.

Functions:
code_language.skript:
# Creates an explosion where the outline of the explosion only explodes.
function fallingOutlineExplosion(location: location, radius: number, velocity: number):
    create a fake explosion at {_location}
    loop blocks in radius {_radius} around {_location}:
        # This below will check that the block is in the outline of the radius.
        # The random numbers are to make the explosion more realistic. That's optional. Larger numbers makes it less of a sphere/circle.
        if distance between loop-block and {_location} > {_radius} - random number between 1 and 3:
            # Checks if the y-coordinate of the exploded block is near a set y-coordinate. For some neat effect. Not really needed though.
            if difference between y-coordinate of loop-block and y-coordinate of {_location} < random number between 0 and 2:
                spawn falling block of loop-block at loop-block
                set loop-block to air
                # Push the block upwards so it doesn't get stuck and glitched in it's original spawn location.
                push last spawned falling block up with force 1
                # To pust the falling block at a velocity in a radius around the explosion at a explosion type direction.
                push last spawned falling block direction from {_location} to last spawned falling block with force {_velocity}


# Same as above just the whole sphere explodes. This is show in the video I provided with this.
function fallingExplosion(location: location, radius: number, velocity: number):
    create a fake explosion at {_location}
    loop blocks in radius {_radius} around {_location}:
        spawn falling block of loop-block at loop-block
        set loop-block to air
        push last spawned falling block up with force 1
        push last spawned falling block direction from {_location} to last spawned falling block with force {_velocity}

To stop the blocks from becoming blocks when they land, you will need to cancel the [on] block land event from SkQuery.

If you want to only cancel the explosion blocks, you will need to add metadata (Skellett syntax) to the falling block entities or keep track of the entities (There are multiple ways to do this in Skript aside from variables), then test when they land if that storage contains the falling block entity, and cancel event. (Metadata is like a variable database that is stored on entities, objects etc, Spigot handled)

Example:
code_language.skript:
on right-click holding a book:
    if name of player's tool contains "&9Detonator":
        fallingExplosion(location of target block, 3, 0.5)

Video (As much fun as it is):

Tags for the public's future searches: Block explosions, sphere explosions, loop explosions, TNT explosion, skquery loop exploded blocks, explode blocks, exploded, explode, explodes.

Wow Thanks, I will give it a try later on, but i will mark it as solved, I'm sure it'll do the trick!
Thanks again, i really appreciate it!
 
Status
Not open for further replies.