//Makes sure you only hurt enemy units
//Can be removed if you don't want it to damage (be sure to remove other damage lines too though)
function LeapDamageCheck takes nothing returns boolean
if ( not ( IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(bj_makeUnitRescuableUnit)) == true ) ) then
return false
endif
if ( not ( IsUnitAliveBJ(GetFilterUnit()) == true ) ) then
return false
endif
return true
endfunction
//Can be removed if you don't want it to damage (be sure to remove other damage lines too though)
function LeapHurtUnits takes nothing returns nothing
//Need to insert code to reward xp, bounty, etc. here
call SetUnitLifeBJ( GetEnumUnit(), ( GetUnitStateSwap(UNIT_STATE_LIFE, GetEnumUnit()) - bj_meleeNearestMineDist ))
endfunction
//NOTE: Some stuff is stored in variables rather than being recalculated
//to help the loop run faster, like halfdistance
function UnitLeap takes unit whichUnit, integer fakeType, location targetLocation returns nothing
local real damage = 10 //Each time unit goes higher, times this is damage that will be done
local real damageRadius = 400 //Adjust this to change radius over which damage is done
local string landingEffect = "Abilities\\Spells\\Orc\\WarStomp\\WarStompwhichUnit.mdl" //Change this to the effect you want for when the leaping unit lands
local player leapingPlayer = GetOwningPlayer(whichUnit)
local location whichUnitLoc = GetUnitLoc(whichUnit)
local real halfdistance = DistanceBetweenPoints(whichUnitLoc, targetLocation) / 2
local real moveIncrement = 100
local real heightIncrement = 100
local real damagecount = 0
local group damageGroup = null
local real currentHeight = 0
local location polartemp = null
local unit fake = CreateUnitAtLoc( leapingPlayer, fakeType, whichUnitLoc, GetUnitFacing(whichUnit) )
local location fakeLoc = GetUnitLoc(fake)
//Hide real whichUnit
call SetUnitPathing( whichUnit, false )
call ShowUnitHide( whichUnit )
//Start moving the fake version of whichUnit
loop
exitwhen DistanceBetweenPoints(fakeLoc, targetLocation) <= 50
set polartemp = PolarProjectionBJ(fakeLoc, moveIncrement, AngleBetweenPoints(fakeLoc, targetLocation))
call SetUnitPositionLoc( fake, polartemp )
//Control arc of the leap
if( DistanceBetweenPoints(fakeLoc, targetLocation) > halfdistance ) then
set currentHeight = currentHeight + heightIncrement
set damagecount = damagecount + 1
else
set currentHeight = currentHeight - heightIncrement
endif
call SetUnitFlyHeightBJ( fake, ( currentHeight ), 999999 )
//Control camera during leap
call SetCameraFieldForPlayer( leapingPlayer, CAMERA_FIELD_TARGET_DISTANCE, 1850.00 + currentHeight, 1 )
call PanCameraToTimedLocForPlayer( leapingPlayer, fakeLoc, 1 )
call SetCameraFieldForPlayer( leapingPlayer, CAMERA_FIELD_ANGLE_OF_ATTACK, 270.00, 1.00 )
call TriggerSleepAction(0)
call RemoveLocation(fakeLoc)
set fakeLoc = GetUnitLoc(fake)
call RemoveLocation(polartemp)
endloop
call RemoveUnit( fake )
//Bring real guy back
call SetCameraFieldForPlayer( leapingPlayer, CAMERA_FIELD_TARGET_DISTANCE, 1650, 1 )
call SetCameraFieldForPlayer( leapingPlayer, CAMERA_FIELD_ANGLE_OF_ATTACK, 304, 1.00 )
call SetUnitPathing( whichUnit, true )
call SetUnitPositionLoc( whichUnit, targetLocation )
call ShowUnitShow( whichUnit )
//Remove these lines if you don't want the leap to do AOE damage when the unit falls
call AddSpecialEffectLocWithTimer( targetLocation, landingEffect, 3.0 )
set bj_makeUnitRescuableUnit = whichUnit
set damageGroup = GetUnitsInRangeOfLocMatching(damageRadius, targetLocation, Condition(function LeapDamageCheck))
set bj_wantDestroyGroup = true
set bj_meleeNearestMineDist = damage * damagecount
call ForGroupBJ(damageGroup, function LeapHurtUnits)
//Reselect whichUnit for player
call SelectUnitForPlayerSingle( whichUnit, leapingPlayer )
call RemoveLocation(whichUnitLoc)
call RemoveLocation(targetLocation)
call RemoveLocation(fakeLoc)
call DestroyGroup(damageGroup)
endfunction