Explode on Contact (Barrel)

I’m looking for a script that will handle the explosion of a barrel on contact. My script is working to a point. The audio of a flame VFX and fireball play on contact, but the visual animation is absent.
My suspicion is that the barrel is being destroyed before any of the animations can play…

Script so far:

void main()
{
    effect eVFX;

    object oSelf = OBJECT_SELF;
    object oPC = GetLastDamager();

    int nInt = GetTotalDamageDealt();
    if ( nInt >= 1 )
    {

    // Apply a visual effect.
    eVFX = EffectVisualEffect(VFX_FNF_FIREBALL);
    ApplyEffectToObject(DURATION_TYPE_INSTANT, eVFX, oSelf);

    // Apply a visual effect.
    eVFX = EffectVisualEffect(VFX_IMP_FLAME_M);
    DelayCommand(1.0, ApplyEffectToObject(DURATION_TYPE_INSTANT, eVFX, oSelf));

    }
}
Thanks guys.

placeables don’t have OnDamaged event

you need to apply the VFX in the script that handles the explosion

placeables don’t have OnDamaged event

huh?

If it’s destroyed effects will go with it I guess (not sure about the imp/fnf types which these are). ApplyEffectAtLocation(similar stuff) with the location being GetLocation(oSelf) is probably worth a shot.

Yeah, I thought about that. Only thing is - I have about 30 barrels and 30 different locations. :frowning:

my bad

eitherway my suggestion holds, the visuals needs to be applied in the script that causing the damage

I should mention - I’ve only been testing attacking using a bow and arrow. Upon arrow impact all of the sounds fire, just not the animations as previously stated.
Just thought I’d update just in case the attack type was relevant to the success or failure of the code.
Or more accurately the weapon type -

Try to apply the effect at the location of the placeable instead might work?

ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eVFX, GetLocation(oSelf));

I could have sworn that I tried that before and failed, but sure enough - works like a charm… :slight_smile:

void main()
{
    effect eVFX;

    object oSelf = OBJECT_SELF;
    object oPC = GetLastDamager();

    int nInt = GetTotalDamageDealt();
    if ( nInt >= 1 )
    {
    // Apply a visual effect.
    eVFX = EffectVisualEffect(VFX_FNF_FIREBALL);
    ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eVFX, GetLocation(oSelf));

    // Apply a visual effect.
    eVFX = EffectVisualEffect(VFX_IMP_FLAME_M);
    DelayCommand(1.0, ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eVFX, GetLocation(oSelf)));
    }
}

1 Like