Events

What are Postal3Script events?

Events are essentially "signals" triggered by an outside source while the entity is in a state or pattern.

Types of Events

Events can be Global, State, or Pattern only.

Tip

Events that were called successfully will always override the caller, if that happens you can do TargetCaller 1 or access Object:caller or do conditional checks like
IfAttr "caller.ea_health > 0 ..." in the same pattern.

Global Events Example

Warning

Must be placed before or after the States bracket!


behavior
{
    name bh_Postal3ScriptDocs
    inherited bh_npc

    // Placing the events bracket here will make them global!
    events
    {
        OnHit           "ExecutePattern st_util.xpt_ThatHurtYouKnow"
        OnISmellFood    "State st_food"
    }
    States
    {
        st_init
        {
            Group Neutral
            Patterns
            {
                pt_default
                {
                    actions
                    {
                        ExecutePattern bh_base:st_init.pt_default
                    }
                }
            }
        }
    }
    // It works here too!
    events
    {
        OnTimer_tPoop "State st_poop"
    }
}

State Events Example

Warning

Must be placed after the State's 'Patterns' bracket!


behavior
{
    name bh_Postal3ScriptDocs
    inherited bh_npc

    States
    {
        st_idle
        {
            Group Neutral
            Patterns
            {
                pt_default
                {
                    actions
                    {
                        Timer tResting,60
                        Pattern pt_rest
                    }
                }

                pt_rest
                {
                    actions
                    {
                        // Note: this animation doesn't exists in Postal 3
                        Sequence seq.IDLE_SLEEP,999
                    }
                }

                pt_wakeup
                {
                    actions
                    {
                        // Note: this animation doesn't exists in Postal 3
                        Sequence seq.IDLE_WAKEUP
                        WaitForEnd 1
                        Wait 2
                        State st_start
                    }
                }
            }
            // Events will execute in any of the patterns above!
            events
            {
                // After 60 seconds this executes
                OnTimer_tResting    "Pattern pt_wakeup"
                // I was hit by someone...
                OnHit               "Pattern pt_wakeup"
                // I'm now pissed, literally
                OnNasty             "Pattern pt_wakeup"
            }
        }
    }
}

Pattern Events Example

Warning

Must be placed after the Pattern's 'actions' bracket!


behavior
{
    name bh_Postal3ScriptDocs
    inherited bh_npc

    States
    {
        st_idle
        {
            Group Neutral
            Patterns
            {
                pt_default
                {
                    actions
                    {
                        Timer tResting,60
                        Pattern pt_rest
                    }
                }

                pt_rest
                {
                    actions
                    {
                        // Note: this animation doesn't exists in Postal 3
                        Sequence seq.IDLE_SLEEP,999
                    }
                    // These events will now only execute in pt_rest
                    events
                    {
                        // After 60 seconds this executes
                        OnTimer_tResting    "Pattern pt_wakeup"
                        // I'm now pissed, literally
                        OnNasty             "Pattern pt_wakeup"
                        // I was hit by someone...
                        OnHit               "Pattern pt_wakeup"
                    }
                }

                pt_wakeup
                {
                    actions
                    {
                        // Note: this animation doesn't exists in Postal 3
                        Sequence seq.IDLE_WAKEUP
                        WaitForEnd 1
                        Wait 2
                        State st_start
                    }
                }
            }
        }
    }
}


Automatically Created Events

There are several Postal3Script functions that automatically create Events, here you can find all of them below, and the correspending functions:

OnAE_[name] -- AreaEvent

OnTimer_[name] -- Timer

OnAnim[animevent] -- Sequence (Note: Model animations need to have an anim event embedded)

OnAttrMin_[attribute] -- ChangeAttr

OnAttrMax_[attribute] -- ChangeAttr

OnAttrChange_[attribute] -- ChangeAttr

OnAttrRemove_[attribute] -- RemoveAttr

OnFire_[name] -- Fire Functions