//::///////////////////////////////////////////////
//:: Name x2_def_userdef
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
    Default On User Defined Event script
*/
//:://////////////////////////////////////////////
//:: Created By: Keith Warner
//:: Created On: June 11/03
//:://////////////////////////////////////////////

#include "nw_i0_generic"

const int EVENT_USER_DEFINED_PRESPAWN = 1510;
const int EVENT_USER_DEFINED_POSTSPAWN = 1511;
void main()
{
    int nUser = GetUserDefinedEventNumber();

    if(nUser == EVENT_HEARTBEAT ) //HEARTBEAT
    {

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

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

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

    }
    else if(nUser == EVENT_ATTACKED) // ATTACKED
    {
        object oPC = GetLastAttacker(OBJECT_SELF);
        int nCRMax = GetHitDice(oPC);
        //ActionUseTalentOnObject(GetCreatureTalentBest(TALENT_CATEGORY_BENEFICIAL_OBTAIN_ALLIES, nCRMax), OBJECT_SELF);


    }
    else if(nUser == EVENT_DAMAGED) // DAMAGED
    {
    int iFeatCheck = GetLocalInt(OBJECT_SELF, "iFeatCheck");
    int iHalfHP;
    if (GetCurrentHitPoints() < (GetMaxHitPoints()/2)) iHalfHP = 1;

    if (iFeatCheck != 1 && iHalfHP == 1)
        {

        int iFeat;

        //Shifter
        if (GetLevelByClass(CLASS_TYPE_SHIFTER) > 0)
            {
            if (GetHasFeat(FEAT_EPIC_WILD_SHAPE_DRAGON)) iFeat = FEAT_EPIC_WILD_SHAPE_DRAGON;
            else if (GetHasFeat(FEAT_EPIC_OUTSIDER_SHAPE)) iFeat = FEAT_EPIC_OUTSIDER_SHAPE;
            else if (GetHasFeat(FEAT_EPIC_CONSTRUCT_SHAPE)) iFeat = FEAT_EPIC_CONSTRUCT_SHAPE;
            else if (GetHasFeat(FEAT_EPIC_WILD_SHAPE_UNDEAD)) iFeat = FEAT_EPIC_WILD_SHAPE_UNDEAD;
            else if (GetHasFeat(FEAT_GREATER_WILDSHAPE_4)) iFeat = FEAT_GREATER_WILDSHAPE_4;
            else if (GetHasFeat(FEAT_GREATER_WILDSHAPE_3)) iFeat = FEAT_GREATER_WILDSHAPE_3;
            else if (GetHasFeat(FEAT_HUMANOID_SHAPE)) iFeat = FEAT_HUMANOID_SHAPE;
            else if (GetHasFeat(FEAT_GREATER_WILDSHAPE_2)) iFeat = FEAT_GREATER_WILDSHAPE_2;
            else if (GetHasFeat(FEAT_GREATER_WILDSHAPE_1)) iFeat = FEAT_GREATER_WILDSHAPE_1;

            ActionUseFeat(iFeat, OBJECT_SELF);
            }

        SetLocalInt(OBJECT_SELF, "iFeatCheck", 1);

        }

    }
    else if(nUser == 1007) // DEATH  - do not use for critical code, does not fire reliably all the time
    {

    }
    else if(nUser == EVENT_DISTURBED) // DISTURBED
    {

    }
    else if (nUser == EVENT_USER_DEFINED_PRESPAWN)
    {

    }
    else if (nUser == EVENT_USER_DEFINED_POSTSPAWN)
    {

    }


}


