• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Problem with units and timers (And starting timers)

Status
Not open for further replies.
Level 14
Joined
Jul 26, 2008
Messages
1,009
Alright so I've been racking my brain trying to figure out how to get this timer to expire properly. It's basically a track effect.

All units are pinged, then if the spell is a high enough level you will get shared vision of the units for a short duration. The problem (I assume) is that all the units are not being stored into a variable when the timer starts, so they're not being removed when the timer expires. I've tried putting in an array to count them all, then creating one timer for each unit, but I'm pretty sure I did that wrong too.

Could someone help me figure out the proper way to save all these units into a variable, and then remove vision upon the timer's expriation? Thanks :)


JASS:
//This is where the loop begins where we choose the units to track
    loop
     set t = FirstOfGroup(g)
    exitwhen t == null
        call PingMinimap(GetUnitX(t), GetUnitY(t), 1.5*GetUnitAbilityLevel(D.c, SpellID))
        if GetUnitAbilityLevel(D.c, SpellID) == 3 then
            set temp[D.i] = t
            call UnitShareVision(temp[D.i], GetOwningPlayer(D.c), true)
            call SetTimerData(tim, D)
            call TimerStart(tim, 3.0, false, function Track_Timer)
        endif
        call GroupRemoveUnit(g, t)
        set D.i = D.i + 1
    endloop

JASS:
//The simple timer for the end of the duration
private function Track_Timer takes nothing returns nothing
 local timer tim = GetExpiredTimer()
 local Data D = Data(GetTimerData(tim))
    call UnitShareVision(temp[D.i], GetOwningPlayer(D.c), false)
    call ReleaseTimer(tim)
 call D.destroy()
endfunction
 
Last edited:
Level 9
Joined
May 28, 2007
Messages
365
Use a unit group in the struct. As well as the unit that is granted the vision.

JASS:
struct Data
    unit caster = null
    group g     = null
endstruct

function Reset takes nothing returns nothing 
local Data d = GetTimerData(GetExpiredTimer())
local unit t = null
    loop
     set t = FirstOfGroup(g)
    exitwhen t == null
        call UnitShareVision( t, GetOwningPlayer(caster), false )
        call GroupRemoveUnit(g, t)
    endloop
endfunction

//This is where the loop begins where we choose the units to track
    loop
     set t = FirstOfGroup(g)
    exitwhen t == null
        call PingMinimap(GetUnitX(t), GetUnitY(t), 1.5*GetUnitAbilityLevel(D.c, SpellID))
        if GetUnitAbilityLevel(D.c, SpellID) == 3 then
            call UnitShareVision(temp[D.i], GetOwningPlayer(D.c), true)
            call GroupAddUnit( D.g, temp[D.i])
            call SetTimerData(tim, D)
            call TimerStart( yourTimer, 3, false, function Reset )
        endif
        call GroupRemoveUnit(g, t)
        set D.i = D.i + 1
    endloop


And TimerUtils is by Vexorian not Rising_Dusk.
 
Level 14
Joined
Jul 26, 2008
Messages
1,009
Thanks. I'll try it and see if it works :)

And you're right, it's Vexorian. Rising_Dusk did GroupUtils and a few other Utils.

UPDATE: So far what I tried didn't work. Here is what I attempted:

JASS:
private struct Data

    unit c
    group g
    
    static method create takes unit caster returns Data
     local Data D = Data.allocate()
        set D.c = caster
        set D.g = CreateGroup()
     return D
    endmethod
     
     
endstruct
/================
private function Track_Timer takes nothing returns nothing
 local timer tim = GetExpiredTimer()
 local Data D = Data(GetTimerData(tim))
 local unit t
    loop
    set t = FirstOfGroup(D.g)
    exitwhen t == null
        call UnitShareVision(t, GetOwningPlayer(D.c), false)
        call GroupRemoveUnit(D.g, t)
    endloop
    call DestroyGroup(D.g)
    set D.g = null
    call ReleaseTimer(tim)
    call D.destroy()
    set tim = null
endfunction
//========================================

    set D.g = g
    loop
     set t = FirstOfGroup(g)
    exitwhen t == null
        call PingMinimap(GetUnitX(t), GetUnitY(t), 1.5*GetUnitAbilityLevel(D.c, SpellID))
        if GetUnitAbilityLevel(D.c, SpellID) == 3 then
            call UnitShareVision(t, GetOwningPlayer(D.c), true)
            call SetTimerData(tim, D)
            call TimerStart(tim, 3.0, false, function Track_Timer)
        else   
            call DestroyGroup(D.g)
            set D.g = null
        endif
        call GroupRemoveUnit(g, t)
    endloop
//=====================================
 
Last edited:
Level 9
Joined
May 28, 2007
Messages
365
Please attach the full code.

Specifically the stuff that pertains to this:
//========================================

set D.g = g
loop
set t = FirstOfGroup(g)
exitwhen t == null
call PingMinimap(GetUnitX(t), GetUnitY(t), 1.5*GetUnitAbilityLevel(D.c, SpellID))
if GetUnitAbilityLevel(D.c, SpellID) == 3 then
call UnitShareVision(t, GetOwningPlayer(D.c), true)
call SetTimerData(tim, D)
call TimerStart(tim, 3.0, false, function Track_Timer)
else
call DestroyGroup(D.g)
set D.g = null
endif
call GroupRemoveUnit(g, t)
endloop
//=====================================

Also, don't set tim = null at the end there. The whole point of TImerUtils is so you won't have to do things like that.
 
Status
Not open for further replies.
Top