Author Topic: Checking a character for specific spell immunity?  (Read 438 times)

Legacy_MrZork

  • Hero Member
  • *****
  • Posts: 1643
  • Karma: +0/-0
Checking a character for specific spell immunity?
« on: April 20, 2012, 07:58:05 am »


               I want to check if a character is immune to the spell Drown. The immunity might come from an equipped item/skin, spell or non-spell scripted effect (e.g. from any script that uses
EffectSpellImmunity(SPELL_DROWN)
). More generally, I'd like to be able to determine if a creature has immunity to a specific spell.

This seems like it should be easy enough recoding something similar to
x0_i0_match
's
GetHasEffect()
and checking for
EFFECT_TYPE_SPELL_IMMUNITY
, but I realize I don't know how to get the spell subtype for that effect. In other words, I can check if a character has the effect
EFFECT_TYPE_SPELL_IMMUNITY
, but I don't know how to determine which specific spell it is immune to.

It seems like there is probably something analogous to the check one would make to see if an item property grants immunity from a specific spell. E.g. if I were looking for this as an objects item property, I might try:
  • Loop through the object's item properties.
  • For each one, check if
    GetItemPropertyType()
    returns
    ITEM_PROPERTY_IMMUNITY_SPECIFIC_SPELL
  • If so, check if
    GetItemPropertyCostTable()
    returns
    IPRP_SPELLCOST
  • If so, check if
    GetItemPropertyCostTableValue()
    returns 201 (the Drown entry from
    iprp_spellcost.2da
    )
Is there a similar way to check for effects on characters? Am I way off on how to go about this?

Thanks for any advice or pointers to another thread that covers this. :-)

[EDIT: It appears that list termination is broken on the boards.]
               
               

               


                     Modifié par MrZork, 20 avril 2012 - 07:05 .
                     
                  


            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Checking a character for specific spell immunity?
« Reply #1 on: April 20, 2012, 10:55:32 am »


               it isnt unless you can use NWNX which allows to get ID of the spell immunity

without it you must specifically search for effects spell id
               
               

               
            

Legacy_MrZork

  • Hero Member
  • *****
  • Posts: 1643
  • Karma: +0/-0
Checking a character for specific spell immunity?
« Reply #2 on: April 21, 2012, 03:31:50 am »


               Thanks for the reply, ShaDoOoW.

So, (without NWNX) there is no way to check for immunity from a specific spell that is granted by a non-spell script? :-(

(And, if I am reading correctly, there is no way to check for immunity to a specific spell gained from an item, except by looping through every item property of every equipped item on the character?)
               
               

               
            

Legacy_ShadowM

  • Hero Member
  • *****
  • Posts: 1373
  • Karma: +0/-0
Checking a character for specific spell immunity?
« Reply #3 on: April 21, 2012, 04:16:04 am »


               Hmm interesting, you could more then likely find a number of workarounds with OnPlayerEquipItem / OnPlyaerUnequipItem , spell hooking, custom functions.
               
               

               
            

Legacy_MrZork

  • Hero Member
  • *****
  • Posts: 1643
  • Karma: +0/-0
Checking a character for specific spell immunity?
« Reply #4 on: April 21, 2012, 10:26:56 pm »


               Thanks, ShadowM. I understand that there are several ways to generally test every item and spell that is cast, perhaps doing the bookkeeping for an bDrownProof local int that can be checked in the areas where this is an issue. There are potentially a couple problems with that approach. First, I was hoping to avoid the extra overhead of extra OnEquip scripts running all the time. Maybe that's not a big deal, but I worry about looping through all the properties on an item each time any item is equipped. Second, the drown is supposed to work on all creatures in the area, not just PCs. Does the equipping/unequipping script fire for non-PCs (including associates that the hostiles might summon)? I understood that it didn't work for non-PCs (the reason why Nasher's items in HotU don't work for henchmen), but I never double-checked if that's really true or if it can be changed.

At any rate, this isn't a huge issue in terms of the drowning situation, but I was hoping there would be a more reliable way of determining all of the effects extant on a given character.
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Checking a character for specific spell immunity?
« Reply #5 on: April 21, 2012, 11:49:35 pm »


               What might be easier is to force your scripted uses of anti-drown through a cheat-cast spell.  Then you can search for GetHasSpellEffect().  As far as item properties you should be able to manage by setting the variables on the item to limited the search through properties to once every time the locals are cleared (e.g. "VariablesSet" having a value of 1 would tell you not to loop through item properties and "Antidrown" having a value of 1 would tell you that item has a permanent anti-drown property on it).
               
               

               
            

Legacy_ShadowM

  • Hero Member
  • *****
  • Posts: 1373
  • Karma: +0/-0
Checking a character for specific spell immunity?
« Reply #6 on: April 22, 2012, 05:05:04 am »


               If you can give me some more info on your system I could give more specific examples. I have a custom function that check for water breathing creature/ has water breathing spell cast on them/ appearance type, subrace etc. that check the target of the drown spell and if return true does not affect them. Ran through the spell hooking system. Like Whizard I do it that way, I done it with other items. Something like "Spell_Immunity" (number of spell in the spell.2da) and then just do a spell hooking check. You could even have it if -1 immunity to all spells. Maybe only allow one spell immunity per equipped item then you can even set it up Spell_Immunity(number of slot) (number from spell.2da) That would handle multiple items with spell immunity. I do not know if you can add new immunities in the spell.2da with some 2da manipulation something I look in at a later time. Just some food for thought. Interesting subject
               
               

               
            

Legacy_MrZork

  • Hero Member
  • *****
  • Posts: 1643
  • Karma: +0/-0
Checking a character for specific spell immunity?
« Reply #7 on: April 23, 2012, 12:31:13 am »


               Thanks for those pointers, guys. WhiZard, cheat casting sounds like a good idea for the scripted effects. I was hoping not to have to modify the spell-related 2DA files (to allow spell mods in overrides to work), but that is a workable approach to the issue. I could even come up with a custom spell that reads some local variables from the caster to fine tune things like duration.

ShadowM, what I am doing now checks race, appearance, effects like ethereal, etc. The thing that was giving me trouble was items with specific spell immunity and items with scripted effects from item activation. As I said, the actual drowning issue is something I can work around, since I can have the scripted effects set a variable and there are a limited number of items to worry about.

The main point of curiosity for me was that this one task of detecting these anti-drown effects got me wondering if generally detecting an immunity to a specific spell was doable with normal scripting or if it would require rewriting the spell itself. It's kind of too bad that detecting EFFECT_TYPE_SPELL_IMMUNITY doesn't allow finishing the job and determining which spell the effect gives the character immunity to.
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Checking a character for specific spell immunity?
« Reply #8 on: April 23, 2012, 07:14:12 am »


               hm in this case its simple then, just use special effect creator for creating drown immunity from all unique power scripts and then check its tag
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Checking a character for specific spell immunity?
« Reply #9 on: April 23, 2012, 09:59:37 pm »


               

ShaDoOoW wrote...

hm in this case its simple then, just use special effect creator for creating drown immunity from all unique power scripts and then check its tag


If you mean GetEffectCreator() then that will return the user of the object not the object being used.

If you mean a separate creature/placeable being assigned the defining of the anti-drown effect in all cases, then that works.
               
               

               


                     Modifié par WhiZard, 23 avril 2012 - 09:03 .
                     
                  


            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Checking a character for specific spell immunity?
« Reply #10 on: April 23, 2012, 10:01:37 pm »


               Double post
               
               

               


                     Modifié par WhiZard, 23 avril 2012 - 09:01 .
                     
                  


            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Checking a character for specific spell immunity?
« Reply #11 on: April 24, 2012, 02:00:29 pm »


               

WhiZard wrote...

If you mean a separate creature/placeable being assigned the defining of the anti-drown effect in all cases, then that works.

this

I numerously suggested this way in past to several scripters. I would also gave Mr Zork link to example of how to use but this forum's search feature won't find anything:innocent:
               
               

               
            

Legacy_MrZork

  • Hero Member
  • *****
  • Posts: 1643
  • Karma: +0/-0
Checking a character for specific spell immunity?
« Reply #12 on: April 25, 2012, 01:27:59 am »


               Maybe one of these threads contains the example you mentioned?
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Checking a character for specific spell immunity?
« Reply #13 on: April 25, 2012, 10:15:55 am »


               yep, first one already and thanks for tip how to search '<img'>
               
               

               


                     Modifié par ShaDoOoW, 25 avril 2012 - 09:42 .
                     
                  


            

Legacy_MrZork

  • Hero Member
  • *****
  • Posts: 1643
  • Karma: +0/-0
Checking a character for specific spell immunity?
« Reply #14 on: April 26, 2012, 02:27:03 am »


               Cool. I will check into that thread.

You're welcome on the search tip. There are so many sites with essentially useless search features that using google to search them is a must. :-)
               
               

               


                     Modifié par MrZork, 26 avril 2012 - 01:33 .