Author Topic: Need to Hook into Spell Resistance  (Read 1716 times)

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Need to Hook into Spell Resistance
« Reply #15 on: August 26, 2011, 04:04:26 pm »


               

ShaDoOoW wrote...

??? dont understand first part again

for speed, monk speed feat is just a placeholder it has no effect on character


I've haven't tested but I have heard it reported otherwise, one instance on NWNwiki under "monk speed".
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Need to Hook into Spell Resistance
« Reply #16 on: August 26, 2011, 04:06:32 pm »


               Actually to get around monk SR (though the SR check will report this wrong) is simply to make the roll manually and then instead of using

if(!ResistSpell())

use

if(!(ResistSpell() > 1))

instead.
               
               

               


                     Modifié par WhiZard, 26 août 2011 - 03:07 .
                     
                  


            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Need to Hook into Spell Resistance
« Reply #17 on: August 26, 2011, 05:17:21 pm »


               This might be a helpful function to use for custom SR checks.  The spell resistance part comes before the spell level absorption.


int DoResistSpell(object oCaster, object oTarget, int nCaster = -100)
{
if(nCaster == -100) nCaster = GetCasterLevel(oCaster);  //Allows preset caster level
int nRoll = nCaster + d20();
int nSR = GetSpellResistance(oTarget);
if(GetHasFeat(FEAT_EPIC_SPELL_PENETRATION, oCaster)) nRoll += 6;
else if(GetHasFeat(FEAT_GREATER_SPELL_PENETRATION, oCaster)) nRoll += 4;
else if(GetHasFeat(FEAT_SPELL_PENETRATION, oCaster)) nRoll +=2;
if(nRoll >= nSR || !nSR)  //0 SR opponents get hit
  {
  FloatingTextStringOnCreature("Spell resistance: spell resisted", oCaster, FALSE);
  FloatingTextStringOnCreature("Spell resistance: spell resisted", oTarget, FALSE);
  return 1;
  }
int nResist = ResistSpell(oCaster, oTarget);
if(nResist == 1)
  {
  FloatingTextStringOnCreature("Spell bypassed resistance", oCaster, FALSE);
  FloatingTextStringOnCreature("Spell bypassed resistance", oTarget, FALSE);
  nResist = 0;
  }
return nResist;
}
               
               

               


                     Modifié par WhiZard, 26 août 2011 - 04:18 .
                     
                  


            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Need to Hook into Spell Resistance
« Reply #18 on: August 26, 2011, 05:31:35 pm »


               Right, this is the PRC solution I just forgot that they return 0 in case that second SR block the spell, still those two feedback which are not multi languaged seemed and still seems to me like a worse downside.
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Need to Hook into Spell Resistance
« Reply #19 on: August 26, 2011, 05:36:19 pm »


               

ShaDoOoW wrote...

Right, this is the PRC solution I just forgot that they return 0 in case that second SR block the spell, still those two feedback which are not multi languaged seemed and still seems to me like a worse downside.


You could add it to a TLK file to make it multilingual.

EDIT: found line 8342 in TLK <CUSTOM 0> attempts to resist spell <CUSTOM 1>
<CUSTOM 1> uses 8343, 8344, or 8345 for resist, immunity, or absorption.
               
               

               


                     Modifié par WhiZard, 26 août 2011 - 04:49 .
                     
                  


            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Need to Hook into Spell Resistance
« Reply #20 on: August 26, 2011, 06:40:32 pm »


               I cant use new lines in TLK for reasons I already explained. Also you cannot set custom token 0 and 1.
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Need to Hook into Spell Resistance
« Reply #21 on: August 27, 2011, 01:11:48 am »


               

ShaDoOoW wrote...

I cant use new lines in TLK for reasons I already explained. Also you cannot set custom token 0 and 1.


Looked into this and you can "set" both manually simply by replacing that part of the string.  (E.g. "<....0>" can be replaced with a name and "<...1>" can be replaced with the string resrefs above, and this works for any language.
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Need to Hook into Spell Resistance
« Reply #22 on: August 27, 2011, 01:41:42 am »


               Just if this needs to be referred to later 5353 is the english TLK line for "failure"
               
               

               


                     Modifié par WhiZard, 27 août 2011 - 12:42 .
                     
                  


            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Need to Hook into Spell Resistance
« Reply #23 on: August 27, 2011, 01:51:54 am »


               So what would happen if I did this?

//if(!ResistSpell())
DoCustomSRCheck(oPC, oTarget);

And ran my own custom checks, if passed, "apply" the spell effects, no resistance should be checked at all correct?
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Need to Hook into Spell Resistance
« Reply #24 on: August 27, 2011, 01:57:05 am »


               

_Guile wrote...

So what would happen if I did this?

//if(!ResistSpell())
DoCustomSRCheck(oPC, oTarget);

And ran my own custom checks, if passed, "apply" the spell effects, no resistance should be checked at all correct?

Yes getting rid of ResistSpell() would do that, however, spell level absorption and spell immunity would be problematic to check.
               
               

               
            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Need to Hook into Spell Resistance
« Reply #25 on: August 27, 2011, 01:59:59 am »


               So you are saying if I chucked out the SR Check function then those two checks would STILL be checked or would NOT be checked because I chucked out the original SR Check?

I'm not interested in getting rid of the checks for those two, I'm only interested in running my own SR Check, so if those two checks would die, then I would prefer to just ditch the entire project.
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Need to Hook into Spell Resistance
« Reply #26 on: August 27, 2011, 02:08:54 am »


               

_Guile wrote...

So you are saying if I chucked out the SR Check function then those two checks would STILL be checked or would NOT be checked because I chucked out the original SR Check?

I'm not interested in getting rid of the checks for those two, I'm only interested in running my own SR Check, so if those two checks would die, then I would prefer to just ditch the entire project.


Without the SR function they would not be checked.  But look at my posts above for incorporating ResistSpell() with a custom SR roll.  The only draw back (once the TLK lines are used)  is that "... attempts to resist spell : failure" may occassionally show up after "... attempts to resist spell : spell resisted" if the custom SR roll shows failure, but resist spell thinks otherwise.

EDIT The occurrence of the double line may also be mitigated if the underwent a temporary decrease by its current magnitude (i.e. all but monks would have an SR of 0 and thus the non-monks would never have the double line).
               
               

               


                     Modifié par WhiZard, 27 août 2011 - 01:30 .
                     
                  


            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Need to Hook into Spell Resistance
« Reply #27 on: August 27, 2011, 02:41:21 am »


               OK, forget it then I'm just leaving SR alone, I don't feel like doing that much work anyway, thanks.
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Need to Hook into Spell Resistance
« Reply #28 on: August 27, 2011, 02:57:32 am »


               You would need to replace SR code with your own. Here's ours, which is modified from the PRCs, if memory serves, and handles all functionality properly:


int GetSpellResisted (struct SpellInfo si, object oTarget=OBJECT_INVALID, float fDelay=0.0, int bSROnly=FALSE) {
    int nSR = 0, nResisted = 0, nRoll = 0;

    if (!GetIsObjectValid(oTarget))
        oTarget = si.target;
    if (!GetIsObjectValid(oTarget))
        return 0;

    if (GetObjectType(oTarget) == OBJECT_TYPE_CREATURE)
        nSR = GetSpellResistance(oTarget);
    else
        nSR = GetLocalInt(oTarget, "SR");


    if (nSR > 0 && GetHasSpellImmunity(SPELL_SPELL_RESISTANCE, oTarget)) {
        nSR -= GetLocalInt(oTarget, "TauntResult");
        if (nSR < 1)
            nSR = 1;
    }


    if (nSR > 0 && si.sp >= 0 && !GetFactionEqual(si.caster, oTarget)) {
        nRoll = d20(1);

        if (si.sp + nRoll < nSR)
            nResisted = 1;
    }

    if (nResisted == 0) {
        if (bSROnly) {
            if (bSROnly == 2 && GetHasSpellImmunity(si.id, oTarget))
                nResisted = 2;
        } else {
            switch (ResistSpell(si.caster, oTarget)) {
                case 2:  /* globe or spell immunity */
                    nResisted = 2;
                    break;
                case 3:  /* spell mantle */
                    if (si.sp >= 0)
                        nResisted = 3;
                    break;
            }
        }
    }

    if (!nResisted) {
        if (nRoll > 0)
            SendSpellResistanceMessage(si.caster, oTarget, nRoll, si.sp, nSR, fDelay);

        return 0;
    }

    if (GetObjectType(oTarget) == OBJECT_TYPE_CREATURE) {
        effect eVis;

        switch (nResisted) {
            case 2:
                nSR  = -2;
                eVis = EffectVisualEffect(VFX_IMP_GLOBE_USE);
                break;
            case 3:
                nSR  = -3;
                eVis = EffectVisualEffect(VFX_IMP_SPELL_MANTLE_USE);
                break;
            default:
                eVis = EffectVisualEffect(VFX_IMP_MAGIC_RESISTANCE_USE);
                break;
        }

        DelayCommand(fDelay, ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oTarget));
    }

    if (nRoll > 0 || nSR < -1)
        SendSpellResistanceMessage(si.caster, oTarget, nRoll, si.sp, nSR, fDelay);

    return nResisted;
}

Funky
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Need to Hook into Spell Resistance
« Reply #29 on: August 27, 2011, 03:11:59 am »


               

FunkySwerve wrote...

You would need to replace SR code with your own. Here's ours, which is modified from the PRCs, if memory serves, and handles all functionality properly:

Funky


Does SR and specific spell immunity before mantles, but spell immunity by level and/or school after mantles.  Also does a double line for not making the custom SR roll but making the ResistSpell() roll.  Are its messages straight TLK lines?
               
               

               


                     Modifié par WhiZard, 27 août 2011 - 02:13 .