Aller au contenu

Photo

GetIsDivineSpell() - Does it Exist?


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

#1
Thayan

Thayan
  • Members
  • 244 messages
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.

#2
The Amethyst Dragon

The Amethyst Dragon
  • Members
  • 1 882 messages
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 .


#3
Thayan

Thayan
  • Members
  • 244 messages
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!

#4
WhiZard

WhiZard
  • Members
  • 1 204 messages
AD, Get2DAString returns a null string if the field value is ****.

#5
painofdungeoneternal

painofdungeoneternal
  • Members
  • 1 799 messages
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 .


#6
WhiZard

WhiZard
  • Members
  • 1 204 messages
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 .


#7
WhiZard

WhiZard
  • Members
  • 1 204 messages
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 .


#8
The Amethyst Dragon

The Amethyst Dragon
  • Members
  • 1 882 messages
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.