Aller au contenu

Photo

Touch Attack Script


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

#1
Laugh out loud

Laugh out loud
  • Members
  • 117 messages

I am working on a custom spell script that delivers "damage type" based upon the caster's alignment in the form of a ranged touch attack. I used acid splash as a frame for my spell but it still will not produce the ranged touch attack.  Can someone take a look and tell me what part am I doing wrong?

 

#include "X0_I0_SPELLS"
#include "x2_inc_spellhook" 
#include "nwn2_inc_spells"
 
object oPC = OBJECT_SELF;
int IsEvil(object oPC)
{
object oPC = GetPCSpeaker();
 
if (GetAlignmentGoodEvil(oPC) != ALIGNMENT_EVIL) return FALSE;
 
return TRUE;
}
 
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 oTarget = GetSpellTargetObject();
    int nCasterLevel = GetCasterLevel(OBJECT_SELF);
int nTouch = TouchAttackRanged(oTarget);
 
    effect eVis;
    effect eVis1;
    effect eVis2;
    effect eBolt;
effect eSide;
int nWIS = GetAbilityModifier(ABILITY_WISDOM, OBJECT_SELF);
    int nDamage;
 
if (IsEvil(oPC)<1)
{
    eBolt = EffectDamage(nDamage, DAMAGE_TYPE_NEGATIVE);
    effect eVis = EffectVisualEffect(VFX_IMP_NEGATIVE_ENERGY);
    effect eVis1 = EffectVisualEffect(VFX_DUR_SPELL_ENERGY_DRAIN);
effect eVis2 = EffectLinkEffects(eVis, eVis1);
eSide = ExtraordinaryEffect(EffectAbilityDecrease(ABILITY_STRENGTH, nWIS));
return;
}
else
{
    eBolt = EffectDamage(nDamage, DAMAGE_TYPE_POSITIVE);
    effect eVis = EffectVisualEffect(VFX_IMP_MAGBLUE);
    effect eVis1 = EffectVisualEffect(VFX_DUR_SPELL_DAZE);
effect eVis2 = EffectLinkEffects(eVis, eVis1);
eSide = ExtraordinaryEffect(EffectDazed());
return;
}
 
if (spellsIsTarget(oTarget, SPELL_TARGET_STANDARDHOSTILE, OBJECT_SELF))
{
        //Fire cast spell at event for the specified target
        SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, 424));
if (nTouch != TOUCH_ATTACK_RESULT_MISS)
       //Make SR Check
       if(!MyResistSpell(OBJECT_SELF, oTarget))
       {
           //Set damage effect
int nDamage = (d10(1) + (nWIS + nCasterLevel/2));
nDamage = ApplyMetamagicVariableMods(nDamage, 3);
if (nTouch == TOUCH_ATTACK_RESULT_CRITICAL && !GetIsImmune(oTarget, IMMUNITY_TYPE_CRITICAL_HIT))
{
nDamage = nDamage*2;
nDamage = ApplyMetamagicVariableMods(nDamage, 6);
}
            ApplyEffectToObject(DURATION_TYPE_INSTANT, eBolt, oTarget);
            ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis2, oTarget);
            ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eSide, oTarget, RoundsToSeconds(nWIS));
}
}
    }
    ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oTarget);
}


#2
kevL

kevL
  • Members
  • 4 075 messages
... the variables eVis/1/2 are being "shadowed".

you've declared them outside the IsEvil() check, then redeclared them inside the IsEvil() check. The scope in which they are actually used, however, uses the former (where they have no definitions).

Also, IsEvil() is checking GetPCSpeaker() for alignment ... that's not proper in a spellscript.

ah, the reason it won't work is because there were returns in the alignment checks.

rewrite:
#include "x2_inc_spellhook"
#include "nwn2_inc_spells"


// ___________
// ** MAIN ***
// -----------
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


    object oTarget = GetSpellTargetObject();

    int bEvil = (GetAlignmentGoodEvil(OBJECT_SELF) == ALIGNMENT_EVIL);

    int iVis;
    if (bEvil) iVis = VFX_IMP_NEGATIVE_ENERGY;
    else       iVis = VFX_IMP_MAGBLUE;

    effect eVis = EffectVisualEffect(iVis);
    ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oTarget);


    if (spellsIsTarget(oTarget, SPELL_TARGET_STANDARDHOSTILE, OBJECT_SELF))
    {
        SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, SPELL_ACID_SPLASH)); // <- change to row# in Spells.2da

        int iTouch = TouchAttackRanged(oTarget);
        if (iTouch != TOUCH_ATTACK_RESULT_MISS && MyResistSpell(OBJECT_SELF, oTarget) == FALSE)
        {
            int iCL = GetCasterLevel(OBJECT_SELF);
            int iWis = GetAbilityModifier(ABILITY_WISDOM, OBJECT_SELF);
            int iBase = iCL / 2 + iWis;
            int iDamage = iBase + d10();
            iDamage = ApplyMetamagicVariableMods(iDamage, iBase + 10);

            if (iTouch == TOUCH_ATTACK_RESULT_CRITICAL && !GetIsImmune(oTarget, IMMUNITY_TYPE_CRITICAL_HIT))
                iDamage *= 2;

            int iBolt;
            effect eSide;
            if (bEvil)
            {
                iBolt = DAMAGE_TYPE_NEGATIVE;

                iVis = VFX_DUR_SPELL_ENERGY_DRAIN;
                eSide = EffectAbilityDecrease(ABILITY_STRENGTH, iWis);
            }
            else
            {
                iBolt = DAMAGE_TYPE_POSITIVE;

                iVis = VFX_DUR_SPELL_DAZE;
                eSide = EffectDazed();
            }

            effect eBolt = EffectDamage(iDamage, iBolt);
            ApplyEffectToObject(DURATION_TYPE_INSTANT, eBolt, oTarget);

            eVis  = EffectVisualEffect(iVis);
            eSide = EffectLinkEffects(eVis, eSide);
            eSide = ExtraordinaryEffect(eSide);

            ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eSide, oTarget, RoundsToSeconds(iWis));
        }
    }
}


#3
Laugh out loud

Laugh out loud
  • Members
  • 117 messages

Thanks,

 

I have never had any form of training.  I am self-taught and use a book for reference so, I do not truly know when and when not to use "returns".  I used them because Lilac Soul's Script Generator used them when I checked it for the starting conditional.



#4
kevL

kevL
  • Members
  • 4 075 messages
ah. "return" bypasses the rest of a function ( if code-flow actually hits it ). Think of "return" as an early out, "no more to do here".

#5
Laugh out loud

Laugh out loud
  • Members
  • 117 messages

For some reason the script is still not producing a ranged touch attack.  Is there something that I need to do on the feats.2da or spells.2da files?



#6
kevL

kevL
  • Members
  • 4 075 messages
what you mean? Is there no ranged graphic effect, or is the script not firing at all, or ...?

#7
Laugh out loud

Laugh out loud
  • Members
  • 117 messages

According to the dialog/text box at the bottom of the screen (during play) there is no roll to hit the target.  You get the script that starts to cast the spell and the one that signifies that the spell has been cast but there is none to display a "to hit" roll has occurred.

 

There are ranged graphics showing the spell being cast at the target but no "to hit" roll.



#8
kevL

kevL
  • Members
  • 4 075 messages
i just tested the script by replacing Acid Splash's ImpactScript w/ the one above. It worked fine and i got a hit roll w/ critical.

definitely using the new script 'cause it did 30 pts (level 15 wizard).

The only thing in the script that could be stopping a hitroll is if target is not SPELL_TARGET_STANDARDHOSTILE. Or there might be something in Spells.2da that affects it, unsure -- recheck your custom row against the Acid Splash entry ....


note if it's not a feat then Feat.2da has no effect.

#9
Laugh out loud

Laugh out loud
  • Members
  • 117 messages

Thanks,

 

I removed the projectile animation from the spells.2da file and now it works fine. I noticed that other ranged touch attack spells (acid splash, ray of enfeeblement, ray of frost,etc.) do not have projectile animations soI removed mine and now it works fine.

 

Thank you for your help,



#10
kevL

kevL
  • Members
  • 4 075 messages
oops I noticed a faux pas in the script i wrote.

viz. iWis could be 0 or negative ...


handled ->
#include "x2_inc_spellhook"
#include "nwn2_inc_spells"


// ___________
// ** MAIN ***
// -----------
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


    object oTarget = GetSpellTargetObject();

    int bEvil = (GetAlignmentGoodEvil(OBJECT_SELF) == ALIGNMENT_EVIL);

    int iVis;
    if (bEvil) iVis = VFX_IMP_NEGATIVE_ENERGY;
    else       iVis = VFX_IMP_MAGBLUE;

    effect eVis = EffectVisualEffect(iVis);
    ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oTarget);


    if (spellsIsTarget(oTarget, SPELL_TARGET_STANDARDHOSTILE, OBJECT_SELF))
    {
        SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, SPELL_ACID_SPLASH)); // <- change to row# in Spells.2da

        int iTouch = TouchAttackRanged(oTarget);
        if (iTouch != TOUCH_ATTACK_RESULT_MISS && MyResistSpell(OBJECT_SELF, oTarget) == FALSE)
        {
            int iCL = GetCasterLevel(OBJECT_SELF);
            int iWis = GetAbilityModifier(ABILITY_WISDOM, OBJECT_SELF);
            int iBase = iCL / 2 + iWis;
            int iDamage = iBase + d10();

            iDamage = ApplyMetamagicVariableMods(iDamage, iBase + 10);
            if (iDamage > 0)
            {
                if (iTouch == TOUCH_ATTACK_RESULT_CRITICAL && !GetIsImmune(oTarget, IMMUNITY_TYPE_CRITICAL_HIT))
                    iDamage *= 2;

                int iBolt;
                if (bEvil) iBolt = DAMAGE_TYPE_NEGATIVE;
                else       iBolt = DAMAGE_TYPE_POSITIVE;

                effect eBolt = EffectDamage(iDamage, iBolt);
                ApplyEffectToObject(DURATION_TYPE_INSTANT, eBolt, oTarget);
            }

            if (iWis > 0)
            {
                effect eSide;
                if (bEvil)
                {
                    iVis = VFX_DUR_SPELL_ENERGY_DRAIN;
                    eSide = EffectAbilityDecrease(ABILITY_STRENGTH, iWis);
                }
                else
                {
                    iVis = VFX_DUR_SPELL_DAZE;
                    eSide = EffectDazed();
                }

                eVis  = EffectVisualEffect(iVis);
                eSide = EffectLinkEffects(eVis, eSide);
                eSide = ExtraordinaryEffect(eSide);

                ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eSide, oTarget, RoundsToSeconds(iWis));
            }
        }
    }
}


#11
Laugh out loud

Laugh out loud
  • Members
  • 117 messages

Thanks for the double-check