I am writing a spell that normally only harms undead but if the character has a feat it can harm elemetals as well. I can get the script to compile but not work properly in the game. Can someone take a look at it to see why it is not haming either creature?
#include "nwn2_inc_spells"
#include "X0_I0_SPELLS"
#include "x2_inc_spellhook"
const int SPELL_SPIRIT_LASH = 1647;
void main()
{
/*
Spellcast Hook Code
Added 2003-06-20 by Georg
If you want to make changes to all spells,
check x2_inc_spellhook.nss to find out more
*/
if (!X2PreSpellCastCode())
{
// If code within the PreSpellCastHook (i.e. UMD) reports FALSE, do not run this spell
return;
}
// End of Spell Cast Hook
//Declare major variables
object oCaster = OBJECT_SELF;
int nCasterLvl = GetCasterLevel(oCaster);
int nDamage;
float fDelay;
//Get the spell target location as opposed to the spell target.
location lTarget = GetSpellTargetLocation();
//Apply the ice storm VFX at the location captured above.
//Declare the spell shape, size and the location. Capture the first target object in the shape.
object oTarget = GetFirstObjectInShape(SHAPE_SPHERE, RADIUS_SIZE_VAST, lTarget, TRUE, OBJECT_TYPE_CREATURE);
effect eEffect;
eEffect = EffectKnockdown();
eEffect = SupernaturalEffect(eEffect);
effect eDam;
effect eVis = EffectVisualEffect(VFX_HIT_WEAKEN_SPIRITS);
effect eEff = EffectLinkEffects(eVis, eEffect);
effect eLink;
while(GetIsObjectValid(oTarget))
{
if (spellsIsTarget(oTarget, SPELL_TARGET_STANDARDHOSTILE, oCaster))
{
SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, 1647));
if ((GetRacialType(oTarget) == RACIAL_TYPE_ELEMENTAL) && (GetHasFeat(2825, oCaster)))
{
nDamage = (d4(4)+(2*nCasterLvl));
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eEff, oTarget, 6.0f);
eDam = EffectDamage(nDamage, DAMAGE_TYPE_DIVINE);
ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis,oCaster);
DelayCommand(0.01, ApplyEffectToObject(DURATION_TYPE_INSTANT, eEff, oTarget));
}
if ((GetRacialType(oTarget) == RACIAL_TYPE_UNDEAD))
{
nDamage = (d4(4)+(2*nCasterLvl));
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eEff, oTarget, 6.0f);
eDam = EffectDamage(nDamage, DAMAGE_TYPE_DIVINE);
ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis,oCaster);
DelayCommand(0.01, ApplyEffectToObject(DURATION_TYPE_INSTANT, eEff, oTarget));
}
else
{
nDamage = 1;
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eEff, oTarget, 6.0f);
eDam = EffectDamage(nDamage, DAMAGE_TYPE_DIVINE);
ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis,oCaster);
DelayCommand(0.01, ApplyEffectToObject(DURATION_TYPE_INSTANT, eEff, oTarget));
}
}
}
oTarget = GetNextObjectInShape(SHAPE_SPHERE, RADIUS_SIZE_VAST, lTarget, TRUE, OBJECT_TYPE_CREATURE);
}