• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

Climb Tree Spell

Status
Not open for further replies.
Level 4
Joined
Sep 15, 2013
Messages
53
Im trying to make a dota 2 like spell of mk which is called tree dance. I based the spell to the sentinel spell. It works when i jump from the ground to a tree but whenever im on a tree and jumps to another one, the jump still starts from the ground when it should be from the tree. Can somebody help me? Here is the code:
JASS:
function TD takes unit mk, real range, real angle returns nothing
    set udg_tdcaster = mk
    set udg_tdrange = range
    set udg_tddistanceTravelled = 0.00
    set udg_tdangle = angle 
endfunction

function unperch takes nothing returns boolean
    if (GetIssuedOrderId() == OrderId("smart") or GetIssuedOrderId() == OrderId("attack") or GetIssuedOrderId() == OrderId("patrol") ) then
        call SetUnitFlyHeight(GetOrderedUnit(), 0, 0)
        call SetUnitPathing(GetOrderedUnit(), true)
        set udg_TreeDance_isPerched[GetUnitUserData(GetOrderedUnit())] = false
        call DisableTrigger(GetTriggeringTrigger())
        return true
    endif
    return false
endfunction

function ParabolaZ takes real h, real d, real x returns real
    return (4 * h / d) * (d - x) * (x / d)
endfunction

function periodic takes nothing returns nothing
    local timer t=GetExpiredTimer()
    local real casterX = GetUnitX(udg_tdcaster)
    local real casterY = GetUnitY(udg_tdcaster)
    local real dx = casterX + 7.50 * Cos(udg_tdangle * bj_DEGTORAD)
    local real dy = casterY + 7.50 * Sin(udg_tdangle * bj_DEGTORAD)
    local real bonusHeight = 0.00
    call SetUnitX(udg_tdcaster, dx)
    call SetUnitY(udg_tdcaster, dy)
    set udg_tddistanceTravelled = udg_tddistanceTravelled + 7.5
    if (udg_tddistanceTravelled >= udg_tdrange / 2 and GetUnitFlyHeight(udg_tdcaster) <= 300) then
        call PauseTimer(t)
        call DestroyTimer(t)
        set udg_TreeDance_isUnPerched = CreateTrigger()
        call TriggerRegisterUnitEvent(udg_TreeDance_isUnPerched, udg_tdcaster, EVENT_UNIT_ISSUED_POINT_ORDER)
        call TriggerRegisterUnitEvent(udg_TreeDance_isUnPerched, udg_tdcaster, EVENT_UNIT_ISSUED_TARGET_ORDER)
        call TriggerAddCondition(udg_TreeDance_isUnPerched, Condition(function unperch))
        set udg_TreeDance_isPerched[GetUnitUserData(udg_tdcaster)] = true
    else
        if udg_TreeDance_isPerched[GetUnitUserData(udg_tdcaster)] == false then
            set bonusHeight = 300.00
        endif
        call SetUnitFlyHeight(udg_tdcaster, ParabolaZ(400,udg_tdrange,udg_tddistanceTravelled) + bonusHeight, 0.00)
    endif
endfunction

function Trig_Climb_Tree_Actions takes nothing returns nothing
    local real angle = AngleBetweenPoints(GetUnitLoc(GetTriggerUnit()), GetDestructableLoc(GetSpellTargetDestructable()))
    local real dist = DistanceBetweenPoints(GetUnitLoc(GetTriggerUnit()), GetDestructableLoc(GetSpellTargetDestructable()))
    local real bonusDist = dist * 300/1000
    local timer t
    local real x = GetSpellTargetX()
    local real y = GetSpellTargetY()
    if GetSpellAbilityId() == 'A000' then
        if udg_TreeDance_isPerched[GetUnitUserData(GetTriggerUnit())] == false then
            set bonusDist = 0.00
        endif
        call TD(GetTriggerUnit(), dist + bonusDist, angle)
        if (UnitAddAbility(udg_tdcaster, 'Amrf')) then
            call UnitRemoveAbility(udg_tdcaster, 'Amrf')
        endif
        set t = CreateTimer()
        call SetUnitPathing(udg_tdcaster, false)
        call TimerStart(t, 0.01, true, function periodic)
        set bj_lastCreatedUnit = CreateUnit(GetTriggerPlayer(), 'h000', x, y, bj_UNIT_FACING)
        call UnitApplyTimedLife(bj_lastCreatedUnit, 'BTLF', 0.5)
        call UnitAddAbility(bj_lastCreatedUnit, 'Adcn')
        call IssuePointOrderById(bj_lastCreatedUnit, 852057, x, y)
    endif
endfunction

//===========================================================================
function InitTrig_Climb_Tree takes nothing returns nothing
    local trigger gg_trg_Climb_Tree = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Climb_Tree, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddAction(gg_trg_Climb_Tree, function Trig_Climb_Tree_Actions)
endfunction
 
Last edited:
Level 4
Joined
Sep 15, 2013
Messages
53
It supposed to simply work like a jump spell but only the target point is atop a tree. When atop a tree, you can cast it to jump from a tree to another. Also when atop a tree and was ordered to move, you will fall from the tree. Basically just that..
From that code, the jump from the ground to a tree works. Well, the tree to tree also works but when it jumps, it still starts from the ground when it should start from the tree. Thats the problem.
 
Last edited:
Level 10
Joined
Oct 5, 2008
Messages
355
In both function periodic and Trig_Climb_Tree_Actions, change :

if udg_TreeDance_isPerched[GetUnitUserData(udg_tdcaster)] == false

to:

if udg_TreeDance_isPerched[GetUnitUserData(udg_tdcaster)] == true


Now i'm curious: When the unit jumped from the ground, did it really start from the ground or did it start from a high of 300? Because you have your high adjustments for the tree to tree jump running when the unit is on the ground and the opposite when it is sitting on a tree.

Above that, i have a little nitpick:

You don't destroy udg_TreeDance_isUnPerched after it fires. So it will leak a disabled trigger whenever you dismount the tree.
 
Level 4
Joined
Sep 15, 2013
Messages
53
In both function periodic and Trig_Climb_Tree_Actions, change :

if udg_TreeDance_isPerched[GetUnitUserData(udg_tdcaster)] == false

to:

if udg_TreeDance_isPerched[GetUnitUserData(udg_tdcaster)] == true


Now i'm curious: When the unit jumped from the ground, did it really start from the ground or did it start from a high of 300? Because you have your high adjustments for the tree to tree jump running when the unit is on the ground and the opposite when it is sitting on a tree.

Above that, i have a little nitpick:

You don't destroy udg_TreeDance_isUnPerched after it fires. So it will leak a disabled trigger whenever you dismount the tree.

When jumping from the ground, it starts from the ground. The same when it jumps from the tree..

---

Now it works! Thank you!
 
Last edited:
Status
Not open for further replies.
Top