Timer

Creates a timer to wait before executing an event.

Syntax

Timer [string],[float] -- Creates a Timer, will execute OnTimer_[string] event after [float] seconds.

Timer [string],[float],repeated -- Creates a Timer, will execute OnTimer_[string] event after every [float] seconds.

Timer [string],0 -- Disables a Timer completely.

Timer:[string] -- Get a Timer object's timer/value.

Warning

Checking for a non-existent Timer is not possible. You must pre-create all the timers you will use with Timer [string],0 to ensure IfAttr will properly return zero value.

The example below shows a piece of code that will always fail if tCantHeal doesn't exists, and instead of returning from it, it will continue to execute all the actions below it.

Example


// This state was entered from somewhere else...
st_medic
{
    Group Neutral
    Patterns
    {
        pt_default
        {
            actions
            {
                // We assume that 'tCantHeal' is a global timer set somewhere else...
                // (Note: if 'tCantHeal' does not exist, this check will fail and will continue 
                // to create 'tHealMe' timer)
                IfAttr "Timer:tCantHeal > 0 Block begin"
                    State st_canthealmyself
                    Return 0
                Block end

                // If we somehow want to limit this NPC to only fully regenerate once...
                IfAttr "fullyregenerated == 1 Block begin"
                    State st_canthealmyself
                    Return 0
                Block end

                Timer tHealMe,3,repeatable
            }
            events
            {
                // Will execute after every 3 seconds
                // (only pt_default will be able to see this event)
                OnTimer_tHealMe "Pattern pt_healcheck"
            }
        }

        pt_healcheck
        {
            actions
            {
                // If our health is equal to or greater than 100 don't bother healing ourselves
                IfAttr "ea_health >= 100 Block begin"
                    // Disable the timer
                    Timer tHealMe,0
                    State st_start // enter into another state...
                    SetAttr "fullyregenerated 1"
                    Return 0
                Block end

                ChangeAttr "ea_health +5"           
                Pattern pt_default
            }
        }
    }
}

//
// Alternative version, which instantly heals an NPC after a few seconds...
//
st_godmode
{
    Group Neutral
    Patterns
    {
        pt_default
        {
            actions
            {   
                Timer tGod,7
            }
            events
            {
                // Will execute after 7 seconds
                // (only pt_default will be able to see this event)
                OnTimer_tGod    "Pattern pt_miracle"
            }
        }

        pt_miracle
        {
            actions
            {   
                SetAttr "ea_health 100"
                State st_start
            }
        }
    }
}