• 🏆 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!

[Spell] Jump Jass Unit Group

Status
Not open for further replies.
Level 5
Joined
Sep 16, 2008
Messages
47
Co my problem is that there is no damage to unit in group, also loop function does not end, When i remove everything about that unit group loop function ends and everything works but i need to caster damage units in Damage_Range.

How to fix it?

If you see anything wrong just tell me

JASS:
constant function SpellID takes nothing returns integer
    return 'A000'
endfunction

constant function MaxHeight takes nothing returns real
    return 350.00
endfunction

constant function FPS takes nothing returns real
    return 0.03125
endfunction

constant function Damage takes nothing returns real
    return 200
endfunction

constant function Damage_Range takes nothing returns real
    return 200
endfunction
           

function ParabolicMovement takes real h, real d, real x returns real
    local real a = -4*h/(d*d)
    local real b = 4*h/d
    return a*x*x + b*x
endfunction 

function GetDistance takes real x, real y, real xt, real yt returns real
    return SquareRoot((xt - x) * (xt - x) + (yt - y) * (yt - y))
endfunction

function GetAngles takes real ax2, real ax, real ay2, real ay returns real
    return bj_RADTODEG*Atan2(ay2 - ay, ax2 - ax)
endfunction

function IsUnitAlive takes unit id returns boolean
    return not IsUnitType(id, UNIT_TYPE_DEAD) and GetUnitTypeId(id) != 0
endfunction

function Loop takes nothing returns nothing
    local       timer       t           =       GetExpiredTimer()
    local       integer     id          =       GetHandleId(t)
    local       unit        caster      =       LoadUnitHandle(udg_HL_Table, id, 0)
    local       real        speed       =       LoadReal(udg_HL_Table, id, 1)
    local       real        distance    =       LoadReal(udg_HL_Table, id, 2)
    local       real        angle       =       LoadReal(udg_HL_Table, id, 3)
    local       real        Cdistance   =       LoadReal(udg_HL_Table, id, 4)
    local       real        damage      =       LoadReal(udg_HL_Table, id, 5)
    local       real        x           =       GetLocationX(GetUnitLoc(caster)) + speed * Cos(angle* bj_DEGTORAD)
    local       real        y           =       GetLocationY(GetUnitLoc(caster)) + speed * Sin(angle* bj_DEGTORAD)
    local       real        Height
    local       group       g
    local       unit        u
        if Cdistance < distance then
            call SetUnitX(caster, x)
            call SetUnitY(caster, y)
            call SaveReal(udg_HL_Table, id, 4, Cdistance + speed)
            set Height =  ParabolicMovement(MaxHeight(), distance, Cdistance)
            call SetUnitFlyHeight(caster, Height, 0)
        else
            set g = GetUnitsInRangeOfLocAll(Damage_Range(), GetUnitLoc(caster))
            loop
                exitwhen u == null
                set u = FirstOfGroup(g)
                if IsUnitEnemy(u, GetOwningPlayer(caster)) == true then
                call UnitDamageTarget(caster, u, damage, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_CLAW_MEDIUM_SLICE) 
                call GroupRemoveUnit(g, u)
                endif
            endloop
            call DestroyGroup(g)
            call UnitRemoveAbility(caster, 'A001')
            call PauseUnit(caster, false)
            call FlushChildHashtable(udg_HL_Table, id)
            call DestroyTimer(t)
        endif
    set caster = null
    set t = null
endfunction

function Actions takes nothing returns nothing
    local       unit        caster      =       GetTriggerUnit()
    local       real        distance    =       GetDistance(GetLocationX(GetUnitLoc(caster)), GetLocationY(GetUnitLoc(caster)), GetLocationX(GetSpellTargetLoc()), GetLocationY(GetSpellTargetLoc()))
    local       real        cx          =       GetUnitX(caster)
    local       real        cy          =       GetUnitY(caster)
    local       real        tx          =       GetLocationX(GetSpellTargetLoc())
    local       real        ty          =       GetLocationY(GetSpellTargetLoc())
    local       real        angle       =       GetAngles(tx, cx, ty, cy)
    local       real        speed       =       distance / 50
    local       real        damage      =       GetUnitAbilityLevel(caster, SpellID()) * Damage()
    local       real        Cdistance   =       0.00
    local       timer       t           =       CreateTimer()
    local       integer     id          =       GetHandleId(t)
    
    call UnitAddAbility(caster, 'A001')
    call PauseUnit(caster, true)
    
    call SaveUnitHandle(udg_HL_Table, id, 0, caster)
    call SaveReal(udg_HL_Table, id, 1, speed)
    call SaveReal(udg_HL_Table, id, 2, distance)
    call SaveReal(udg_HL_Table, id, 3, angle)  
    call SaveReal(udg_HL_Table, id, 4, Cdistance)  
    call SaveReal(udg_HL_Table, id, 5, damage)   
    
    call TimerStart(t, FPS(), true, function Loop)
    
    set caster = null
    set t = null
endfunction

function Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == SpellID() ) ) then
        return false
    endif
    return true
endfunction

//===========================================================================
function InitTrig_Heroic_Leap_Cast takes nothing returns nothing
    set gg_trg_Heroic_Leap_Cast = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Heroic_Leap_Cast, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Heroic_Leap_Cast, Condition( function Conditions ) )
    call TriggerAddAction( gg_trg_Heroic_Leap_Cast, function Actions )
endfunction
 
Level 11
Joined
Dec 19, 2012
Messages
411
Next time, please post this in Triggers & Scripts forum if you want others people help you to fix code.

Firstly, your spell is quite inefficient. Run init inside condition function instead of actions function.

Instead using GetLocationX(GetSpellTargetLoc()), use GetSpellTargetX(). Same for the other one.

Avoid using BJs function.

JASS:
            loop
                exitwhen u == null
                set u = FirstOfGroup(g)
                if IsUnitEnemy(u, GetOwningPlayer(caster)) == true then
                call UnitDamageTarget(caster, u, damage, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_CLAW_MEDIUM_SLICE) 
                call GroupRemoveUnit(g, u)
                endif
            endloop

Should be :

JASS:
            loop
                set u = FirstOfGroup(g)
                exitwhen u == null
                if IsUnitEnemy(u, GetOwningPlayer(caster)) == true then
                call UnitDamageTarget(caster, u, damage, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_CLAW_MEDIUM_SLICE) 
                endif
                call GroupRemoveUnit(g, u)
            endloop

Also, set g = GetUnitsInRangeOfLocAll(Damage_Range(), GetUnitLoc(caster)) leaks 1 location in GetUnitLoc(caster)

And, local real distance = GetDistance(GetLocationX(GetUnitLoc(caster)), GetLocationY(GetUnitLoc(caster)), GetLocationX(GetSpellTargetLoc()), GetLocationY(GetSpellTargetLoc())) leaks lots of location, use GetUnitX(whichUnit) and GetUnitY(whichUnit)

JASS:
    local       real        x           =       GetLocationX(GetUnitLoc(caster)) + speed * Cos(angle* bj_DEGTORAD)
    local       real        y           =       GetLocationY(GetUnitLoc(caster)) + speed * Sin(angle* bj_DEGTORAD)
leak as well. As stated above, use GetUnitX(whichUnit) and GetUnitY(whichUnit)
 
Status
Not open for further replies.
Top