// Living Bomb
//
// By Ross Dubery
//
// This ability detonates a target unit after counting down. It deals damage in an area
// and explodes the targeted unit.
//
// Defaults to 5 second count down
// You need to create a buff as this ability will not create one for you...
// The buff should be .2 seconds longer then you want the count down to be if you
// want it to match, but it depends on the effect death that you use in the buff.
//
// There are two things that would require changing
// 1 - The ability, highlighted below (A001) and further below in an int
// 2 - The dummy unit, currently it is set to the Undead Gargoyle,
// if you wish to change it feel free (uloc)
//
// Check if the ability matches
//
function living_bomb_conditions takes nothing returns boolean
// Change the 'A001' to whatever your ability code is
return GetSpellAbilityId() == 'A001'
endfunction
//
// Creates the floating text
//
function create_floating_text takes unit TargetUnit, real Red, real Green, real Blue, string Text, integer Size, real Life, real Fade, boolean Rise, integer Speed, integer Angle returns texttag
//Initialise
local texttag LastText
//Create text
set LastText = CreateTextTag()
call SetTextTagText(LastText, Text, Size* 0.023 / 10)
call SetTextTagPosUnit(LastText, TargetUnit, 0)
call SetTextTagColor(LastText, PercentTo255(Red), PercentTo255(Green), PercentTo255(Blue), PercentTo255(100.0))
call SetTextTagPermanent( LastText, false )
call SetTextTagLifespan( LastText, Life )
call SetTextTagFadepoint( LastText, Fade )
//Check whether it should rise or not
if (Rise == true) then
call SetTextTagVelocity(LastText, (Speed* 0.071 / 128) * Cos(Angle * bj_DEGTORAD), TextTagSpeed2Velocity(Speed) * Sin(Angle * bj_DEGTORAD))
return LastText
else
return LastText
endif
endfunction
//
// Controls the colour, raising or lowering it as needed
//
function colour_control takes real Amount, real Colour, boolean Increase returns real
if ( Increase == true ) then
set Colour = Colour + Amount
if (Colour > 100.00) then
set Colour = 100.00
endif
else
set Colour = Colour - Amount
if (Colour < 0.00) then
set Colour = 0.00
endif
endif
return Colour
endfunction
function living_bomb_actions takes nothing returns nothing
//
// Variables
//
local integer CountMax
local integer CountMin
local integer CountCurrent
local integer CountMiddle
local integer NormalSize
local integer BoomSize
local integer NormalSpeed
local integer NormalAngle
local integer BoomSpeed
local integer BoomAngle
local real Red
local real Green
local real Blue
local real BoomLife
local real BoomFade
local real CountLife
local real CountFade
local real AOELarge
local real DamageLarge
local real AOESmall
local real DamageSmall
local real Amount
local boolean BoomRise
local boolean CountRise
local boolean ColourChange
local boolean CountBackwards
local boolean Increase
local string EffectFile
local string SoundFile
local string FailText
local string SucceedText
local unit TargetUnit
local unit DummyUnit
local sound LastSound
local texttag LastText
local effect LastEffect
local location TargetUnitPos
local location TargetLoc
local integer Ability_Code
//
// Initialise
//
//
// These variables can be adjusted
//
//The ability code
set Ability_Code = 'A001'
//Count of the ability
set CountMax = 1 // Counts for 5 CountLifes
set CountMin = 5 // What to begin counting at... if CountMin is
//bigger then CountMax will default to backwards and vice versa
//Warning, one of them must be 1 or the colourchanger will not work properly
//The following controls the floating text
set BoomLife = 3.00 // Boom lasts 3 seconds
set BoomFade = 2.00 // Boom starts fading after 2 seconds
set CountLife = 1.00 // sets the count down interval to 1 second
set CountFade = 0.50 // Makes the count down number start fading after .5 seconds
set BoomRise = true // Makes the numbers rise
set CountRise = true // Makes the final and fail boom rise
set ColourChange = true // Do this if you want the count to start green and end red
set Red = 0.00 // Modify if ColourChange is false
set Green = 100.00 // Modify if ColourChange is false
set Blue = 0.00 // Modify if ColourChange is false
set NormalSize = 10 // Size of the count text
set BoomSize = 15 // Size of the Boom text
set NormalSpeed = 64 // The speed the text will rise at
set NormalAngle = 90 // The angle the text will rise at
set BoomSpeed = 64 // The speed the Boom text will rise at
set BoomAngle = 90 // The angle the Boom text will rise at
//What the text should say
set FailText = "Boom?" // Text if the bomb fails
set SucceedText = "Boom!" // Text if the bomb explodes
//AOE of the ability
set AOELarge = 300 // This is the low damage aoe, 300 is the size of the crator made in sfx
set AOESmall = 200 // This is the high damage aoe, it will also feel the damage of the low area
//Damage of ability
set DamageLarge = (50*GetUnitAbilityLevel(GetSpellAbilityUnit(),Ability_Code)) // This is the low damage
set DamageSmall = (100*GetUnitAbilityLevel(GetSpellAbilityUnit(),Ability_Code)) // this is the high damage (low damage + high damage) so 400
//The location of the files used
set EffectFile = "Objects\\Spawnmodels\\Other\\NeutralBuildingExplosion\\NeutralBuildingExplosion.mdl"
set SoundFile = "Sound\\Interface\\BattleNetTick.wav"
//
// These variables should not be tampered with
//
set TargetUnit = GetSpellTargetUnit() // targetunit
set TargetLoc = GetUnitLoc(TargetUnit) // Location of targetunit
set Increase = true // Controls colourchange
set LastSound = CreateSound(SoundFile, false, false, false, 10, 10, "")
call SetSoundVolume(LastSound, 100)
call StartSound(LastSound)
call KillSoundWhenDone(LastSound)
call TriggerSleepAction(0.48)
set LastSound = null
//Safety features
if (CountLife < 0.27) then
set CountLife = 0.27
endif
if (CountFade < 0.27) then
set CountFade = 0.27
endif
if (BoomLife < 0.27) then
set BoomLife = 0.27
endif
if (BoomFade < 0.27) then
set BoomFade = 0.27
endif
if (NormalSize < 1) then
set NormalSize = 1
endif
if (BoomSize < 1) then
set BoomSize = 1
endif
//Decides whether to count backwards or not
if (CountMin > CountMax) then
set CountBackwards = true
set CountMiddle = CountMax + R2I((CountMin - CountMax) / 2)
else
set CountBackwards = false
set CountMiddle = CountMin + R2I((CountMax - CountMin) / 2)
endif
//Calculates amount
set Amount = (100/(CountMiddle-1))
//Create dummy unit for damage change the 'uloc' to your dummy's code if you want
// As it is set to the Stoneform gargoyle atm
set DummyUnit = CreateUnit(GetOwningPlayer(GetSpellAbilityUnit()),'uloc', GetLocationX(TargetLoc), GetLocationY(TargetLoc), bj_UNIT_FACING )
call ShowUnit( DummyUnit, false )
call SetUnitInvulnerable( DummyUnit, true )
call SetUnitUseFood( DummyUnit, false)
call RemoveLocation (TargetLoc)
set TargetLoc = null
//
// Begin Ability
//
//Enter the loop
if (CountBackwards == false) then
set CountCurrent = CountMax
else
set CountCurrent = CountMin
endif
loop
if (CountBackwards == true) then
exitwhen CountCurrent < CountMax
else
exitwhen CountCurrent > CountMax
endif
//Sort out colour stuff
if (ColourChange == true) then
if (not (CountCurrent == CountMin)) then
if (not (CountCurrent == CountMax)) then
if (Increase == true) then
set Red = colour_control (Amount, Red, Increase)
else
set Green = colour_control (Amount, Green, Increase)
endif
if (CountCurrent == CountMiddle) then
set Increase = false
endif
else
//Overides and resets the colours
if (CountBackwards) then
set Green = 0.00
set Red = 100.00
else
set Green = 100.00
set Red = 0.00
endif
set Blue = 0.00
endif
else
//Overides and resets the colours
if (CountBackwards) then
set Green = 100.00
set Red = 0.00
else
set Green = 0.00
set Red = 100.00
endif
set Blue = 0.00
endif
endif
//Create count down text after checking a unit is alive
if ( not(GetUnitState(TargetUnit, UNIT_STATE_LIFE) <= 0) ) then
//Create count down text
set LastText = create_floating_text( TargetUnit, Red, Green, Blue, I2S(CountCurrent), NormalSize, CountLife, CountFade, CountRise, NormalSpeed, NormalAngle)
set LastSound = CreateSound(SoundFile, false, false, false, 10, 10, "")
call SetSoundVolume(LastSound, 100)
call StartSound(LastSound)
call KillSoundWhenDone(LastSound)
call TriggerSleepAction(CountLife)
set LastSound = null
call DestroyTextTag(LastText)
else
//Create "Boom?" text that floats upwards and exit ability
set LastText = create_floating_text( TargetUnit, Red, Green, Blue, FailText, BoomSize, BoomLife, BoomFade, BoomRise, BoomSpeed, BoomAngle)
//Clean up
call TriggerSleepAction(BoomLife)
call DestroyTextTag(LastText)
call RemoveLocation(TargetUnitPos)
set TargetUnit = null
call RemoveUnit( DummyUnit )
set DummyUnit = null
set LastText = null
return
endif
//Determines the count
if (CountBackwards == true ) then
set CountCurrent = CountCurrent - 1
else
set CountCurrent = CountCurrent + 1
endif
endloop
//If target unit not dead continue, otherwise display "Boom?"
if ( not(GetUnitState(TargetUnit, UNIT_STATE_LIFE) <= 0) ) then
//Create text thats says "Boom!"
set LastText = create_floating_text( TargetUnit, Red, Green, Blue, SucceedText, BoomSize, BoomLife, BoomFade, BoomRise, BoomSpeed, BoomAngle)
//Create explosion effect on target unit
set TargetUnitPos = GetUnitLoc(TargetUnit)
set LastEffect = AddSpecialEffectLoc( EffectFile, TargetUnitPos )
//Damage area with low damage first, and then high damage
call UnitDamagePoint(DummyUnit, 0, AOELarge, GetLocationX(TargetUnitPos), GetLocationY(TargetUnitPos), DamageLarge, true, false, ATTACK_TYPE_PIERCE, DAMAGE_TYPE_DEMOLITION, WEAPON_TYPE_WHOKNOWS)
call UnitDamagePoint(DummyUnit, 0, AOESmall, GetLocationX(TargetUnitPos), GetLocationY(TargetUnitPos), DamageSmall, true, false, ATTACK_TYPE_PIERCE, DAMAGE_TYPE_DEMOLITION, WEAPON_TYPE_WHOKNOWS)
//Detonate target unit
call SetUnitExploded(TargetUnit, true)
call KillUnit(TargetUnit)
//Wait for explosion animation to end before cleaning up
call TriggerSleepAction( 1.60 )
//Clean up
call DestroyEffect( LastEffect )
if (BoomLife > 1.9) then
call TriggerSleepAction((BoomLife-1.6))
endif
else
//Create "Boom?" text that floats upwards and exit ability
set LastText = create_floating_text( TargetUnit, Red, Green, Blue, FailText, BoomSize, BoomLife, BoomFade, BoomRise, BoomSpeed, BoomAngle)
call TriggerSleepAction(BoomLife)
endif
//Clean up
call DestroyTextTag(LastText)
call RemoveLocation(TargetUnitPos)
set TargetUnit = null
call RemoveUnit( DummyUnit )
set DummyUnit = null
set LastText = null
set TargetUnitPos = null
endfunction
//
//
//Credits to Thanathos and gunggang777 for AntiLeakFilter
function AntiLeakFilter takes nothing returns boolean
return true
endfunction
//===========================================================================
function InitTrig_Living_Bomb takes nothing returns nothing
local trigger LiveBomb
local filterfunc filter
local integer index
set LiveBomb = CreateTrigger( )
set filter = Filter(function AntiLeakFilter)
set index = 0
loop
call TriggerRegisterPlayerUnitEvent(LiveBomb, Player(index), EVENT_PLAYER_UNIT_SPELL_EFFECT, filter)
set index = index + 1
exitwhen index == bj_MAX_PLAYER_SLOTS
endloop
call TriggerAddCondition( LiveBomb, Condition( function living_bomb_conditions ) )
call TriggerAddAction( LiveBomb, function living_bomb_actions )
call DestroyFilter(filter)
set LiveBomb = null
set filter = null
endfunction