HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

timer help

05-14-2007, 11:11 AM#1
MaD[Lion]
ok ive heard of timer, but tbh i have no idea how to use them. As wait. Can someone give me an example in jass thnx :)

example i wanna wait 0.05 sec with timer, how do i do tat
05-14-2007, 11:44 AM#2
TheSecretArts
Collapse JASS:
function Display takes nothing returns nothing
    call DisplayTextToForce(GetPlayersAll(),".05 seconds have passed")
endfunction
function createtimer takes nothing returns nothing
local timer t
set t = CreateTimer()
call TimerStart(t,.05,true,code Display)
endfunction
That is basic for a timer that every .05 seconds displays .05 seconds have passed
Collapse JASS:
//With this, you can use handle vars
//IE (Blade.dk stomp tutorial): 
function Trig_Stomp_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A000'
endfunction

function Stomp_Filter takes nothing returns boolean
    return IsPlayerEnemy(GetOwningPlayer(GetTriggerUnit()), GetOwningPlayer(GetFilterUnit())) and GetWidgetLife(GetFilterUnit()) > 0.405 and not IsUnitType(GetFilterUnit(), UNIT_TYPE_FLYING)
endfunction

function Stomp_CopyGroup takes group g returns group
    set bj_groupAddGroupDest = CreateGroup()
    call ForGroup(g, function GroupAddGroupEnum)
    return bj_groupAddGroupDest
endfunction

function Stomp_Move takes nothing returns nothing
    local string s = I2S(H2I(GetExpiredTimer()))
    local gamecache gc = udg_AbilityCache
    local real x = GetStoredReal(gc, s, "x")
    local real y = GetStoredReal(gc, s, "y")
    local integer i = GetStoredInteger(gc, s, "level")
    local group g = Stomp_CopyGroup(I2G(GetStoredInteger(gc, s, "group")))
    local real dur = GetStoredReal(gc, s, "dur")+0.05
    local real ux
    local real uy
    local real a
    local unit f
    local real p = GetStoredReal(gc, s, "speed")-0.5/(1+0.5*i)
    local real fx = GetStoredReal(gc, s, "fx")+0.05
    if dur < 1+0.5*i then
        loop
            set f = FirstOfGroup(g)
            exitwhen f == null
            set ux = GetUnitX(f)
            set uy = GetUnitY(f)
            set a = Atan2(uy-y, ux-x)
            call SetUnitPosition(f, ux+p*Cos(a), uy+p*Sin(a))
            if fx >= 1 then
                call DestroyEffect(AddSpecialEffectTarget(GetAbilityEffectById('A000', EFFECT_TYPE_MISSILE, 1), f, GetAbilityEffectById('A000', EFFECT_TYPE_MISSILE, 2)))
            endif
            call GroupRemoveUnit(g, f)
        endloop
        call StoreReal(gc, s, "dur", dur)
        call StoreReal(gc, s, "speed", p)
        call StoreReal(gc, s, "fx", fx)
        if fx >= 1 then
            call StoreReal(gc, s, "fx", 0)
        endif
    else
        call DestroyGroup(I2G(GetStoredInteger(gc, s, "group")))
        call FlushStoredMission(gc, s)
        call DestroyTimer(GetExpiredTimer())
    endif
    set gc = null
    call DestroyGroup(g)
    set g = null
    set f = null
endfunction

function Trig_Stomp_Actions takes nothing returns nothing
    local unit c = GetTriggerUnit()
    local real x = GetUnitX(c)
    local real y = GetUnitY(c)
    local integer i = GetUnitAbilityLevel(c, 'A000')
    local boolexpr b = Condition(function Stomp_Filter)
    local group g = CreateGroup()
    local group n
    local unit f
    local gamecache gc = udg_AbilityCache
    local timer t = CreateTimer()
    local string s = I2S(H2I(t))
    call DestroyEffect(AddSpecialEffect(GetAbilityEffectById('A000', EFFECT_TYPE_MISSILE, 0), x, y))
    call GroupEnumUnitsInRange(g, x, y, 100+50*i, b)
    set n = Stomp_CopyGroup(g)
    loop
        set f = FirstOfGroup(n)
        exitwhen f == null
        call UnitDamageTarget(c, f, 25*i, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC, null)
        call GroupRemoveUnit(n, f)
    endloop
    call StoreInteger(gc, s, "level", i)
    call StoreInteger(gc, s, "group", H2I(g))
    call StoreReal(gc, s, "x", x)
    call StoreReal(gc, s, "y", y)
    call TimerStart(t, 0.05, true, function Stomp_Move)
    set c = null
    call DestroyBoolExpr(b)
    set b = null
    set g = null
    call DestroyGroup(n)
    set n = null
    set f = null
    set gc = null
    set t = null
endfunction

//===========================================================================
function InitTrig_Stomp takes nothing returns nothing
    set gg_trg_Stomp = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Stomp, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Stomp, Condition( function Trig_Stomp_Conditions ) )
    call TriggerAddAction( gg_trg_Stomp, function Trig_Stomp_Actions )
    call Preload(GetAbilityEffectById('A000', EFFECT_TYPE_MISSILE, 0))
    call Preload(GetAbilityEffectById('A000', EFFECT_TYPE_MISSILE, 1))
endfunction
The above spell (after //IE:) is credited to Blade.dk's Spell Making tutorial found here http://www.wc3campaigns.net/showthread.php?t=83337
05-14-2007, 12:48 PM#3
Toink
The most efficient way to use timer is the Timer Recycling, included in the Caster System in the CSSafety trigger by Vexorian.

There are somekind of bugs with timers when nulling them.

Take a look at Rising_Dusk's tutorial about timers here

That tutorial is excellent.
05-14-2007, 01:04 PM#4
iNfraNe
haha
05-14-2007, 01:10 PM#5
grim001
You can't use a timer as a simple replacement for wait, you can only perform a callback after a delay.
05-14-2007, 02:14 PM#6
Rising_Dusk
I think this is one of his "pretending to be stupid" things.

But yeah, Toink did it first.
In case you do happen to be serious and a bump on the head removed all memory of how to use timers.
My tutorial pretty much explains everything about them.
05-15-2007, 05:43 AM#7
MaD[Lion]
hm... so timer must call a code, how gay :P

but i just figured out a way to make a nice wait function :D

and to Infrane: shut up :P not everyone have knowledge about everything :P
05-15-2007, 09:48 AM#8
Toadcop
Quote:
Timer Recycling
btw first it was my idea + realisation and don't simple recylce timer but also precache needed amount of them it makes stuff 100% bullet proof !

Quote:
not everyone have knowledge about everything
yes.
for example no one knows Agent Smith - Cosmos (overburden with snow (- it's translated)) (Bobina in rock remix - rocks !)
05-15-2007, 11:02 AM#9
MaD[Lion]
no one cares about tc's opinions anyway ^^ at least i dont, cus everything he say are total crap tat dont solve anything. cus they are just like: "omg my stuff is better but i choose to be noob so i dont say.". In other words:
"omg i am so stupid, they are so much better than me, im jealous so i pretend i know more but i have no proof" :P