• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Jump Spell Help

Status
Not open for further replies.
Level 11
Joined
Sep 14, 2009
Messages
284
Hi. I need help to fix a problem with this spell called Crushing Strike. A blademaster jumping spell that targets a unit and then jumps to the unit and damages him.
The problem is that when he lands the timer trigger doesn't stop and he never deals the damage.
The spell does not need to be MUI.

Any ideas how the code can be improved is also welcome.


EDIT

First problem is solved. But now I have another problem after improving the code and experimenting with natives.
Basically at the end of a blademaster jump spell, some of the code below a certain line is not executed. Here is the part of the code:


JASS:
function CrushingStrike_Dmg takes nothing returns nothing
    local effect e
    local real r
    call DisplayTextToPlayer(Player(8), 0, 0, "DmgSTART")
    call UnitRemoveAbility(udg_CrushingStrikeCaster, 'Avul')
    call UnitRemoveAbility(udg_CrushingStrikeCaster, 'A000')
    call SetUnitFlyHeight(udg_CrushingStrikeCaster, 0.00, 0.00)
    call SetUnitPathing(udg_CrushingStrikeCaster, true)
    call DestroyEffect(udg_CrushingStrikeSFX)
    set e = AddSpecialEffectTarget("MDX\\Effect_CrushingStrikeTarget.mdx", udg_CrushingStrikeTarget, "chest")
    call DestroyEffect(e)
    set r = (10.00 * (I2R(GetUnitAbilityLevel(udg_CrushingStrikeCaster, 'A00Q'))) + 40.00) + (1.20 * GetBonusAtkDmg(udg_CrushingStrikeCaster))
    //Everything below is ignored/not executed

My guess is that something within the function "GetBonusAtkDmg" is the problem, so I will post that function below and hope someone can see what the problem is.

JASS:
function GetBonusAtkDmg takes unit u returns real
    local integer i = 1
    local integer itemId
    local real r
    loop
        exitwhen i > 6
        set itemId = GetItemTypeId(UnitItemInSlot(u, i - 1))
        if itemId == 'I00A' then
            set r = r + 3.00
        endif
        set i = i + 1
    endloop
    if GetUnitAbilityLevel(u, 'B00A') >= 1 then
        set r = r + 13 + (2 * (GetUnitAbilityLevel(udg_LionsRoarCaster, 'A01X')))
    endif
    return r
endfunction

EDIT: Solved. New problem on post #5. Please help ^^.
 
Last edited:
Level 12
Joined
Feb 22, 2010
Messages
1,115
I am loking from phone but one thing O noticed is you are checking if distance less than 5, it is too small use 50 instead
 
Level 11
Joined
Sep 14, 2009
Messages
284
Thank you IcemanBo, this solved the problem. However, I further improved the code by only using coordinates instead of locations ad have run into yet another problem.

The "Move" function does for some reason not move the casting unit, if anyone can see why, great appreciation ^^.

JASS:
globals
    effect CrushStrikeSFX = null
    real CrushStrikeDist = 0.00
    real CrushStrikeFlyHeight = 0.00
    timer CrushStrikeTimer = null
    unit CrushStrikeCast = null
    unit CrushStrikeTarg = null
endglobals

function CrushingStrike_Dmg takes nothing returns nothing
    local real r = (10.00 * (I2R(GetUnitAbilityLevel(CrushStrikeCast, 'A00Q'))) + 40.00) + (1.20 * GetBonusAtkDmg(CrushStrikeCast))
    call DestroyEffect(AddSpecialEffectTarget("MDX\\Effect_CrushingStrikeHit.mdx", CrushStrikeTarg, "chest"))
    call UnitRemoveAbility(CrushStrikeCast, 'Avul')
    call UnitRemoveAbility(CrushStrikeCast, 'A000')
    call SetUnitFlyHeight(CrushStrikeCast, 0.00, 0.00)
    call SetUnitPathing(CrushStrikeCast, true)
    call DestroyEffect(CrushStrikeSFX)
    if GetRandomInt(1, 100) <= GetHeroInt(CrushStrikeCast, true) then
        call UnitAddAbility(CrushStrikeCast, 'A001')
        if GetUnitAbilityLevel(CrushStrikeCast, 'A00K') >= 1 then
            call UnitDamageTarget(CrushStrikeCast, CrushStrikeTarg, r * (2.10 + (0.30 * I2R(GetUnitAbilityLevel(CrushStrikeCast, 'A00K')))), true, false, ATTACK_TYPE_MELEE, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
        else
            call UnitDamageTarget(CrushStrikeCast, CrushStrikeTarg, r * 2.00, true, false, ATTACK_TYPE_MELEE, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
        call UnitRemoveAbility(CrushStrikeCast, 'A001')
        endif
        if GetUnitAbilityLevel(CrushStrikeCast, 'A016') >= 1 then
            call TigersRage(CrushStrikeCast)
        endif
    else
        set udg_AbilityPhysical = true
        call UnitDamageTarget(CrushStrikeCast, CrushStrikeTarg, r, true, false, ATTACK_TYPE_MELEE, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
        set udg_AbilityPhysical = false
    endif
    set udg_CombatActive = udg_CombatActive - 1
endfunction

function CrushingStrike_Move takes nothing returns nothing
    local real castAX = GetUnitX(CrushStrikeCast)
    local real castAY = GetUnitY(CrushStrikeCast)
    local real targX = GetUnitX(CrushStrikeTarg)
    local real targY = GetUnitY(CrushStrikeTarg)
    local real targPX = PolarProjectionX(targX, 100.00, bj_RADTODEG * Atan2(castAY - targY, castAX - targX))
    local real targPY = PolarProjectionY(targY, 100.00, bj_RADTODEG * Atan2(castAY - targY, castAX - targX))
    local real castBX = PolarProjectionX(castAX, 18.00, bj_RADTODEG * Atan2(targPY - castAY, targPX - castAX))
    local real castBY = PolarProjectionY(castAY, 18.00, bj_RADTODEG * Atan2(targPY - castAY, targPX - castAX))
    local real r = 0.00
    call SetUnitPosition(CrushStrikeCast, castBX, castBY)
    call SetUnitFacing(CrushStrikeCast, bj_RADTODEG * Atan2(targY - castBY, targX - castBX))
    set r = SquareRoot(((targPX - castAX) * (targPX - castAX)) + ((targPY - castAY) * (targPY - castAY)))
    if r <= CrushStrikeDist * 0.5 then
        set CrushStrikeFlyHeight = (CrushStrikeFlyHeight - 15.00)
    else
        set CrushStrikeFlyHeight = (CrushStrikeFlyHeight + 15.00)
    endif
    call SetUnitFlyHeight(CrushStrikeCast, CrushStrikeFlyHeight, 0.00)
    if r <= 40.00 then
        call PauseTimer(CrushStrikeTimer)
        call CrushingStrike_Dmg()
    endif
endfunction

function CrushingStrike_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A00Q'
endfunction

function CrushingStrike_Cast takes nothing returns nothing
    local real castX = 0.00
    local real castY = 0.00
    local real targX = 0.00
    local real targY = 0.00
    set udg_CombatActive = udg_CombatActive + 1
    set CrushStrikeCast = GetTriggerUnit()
    set CrushStrikeTarg = GetSpellTargetUnit()
    set castX = GetUnitX(CrushStrikeCast)
    set castY = GetUnitY(CrushStrikeCast)
    set targX = GetUnitX(CrushStrikeTarg)
    set targY = GetUnitY(CrushStrikeTarg)
    set CrushStrikeDist = SquareRoot(((targX - castX) * (targX - castX)) + ((targY - castY) * (targY - castY)))
    set CrushStrikeFlyHeight = 0.00
    call UnitAddAbility(CrushStrikeCast, 'Amrf')
    call UnitRemoveAbility(CrushStrikeCast, 'Amrf')
    call SetUnitPathing(CrushStrikeCast, false)
    set CrushStrikeSFX = AddSpecialEffectTarget("MDX\\Effect_CrushingStrike.mdx", CrushStrikeCast, "weapon")
    call SetUnitAnimation(CrushStrikeCast, "attack slam")
    call UnitAddAbility(CrushStrikeCast, 'Avul')
    call UnitAddAbility(CrushStrikeCast, 'A000')
    call TimerStart(CrushStrikeTimer, 0.03, true, function CrushingStrike_Move)
endfunction

//===========================================================================
function InitTrig_CrushingStrike takes nothing returns nothing
    set gg_trg_CrushingStrike = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_CrushingStrike, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(gg_trg_CrushingStrike, Condition(function CrushingStrike_Conditions))
    call TriggerAddAction(gg_trg_CrushingStrike, function CrushingStrike_Cast)
endfunction
 
Level 11
Joined
Sep 14, 2009
Messages
284
Make a BJDebugMsg to print out "r" in CrushingStrike_Move. Perhaps the spell is ending quickly, so it seems like the unit isn't being moved.

Otherwise, be sure that the coordinates are being calculated properly for castBX/castBY.

It's neither of those cases. The move function is not run at all. When i used the timer variable from the variable editor. Then it worked, thus, could it be the it's set to null? Should i set it to "CreateTimer()" or smth instead?

EDIT: Yes, this was the case. The Spell now works flawlessly. Thanks everyone.
 
Last edited:
Status
Not open for further replies.
Top