Warcraft III resources & community, 2003–2006 · archived

UnitLeap

not rated
Submitted by AltSubmitterFunctions0 downloads
UnitLeap creates the effect of a unit leaping from its current location to a target location. It takes three parameters. First, the unit that you would like to leap. Second, the unittype you would like to serve as the model for the jumping unit -- if you want the unit just to appear as it normally does, you should still create a new unittype. The new unittype should be a flying unit with a minimum movement speed of 1 (otherwise changes in flying height don't work), and the Locust ability, so that the player doesn't try to move it midleap. Third, you pass the target location.

You can customize the function pretty easily by changing the first 3 lines of the UnitLeap function. This way you can change the damage when the unit falls, the radius of the damage, and the special effect used. You can also adjust moveIncrement and heightIncrement to smaller values for a smoother looking but slower jump.

I recommend using this as a START for your own code. Note that there is no included code for rewarding experience or gold for kills. I have added a comment where one would need to insert this code. Also, you could add more parameters for better control of the camera, and a terrain deformation crater on landing =)

Source

//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

Comments

0

No comments.