//::///////////////////////////////////////////////
//:: Custom User Defined Event

void main()
{
    int nUser = GetUserDefinedEventNumber();

    if(nUser == 1001) //HEARTBEAT
    {

    }
    else if(nUser == 1002) // PERCEIVE
    {

    }
    else if(nUser == 1003) // END OF COMBAT
    {

    }
    else if(nUser == 1004) // ON DIALOGUE
    {

    }
    else if(nUser == 1005) // ATTACKED
    {

    }
    else if(nUser == 1006) // DAMAGED
    {
        if (GetCurrentHitPoints() < GetMaxHitPoints() / 4)
            SetPlotFlag(OBJECT_SELF, TRUE);
    }
    else if(nUser == 1007) // DEATH
    {
        //object oZendril = GetObjectByTag("jhr_zendril_battle");
        //SetLocalObject(oZendril, "oHealTarget", OBJECT_SELF);
        //SignalEvent(oZendril, EventUserDefined(2001));

        int nMaxHP = GetMaxHitPoints(OBJECT_SELF);
        // : REMINDER: The delay is here   for a reason
        //DelayCommand(0.1, RemoveEffects(OBJECT_SELF));
        DelayCommand(0.2, ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectResurrection(), OBJECT_SELF));
        if (nMaxHP != 1)
            DelayCommand(0.3, ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectHeal(nMaxHP - (nMaxHP - 1)), OBJECT_SELF));
        else
            DelayCommand(0.3, ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectHeal(nMaxHP), OBJECT_SELF));
        DelayCommand(5.1, SetIsDestroyable(FALSE, TRUE, FALSE));
        SetPlotFlag(OBJECT_SELF, TRUE);
    }
    else if(nUser == 1008) // DISTURBED
    {

    }

}

