/////////////////////////:/:///////////////////////////////////////////////////////////////////////////////////////
//:: Default:On Death
//:: NW_C2_DEFAULT7
//:: Copyright (c) 2001 Bioware Corp.
//::///////////////////////////////////////////////
/*
    Shouts to allies that they have been killed
*/
//:://////////////////////////////////////////////
//:: Created By: Preston Watamaniuk
//:: Created On: Oct 25, 2001
//:://///////////////////////////////////////////////
#include "NW_I0_GENERIC"
#include "jw_exp_giver"
#include "jw_custom_spells"
#include "prc_inc_spells"

void main()
{

    //Declare major variables
    object oCaster = OBJECT_SELF;
    int nMetaMagic = PRCGetMetaMagicFeat();
    float fDelay;
    effect eExplode = EffectVisualEffect(VFX_FNF_WAIL_O_BANSHEES);
//    effect eVis = EffectVisualEffect(VFX_FNF_WAIL_O_BANSHEES);
//    effect eDam;
    //Get the spell target location as opposed to the spell target.
    location lTarget = GetLocation(OBJECT_SELF);
    //Limit Caster level for the purposes of damage
    //Apply the fireball explosion at the location captured above.
    ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eExplode, lTarget);
    //Declare the spell shape, size and the location.  Capture the first target object in the shape.
    object oTarget = GetFirstObjectInShape(SHAPE_SPHERE, RADIUS_SIZE_HUGE, lTarget, TRUE, OBJECT_TYPE_CREATURE | OBJECT_TYPE_DOOR);
    //Cycle through the targets within the spell shape until an invalid object is captured.
    AssignCommand(oCaster,forcewave());
    int nClass = GetLevelByClass(CLASS_TYPE_COMMONER);
    int nAlign = GetAlignmentGoodEvil(OBJECT_SELF);
    if(nClass > 0 && (nAlign == ALIGNMENT_GOOD || nAlign == ALIGNMENT_NEUTRAL))
    {
        object oKiller = GetLastKiller();
        AdjustAlignment(oKiller, ALIGNMENT_EVIL, 5);
    }

    SpeakString("NW_I_AM_DEAD", TALKVOLUME_SILENT_TALK);
    //Shout Attack my target, only works with the On Spawn In setup
    SpeakString("NW_ATTACK_MY_TARGET", TALKVOLUME_SILENT_TALK);
    if(GetSpawnInCondition(NW_FLAG_DEATH_EVENT))
    {
        SignalEvent(OBJECT_SELF, EventUserDefined(1007));
    }

    location lPortal = GetLocation(GetWaypointByTag("ah_crypt_exit"));
   // CreateObject(OBJECT_TYPE_PLACEABLE, "ah_crypt_portal", lPortal, TRUE);


int nRandom=Random(7)+1;
if (nRandom>5)
{
nRandom=6;
}
string sObject="ah_banering"+IntToString(nRandom);

if (sObject=="ah_banering3")
{
sObject="ah_banering9";
}


CreateItemOnObject(sObject,OBJECT_SELF,1);

givexp(OBJECT_SELF,GetLastKiller());
ExecuteScript("prc_npc_death", OBJECT_SELF);
}