Aller au contenu

Photo

targeting spell-like feat


  • Veuillez vous connecter pour répondre
5 réponses à ce sujet

#1
Laugh out loud

Laugh out loud
  • Members
  • 109 messages

I have a spell-like feat that is supposed to target all applicable opponents (as selected by race) within range but it only seems to be targeting a few if they are of different applicable races.  For example if you are being attacked by an undead, a dwarf and a spider at the same time it will be able to strike all three as they are all different races however, if you are attacked by 8 dogs it is only attacking 1-4 of them because they are all of the same race.  Can someone take a look and see why it is not attacking all applicable opponents within range?

 

 

#include "nwn2_inc_spells" 
#include "X0_I0_SPELLS"
#include "x2_inc_spellhook" 
const int SPELL_SPIRIT_LASH = 1647;
 
void main()
{
 
 
    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 = GetLevelByClass(64, 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_TURN_UNDEAD);
    effect eEff = EffectLinkEffects(eVis, eEffect);
    effect eLink;
 
if (GetHasFeat(2818, oCaster))
    {
    nDamage = (d8(4) + (2 * nCasterLvl));
SendMessageToPC(GetFirstPC(), "Improved spirit lash!");
    }
    else
    {
    nDamage = (d4(4) + (2 * nCasterLvl));
    }
 
    
    while (GetIsObjectValid(oTarget))
    {
        if (spellsIsTarget(oTarget, SPELL_TARGET_STANDARDHOSTILE, oCaster))
        {
          SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, 1647));
          if ((GetRacialType(oTarget) == RACIAL_TYPE_UNDEAD ||  GetSubRace(oTarget) == RACIAL_SUBTYPE_INCORPOREAL)
                || (GetHasFeat(2825, oCaster, TRUE)
                    && (GetRacialType(oTarget) == RACIAL_TYPE_ELEMENTAL
                        || GetSubRace(oTarget) == RACIAL_SUBTYPE_PLANT))
                || (GetHasFeat(2826, oCaster, TRUE)
                    && (GetRacialType(oTarget) == RACIAL_TYPE_ANIMAL
                        || GetRacialType(oTarget) == RACIAL_TYPE_BEAST
                        || GetRacialType(oTarget) == RACIAL_TYPE_MAGICAL_BEAST
                        || GetRacialType(oTarget) == RACIAL_TYPE_VERMIN))
                || (GetHasFeat(2827, oCaster, TRUE)
                    && (GetRacialType(oTarget) == RACIAL_TYPE_HUMAN
                        || GetRacialType(oTarget) == RACIAL_TYPE_DWARF
                        || GetRacialType(oTarget) == RACIAL_TYPE_ELF
                        || GetRacialType(oTarget) == RACIAL_TYPE_GNOME
                        || GetRacialType(oTarget) == RACIAL_TYPE_HALFLING
                        || GetRacialType(oTarget) == RACIAL_TYPE_HALFELF
                        || GetRacialType(oTarget) == RACIAL_TYPE_HALFORC)))
            {
eDam = EffectDamage(nDamage, DAMAGE_TYPE_DIVINE);
            ApplyEffectToObject(DURATION_TYPE_INSTANT, eDam, oTarget);
            ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eEffect, oTarget, 6.0f);
}
else
{
}
       oTarget = GetNextObjectInShape(SHAPE_SPHERE, RADIUS_SIZE_VAST, lTarget, TRUE, OBJECT_TYPE_CREATURE);
    }
}
}
 
 
PS: I already got help withone once in the past and it was working but I had a system crash and lost a lot of data that I was working on.  I have tried rewriting the same script again but it is not working as well as it did before the data loss.  Something must not be quite right.


#2
kevL

kevL
  • Members
  • 4 056 messages
re-definition of oTarget is up inside spellsIsTarget() condition

move it out a brace, so only the while() condition affects it

#3
Laugh out loud

Laugh out loud
  • Members
  • 109 messages

Sorry, but I am afraid I do not understand?  If I move the oTarget out of the spellIsTarget() condition or remove the brackets around the whole function, it will not even compile.  If I remove the SPELL_TARGET_STANDARDHOSTILE function the spell will attack the caster and his allies.



#4
4760

4760
  • Members
  • 1 204 messages

The way the script it written, the target object is not re-defined at each pass of the while loop:

 while (GetIsObjectValid(oTarget))
{ // while
        if (spellsIsTarget // end of line removed for sake of clarity
        { //if spellsIsTarget
          if ((GetRacialType(oTarget)
          { // if GetRacialType TRUE
            eDam = EffectDamage(nDamage, DAMAGE_TYPE_DIVINE);
            ApplyEffectToObject(DURATION_TYPE_INSTANT, eDam, oTarget);
            ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eEffect, oTarget, 6.0f);
          } // if GetRacialType TRUE ends
          else
          { // if GetRacialType FALSE
            // nothing? Then no need for the else part...
          } // if GetRacialType FALSE end
       oTarget = GetNextObjectInShape // end of line removed for sake of clarity
       } //if spellsIsTarget end
// This is where oTarget = GetNextObjectInShape should be
    } // while end


#5
kevL

kevL
  • Members
  • 4 056 messages
that is, the loop is stopping as soon as it hits a creature that returns false for spellsIsTarget()

you want it to keep going regardless and check the next creature - with this structure:


Object is FirstObjectInShape()
while (Object is Valid)
{
if (spellsIsTarget)
{
// ...
}

Object is NextObjectInShape()
}


that way the loop doesn't shut down until all creatures in shape have been examined.

#6
Laugh out loud

Laugh out loud
  • Members
  • 109 messages

Thank you both.  I understand now and it passed both tests I ran on it.