[EXPIRIMENTAL] Epic explosions

Discussion in 'CommandHelper Scripts' started by MCmacjuul, Jun 15, 2014.

  1. MCmacjuul

    MCmacjuul Member

    This script makes explosions look EPIC!! Some of the blocks destroyed by the explosions will fly off into the air and fall to the ground.

    NOTE 1: This changes behavoir of explosions AND falling blocks.
    NOTE 2: This script is expirimental and can contain some bugs.
    NOTE 3: This script CAN make lagg on your server, I added an option to change how much blocks get blown away and how far.

    MAIN.MS:
    PHP:

    bind(entity_explode, null, null, @e,
    if(!sk_regions_at(@e[location]) == array()) {die()}
     # The spread multiplier changes how far blocks travel. The LOWER this number the further they go! (Default: 5)
    @repel = 5
     # The height multiplier changes how high most blocks travel. The LOWER this value is the HIGHER the blocks will go! (Default: 3)
    @height = 3
     # The chance multiplier changes how many blocks will fly away. The LOWER this value is the MORE blocks get spawned. (Default: 10)
    @chance = 10
     # Spawn fire [true/false] (Default: false)
    @fire = false
    play_sound(@e[location], array(sound:EXPLODE,volume:2,pitch:0))
    play_sound(@e[location], array(sound:EXPLODE,volume:2,pitch:2))
    make_effect(@e[location], MOBSPAWNER_FLAMES)
    foreach(@e[blocks], @i,
    if(!rand(@chance + 1)) {
    make_effect(@i, 'STEP_SOUND:'.split(':',get_block_at(array(@i[x], @i[y], @i[z], @i[world])))[0])}
    if(!rand(@chance + 1)) {
    if(@fire) {
    queue_push(closure(
    spawn_falling_block(@i, 51, array(0,-10,0))
    ))
    }
    spawn_falling_block(@i,split(':',get_block_at(array(@i[x], @i[y], @i[z], @i[world])))[0],array(rand(-5, 6) / @repel,rand(0, 10) / @height,rand(-5, 6) / @repel))}
    ))

    bind('entity_change_block', null, null, @event) {
      if(entity_type(@event['entity']) == 'FALLING_BLOCK') {
        switch(@event[to]) {
        case 51: null
        default:
         make_effect(@event[location], 'STEP_SOUND:'[email protected]event[to])
         make_effect(@event[location], 'STEP_SOUND:'[email protected]event[to])
         make_effect(@event[location], 'STEP_SOUND:'[email protected]event[to])
         set_timeout(50, closure(set_block_at(@event[location], 0)))
        }
       }
      }
     
    You can change the Spread, height and chance values in the script to alter the behavoir of the explosions.
    Last edited: Aug 3, 2014
    Otium likes this.
  2. PseudoKnight

    PseudoKnight Well-Known Member Developer

    Hope you don't mind, but I have some suggestions.

    PHP:
    if(!sk_regions_at(@e[location]) == array()) {die()}
    Assuming you're detecting explosions where there aren't regions, this should be:
    PHP:
    if(!sk_regions_at(@e[location])) {die()}
    PHP:
    make_effect(array(@i[x], @i[y], @i[z], @i[world]), 'STEP_SOUND:'.split(':',get_block_at(array(@i[x], @i[y], @i[z], @i[world])))[0])}
    This can be optimized to:
    PHP:
    make_effect(@i, 'STEP_SOUND:'.split(':',get_block_at(@i))[0])}
    PHP:
    spawn_falling_block(array(@i[x], @i[y], @i[z], @i[world]),split(':',get_block_at(array(@i[x], @i[y], @i[z], @i[world])))[0],array(rand(-5, 6) / @repel,rand(0, 10) / @height,rand(-5, 6) / @repel))}
    This can be optimized to:
    PHP:
    spawn_falling_block(@i,get_block_at(@i),array(rand(-5, 6) / @repel,rand(0, 10) / @height,rand(-5, 6) / @repel))}
    PHP:
    bind('entity_change_block', null, null, @event) {
    This can be optimized to:
    PHP:
    bind('entity_change_block', null, array('from': 0), @event) {
  3. MCmacjuul

    MCmacjuul Member


    Thanks for the help, only I ont use the last suggestion becous when the blocks fall in/on blocks like tallgrass and water they don't break.
  4. RataRataData

    RataRataData Member

    I think you can just cancel entity_change_block() event so you don't need that timeout there.
  5. MCmacjuul

    MCmacjuul Member

    I tried but that causes sand and other gravity affected blocks to stay hovering in the air
  6. PseudoKnight

    PseudoKnight Well-Known Member Developer

    Hah, interesting. Cancel and then remove the entity.
  7. MCmacjuul

    MCmacjuul Member

    Example?
  8. PseudoKnight

    PseudoKnight Well-Known Member Developer

    Well, if the falling block entity is floating because it can't land, you just want to remove it.

    cancel()
    entity_remove(@event['entity'])
  9. Noahmoose

    Noahmoose Member

    Works Great!
    Thanks
  10. Jason Krause

    Jason Krause Member

    Quick question: In the spawn_falling_block command, you divide by a variable called @repel but it isn't initialized anywhere... Am I missing something here? I'm getting an error on this line: CastException: Expecting a number, but received "" instead.
  11. PseudoKnight

    PseudoKnight Well-Known Member Developer

    It looks like he changed it at one point and forgot to change the other part. It's initialized as @spread.
  12. Jason Krause

    Jason Krause Member

    Thanks PseudoKnight. That fixed it.
  13. MCmacjuul

    MCmacjuul Member


    Fixed!
  14. Jason Krause

    Jason Krause Member

    MCmacjuul, how hard would it be to set some of the blocks near the explosion on fire?
  15. MCmacjuul

    MCmacjuul Member

    I will try to add that (as optional feature)

    I think the best way to do it it is spawning falling fire at random locations in the crator (and around)
    Last edited: Aug 3, 2014
  16. MCmacjuul

    MCmacjuul Member

    Done, I added it to the code.

    The fire is disabled by default, change "@fire = false" to "@fire = true" to put it on
    The fire gets influenced by the @chance multiplier

    I also updates the falling block breaking script to allow fire to form
  17. Jason Krause

    Jason Krause Member

    Great! Thanks MCmacjuul!