Author Topic: GetIsDivineSpell() - Does it Exist?  (Read 390 times)

Legacy_Thayan

  • Sr. Member
  • ****
  • Posts: 435
  • Karma: +0/-0
GetIsDivineSpell() - Does it Exist?
« on: July 15, 2013, 09:10:59 pm »


               I'm wondering if anyone has developed a way to determine if a spell being cast is a Divine or an Arcane spell? I know all about the module spellhook which could be used as the event/script to do the check, but I'm not aware of any function or method which exists that can be used to determine of the spell is an arcane or divine spell.
               
               

               
            

Legacy_The Amethyst Dragon

  • Hero Member
  • *****
  • Posts: 2981
  • Karma: +0/-0
GetIsDivineSpell() - Does it Exist?
« Reply #1 on: July 15, 2013, 09:24:31 pm »


               It doesn't exist normally, but it's not a difficult function to create.


// Returns TRUE if the spell cast is a divine spell
// nSpellID = line number of the spell in spells.2da ( use GetSpellId() )
// nCasterClass = class used to cast the spell ( use GetLastSpellCastClass() )
int GetIsDivineSpell(int nSpellID, int nCasterClass);
int GetIsDivineSpell(int nSpellID, int nCasterClass)
{
int nReturn = FALSE;
object oCaster = GetSpellCastItem();
if (nCasterClass != CLASS_TYPE_CLERIC &&
    nCasterClass != CLASS_TYPE_DRUID &&
    nCasterClass != CLASS_TYPE_PALADIN &&
    nCasterClass != CLASS_TYPE_RANGER)
    {
    return FALSE;
    }
string sCasterClass = "Cleric";
if (nCasterClass == CLASS_TYPE_DRUID) { sCasterClass = "Druid"; }
else if (nCasterClass == CLASS_TYPE_PALADIN) { sCasterClass = "Paladin"; }
else if (nCasterClass == CLASS_TYPE_RANGER) { sCasterClass = "Ranger"; }
int nCheck2DA = StringToInt(Get2DAString("spells", sCasterClass, nSpellID));
if (nCheck2DA >= 0 && nCheck2DA < 10)
   {
   if (nCheck2DA == 0)
      {
      if (nSpellID == SPELL_CURE_MINOR_WOUNDS ||
          nSpellID == SPELL_INFLICT_MINOR_WOUNDS ||
          nSpellID == SPELL_LIGHT ||
          nSpellID == SPELL_RESISTANCE ||
          nSpellID == SPELL_VIRTUE)
         {
         nReturn = TRUE;
         }
      else { nReturn = FALSE; }
      }
   else { nReturn = TRUE; }
   }
return nReturn;
}

               
               

               


                     Modifié par The Amethyst Dragon, 16 juillet 2013 - 02:53 .
                     
                  


            

Legacy_Thayan

  • Sr. Member
  • ****
  • Posts: 435
  • Karma: +0/-0
GetIsDivineSpell() - Does it Exist?
« Reply #2 on: July 15, 2013, 10:31:47 pm »


               Oh nice! Checking if there's a value in the Cleric/Druid/Paladin/Ranger columns of the spells.2da is a very clever way to do that. I had not thought of that, and this looks like it will work splendidly.

Many thanks, Mr. Gem Dragon!
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
GetIsDivineSpell() - Does it Exist?
« Reply #3 on: July 15, 2013, 10:42:05 pm »


               AD, Get2DAString returns a null string if the field value is ****.
               
               

               
            

Legacy_painofdungeoneternal

  • Sr. Member
  • ****
  • Posts: 313
  • Karma: +0/-0
GetIsDivineSpell() - Does it Exist?
« Reply #4 on: July 15, 2013, 10:56:39 pm »


               true ( unless someone mucks up that blank line at the top of 2da's )

Wouldn't you just check to see if the "GetLastSpellCastClass" is a divine class?  I'd think this would mean domain bonus spells might be arcane spells, which probably should not be the case for a cleric casting invisibility from the trickery domain. You'd only have to check the 2da IF the spell is coming from a scroll like when a rogue is casting it.

Just asking...

( i did some of this for NWN2, and used a lot of things from the spell compendium and spell casting framework which tackled this, seem to remember it being in the PRC as well, might be confused by differences between the two games )
               
               

               


                     Modifié par painofdungeoneternal, 15 juillet 2013 - 09:59 .
                     
                  


            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
GetIsDivineSpell() - Does it Exist?
« Reply #5 on: July 15, 2013, 11:16:21 pm »


               It shouldn't revert to arcane.  If the spell is cast by a non-default method (e.g. as a polymorph ability), GetLastSpellCastClass() would use the initial class (class taken at character generation) of the character.
               
               

               


                     Modifié par WhiZard, 15 juillet 2013 - 10:17 .
                     
                  


            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
GetIsDivineSpell() - Does it Exist?
« Reply #6 on: July 15, 2013, 11:49:49 pm »


               Info on GetLastSpellCastClass()
Spells cast from a spellbook (including domain spells and quickslots of the spellbook used in combination with a polymorph) are treated as cast by that class.
Spells cast from a polymorph's spell menu are treated as from the initial class of the character.
Spells cast from a scroll or item (including on-hit cast spell), spells cast as a feat, and NPC spells not assigned to a spellbook return 255 (CLASS_TYPE_INVALID).

EDIT: added the feat and NPC cases
               
               

               


                     Modifié par WhiZard, 15 juillet 2013 - 11:22 .
                     
                  


            

Legacy_The Amethyst Dragon

  • Hero Member
  • *****
  • Posts: 2981
  • Karma: +0/-0
GetIsDivineSpell() - Does it Exist?
« Reply #7 on: July 16, 2013, 03:52:41 am »


               Changed original function from checking for a string to checking for an integer (converted from the 2da string) and to account for standard 0-level spells.

The other alternative (simpler, but a bit more work) would be to make a function that includes a list of all divine spells (listed by constant or spell ID), then just check against that. If you're still using just the default spells, here's lists: NWN Cleric Spells, Druid Spells, Paladin Spells, Ranger Spells.