• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] Mmmm memory leaks.

Status
Not open for further replies.
JASS:
function Trig_Intimidating_Shout_Actions takes nothing returns nothing

     local unit caster = GetSpellAbilityUnit()
     local unit target = GetSpellTargetUnit()
     local location casterLoc = GetUnitLoc(caster)
     local location array rundest
     local unit array feared
     local location array fearedLoc
     local group aoe
     local integer loops = 0
     local integer fearinterval = 0
     local effect array fearSFX

     call AddSpecialEffectTargetUnitBJ("origin", caster, "Abilities\\Spells\\Human\\Avatar\\AvatarCaster.mdl")
     call DestroyEffect(GetLastCreatedEffectBJ())
     call AddSpecialEffectTargetUnitBJ("origin", caster, "Abilities\\Spells\\NightElf\\BattleRoar\\RoarCaster.mdl")
     call DestroyEffect(GetLastCreatedEffectBJ())
     call AddSpecialEffectTargetUnitBJ("origin", caster, "Abilities\\Spells\\NightElf\\Taunt\\TauntCaster.mdl")
     call DestroyEffect(GetLastCreatedEffectBJ())

     set aoe = GetUnitsInRangeOfLocAll(300, casterLoc)
     call GroupRemoveUnit(aoe, target)
     call GroupRemoveUnit(aoe, caster)

     call PauseUnit(target, true)

     loop
     exitwhen IsUnitGroupEmptyBJ(aoe) == true

     if IsUnitEnemy(FirstOfGroup(aoe), GetOwningPlayer(caster)) == true then
        set loops = loops + 1
        set feared[loops] = FirstOfGroup(aoe)
        set fearedLoc[loops] = GetUnitLoc(feared[loops])
        call GroupRemoveUnit(aoe, FirstOfGroup(aoe))
        exitwhen IsUnitGroupEmptyBJ(aoe) == true
     else
         call GroupRemoveUnit(aoe, FirstOfGroup(aoe))
     endif
     exitwhen loops == 5
     endloop

     set loops = 1

     loop
     exitwhen feared[loops] == null

     call AddSpecialEffectTargetUnitBJ("overheard", feared[loops], "Abilities\\Spells\\Other\\HowlOfTerror\\HowlTarget.mdl")
     set fearSFX[loops] = GetLastCreatedEffectBJ()

     set loops = loops + 1
     endloop


     loop

     set loops = 1

     loop
     exitwhen feared[loops] == null

     set rundest[loops] = PolarProjectionBJ(fearedLoc[loops], GetRandomReal(140, 310), GetRandomReal(0,359))
     call  IssuePointOrderLoc(feared[loops], "move", rundest[loops])


     set loops = loops + 1
     endloop
     call RemoveLocation(fearedLoc[1])
     call RemoveLocation(fearedLoc[2])
     call RemoveLocation(fearedLoc[3])
     call RemoveLocation(fearedLoc[4])
     call RemoveLocation(fearedLoc[5])

     call RemoveLocation(rundest[1])
     call RemoveLocation(rundest[2])
     call RemoveLocation(rundest[3])
     call RemoveLocation(rundest[4])
     call RemoveLocation(rundest[5])

     call TriggerSleepAction(0.25)
     set fearinterval = fearinterval + 1
     if fearinterval == 12 then
        call PauseUnit(target, false)
     endif
     exitwhen fearinterval == 32
     endloop



     set caster = null
     set target = null

     set fearedLoc[1] = null
     set fearedLoc[2] = null
     set fearedLoc[3] = null
     set fearedLoc[4] = null
     set fearedLoc[5] = null

     set feared[1] = null
     set feared[2] = null
     set feared[3] = null
     set feared[4] = null
     set feared[5] = null

     set rundest[1] = null
     set rundest[2] = null
     set rundest[3] = null
     set rundest[4] = null
     set rundest[5] = null

     call DestroyEffect(fearSFX[1])
     call DestroyEffect(fearSFX[2])
     call DestroyEffect(fearSFX[3])
     call DestroyEffect(fearSFX[4])
     call DestroyEffect(fearSFX[5])

     call RemoveLocation(casterLoc)

     call DestroyGroup(aoe)

     set aoe = null

     set fearSFX[1] = null
     set fearSFX[2] = null
     set fearSFX[3] = null
     set fearSFX[4] = null
     set fearSFX[5] = null

     set casterLoc = null


endfunction


Now, this spell is called Intimidating Shout. What this spell does is basically just stun the target for 3 seconds, while causing up to 5 enemies nearby to flee for 8 seconds. While in the 8 seconds, enemies can still be issued order by players, but will have difficulty in doing so.

Now I was wondering if any JASS experts here can help me if there is any memory leak in this spell.

:p First time doing a non-art, non-MDL thing.

EDIT: Some new spell lawl.
 

Attachments

  • BlastNova.w3x
    35.6 KB · Views: 53
Last edited:
Level 40
Joined
Dec 14, 2005
Messages
10,532
Didn't leak, far as I could tell.

Anyways, please use
JASS:
 tags.

Finally, majorly cleaned up your code, hope you can learn something from this =D

(of course, there's a fair chance this won't work, since I can't test it)

[code=jass]function Intimidating_Shout_Antileak takes nothing returns boolean
    return true
endfunction

function Trig_Intimidating_Shout_Actions takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local unit target = GetSpellTargetUnit()
    local unit array feared
    local group aoe = CreateGroup()
    local integer i = 0
    local integer fearinterval = 0
    local effect array fearSFX
    local real d
    local real a
    local unit u
    call GroupEnumUnitsInRange(aoe,GetUnitX(caster),GetUnitY(caster),300,Filter(function Intimidating_Shout_Antileak))

    call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\Avatar\\AvatarCaster.mdl",caster,"origin"))
    call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\NightElf\\BattleRoar\\RoarCaster.mdl",caster,"origin"))
    call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\NightElf\\Taunt\\TauntCaster.mdl",caster,"origin"))

    call GroupRemoveUnit(aoe, target)
    call GroupRemoveUnit(aoe, caster)
    call PauseUnit(target, true)
    loop
        set u = FirstOfGroup(aoe)
        exitwhen u == null or i > 4
        if IsUnitEnemy(u, GetOwningPlayer(caster)) then
            set i = i + 1
            set feared[i] = u
        endif
        call GroupRemoveUnit(aoe,u)
    endloop
    call DestroyGroup(aoe)
    set aoe = null
    set i = 0
    loop
        exitwhen feared[i] == null
        set fearSFX[i] = AddSpecialEffectTarget("Abilities\\Spells\\Other\\HowlOfTerror\\HowlTarget.mdl",feared[i],"overhead")
        set i = i + 1
    endloop
    loop
        set i = 0
        exitwhen fearinterval == 32
        loop
            exitwhen feared[i] == null
            set d = GetRandomReal(140,310)
            set a = GetRandomReal(.01,2*bj_PI)
            call IssuePointOrder(feared[i], "move", GetUnitX(feared[i])+d*Cos(a), GetUnitY(feared[i])+d*Sin(a))
            set i = i + 1
        endloop
        call TriggerSleepAction(.25)
        set fearinterval = fearinterval + 1
        if fearinterval == 12 then
           call PauseUnit(target, false)
        endif
    endloop
    loop
        exitwhen i > 4
        set feared[i] = null
        call DestroyEffect(fearSFX[i])
        set fearSFX[i] = null
        set i = i + 1
    endloop
    set caster = null
    set target = null
endfunction
 
Status
Not open for further replies.
Top