Author Topic: Caster Level of Items  (Read 964 times)

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Caster Level of Items
« Reply #15 on: January 17, 2012, 06:22:10 pm »


               yea to get correct DC in this exact case is a bit difficult, try this:

#include "x2_i0_spells"
int GetDCBonusFromFeats(string sSchool, object oCaster);

void main()
{
object oCaster = OBJECT_SELF;
object oItem = GetSpellCastItem();
int nSpellId = GetSpellId();
int casterLevel = GetCasterLevel(oCaster);
 if(oItem != OBJECT_INVALID && GetBaseItemType(oItem) != BASE_ITEM_POTIONS && GetBaseItemType(oItem) != BASE_ITEM_ENCHANTED_POTION)
 {//spell cast from item
 string sInnate;
 int nInnate;
 int bestLevel, reqLevel;
 int nLevel = GetLevelByclass(class_TYPE_BARD,oCaster);
  if(nLevel > 0)
  {
  sInnate = Get2DAString("spells","Bard",nSpellId);
  nInnate = StringToInt(sInnate);
   if(nInnate == 0 && sInnate == "0" || nInnate > 0)
   {
   reqLevel = nInnate*2;
    if(nLevel >= reqLevel && nLevel > bestLevel)
    {
    bestLevel = nLevel;
    }
   }
  }
nLevel = GetLevelByclass(class_TYPE_CLERIC,oCaster);
  if(nLevel > 0)
  {
  sInnate = Get2DAString("spells","Cleric",nSpellId);
  nInnate = StringToInt(sInnate);
   if(nInnate == 0 && sInnate == "0" || nInnate > 0)
   {
   reqLevel = (nInnate*2)-1;
    if(nLevel >= reqLevel && nLevel > bestLevel)
    {
    bestLevel = nLevel;
    }
   }
  }
nLevel = GetLevelByclass(class_TYPE_DRUID,oCaster);
  if(nLevel > 0)
  {
  sInnate = Get2DAString("spells","Druid",nSpellId);
  nInnate = StringToInt(sInnate);
   if(nInnate == 0 && sInnate == "0" || nInnate > 0)
   {
   reqLevel = (nInnate*2)-1;
    if(nLevel >= reqLevel && nLevel > bestLevel)
    {
    bestLevel = nLevel;
    }
   }
  }
nLevel = GetLevelByclass(class_TYPE_PALADIN,oCaster);
  if(nLevel > 0)
  {
  sInnate = Get2DAString("spells","Paladin",nSpellId);
  nInnate = StringToInt(sInnate);
   if(nInnate == 0 && sInnate == "0" || nInnate > 0)
   {
   reqLevel = nInnate*3+(nInnate > 1 ? 2 : 1);
    if(nLevel >= reqLevel && nLevel > bestLevel)
    {
    bestLevel = nLevel;
    }
   }
  }
nLevel = GetLevelByclass(class_TYPE_RANGER,oCaster);
  if(nLevel > 0)
  {
  sInnate = Get2DAString("spells","Ranger",nSpellId);
  nInnate = StringToInt(sInnate);
   if(nInnate == 0 && sInnate == "0" || nInnate > 0)
   {
   reqLevel = nInnate*3+(nInnate > 1 ? 2 : 1);
    if(nLevel >= reqLevel && nLevel > bestLevel)
    {
    bestLevel = nLevel;
    }
   }
  }
nLevel = GetLevelByclass(class_TYPE_WIZARD,oCaster);
  if(nLevel > 0)
  {
  sInnate = Get2DAString("spells","Wiz_Sorc",nSpellId);
  nInnate = StringToInt(sInnate);
   if(nInnate == 0 && sInnate == "0" || nInnate > 0)
   {
   reqLevel = (nInnate*2)-1;
    if(nLevel >= reqLevel && nLevel > bestLevel)
    {
    bestLevel = nLevel;
    }
   }
  }
nLevel = GetLevelByclass(class_TYPE_SORCERER,oCaster);
  if(nLevel > 0)
  {
  sInnate = Get2DAString("spells","Wiz_Sorc",nSpellId);
  nInnate = StringToInt(sInnate);
   if(nInnate == 0 && sInnate == "0" || nInnate > 0)
   {
   reqLevel = nInnate*2;
    if(nLevel >= reqLevel && nLevel > bestLevel)
    {
    bestLevel = nLevel;
    }
   }
  }
  if(bestLevel > casterLevel)
  {
  SetLocalInt(oItem,"ITEM_CASTER_LEVEL_OVERRIDE",bestLevel);
  SendMessageToPC(oCaster,"DEBUG: caster level overriden: "+IntToString(bestLevel));
  }
 int nDC = GetSpellSaveDC()-3;//by default DC is 13+innate, normal DC should be 10+innate+caster ability+feats
 nDC+= GetCasterAbilityModifier(oCaster);
 string sSchool = Get2DAString("spells","School",nSpellId);
 nDC+= GetDCBonusFromFeats(sSchool,oCaster);
 SetLocalInt(oItem,"ITEM_DC_OVERRIDE",nDC);
 SendMessageToPC(oCaster,"DEBUG: spell DC overriden: "+IntToString(nDC));
 }
}


int GetDCBonusFromFeats(string sSchool, object oCaster)
{
  if(sSchool == "A")
  {
   if(GetHasFeat(FEAT_EPIC_SPELL_FOCUS_ABJURATION,oCaster))
   {
   return 6;
   }
   else if(GetHasFeat(FEAT_GREATER_SPELL_FOCUS_ABJURATION,oCaster))
   {
   return 4;
   }
   else if(GetHasFeat(FEAT_SPELL_FOCUS_ABJURATION,oCaster))
   {
   return 2;
   }
  }
  else if(sSchool == "C")
  {
   if(GetHasFeat(FEAT_EPIC_SPELL_FOCUS_CONJURATION,oCaster))
   {
   return 6;
   }
   else if(GetHasFeat(FEAT_GREATER_SPELL_FOCUS_CONJURATION,oCaster))
   {
   return 4;
   }
   else if(GetHasFeat(FEAT_SPELL_FOCUS_CONJURATION,oCaster))
   {
   return 2;
   }
  }
  else if(sSchool == "D")
  {
   if(GetHasFeat(FEAT_EPIC_SPELL_FOCUS_DIVINATION,oCaster))
   {
   return 6;
   }
   else if(GetHasFeat(FEAT_GREATER_SPELL_FOCUS_DIVINATION,oCaster))
   {
   return 4;
   }
   else if(GetHasFeat(FEAT_SPELL_FOCUS_DIVINATION,oCaster))
   {
   return 2;
   }
  }
  else if(sSchool == "E")
  {
   if(GetHasFeat(FEAT_EPIC_SPELL_FOCUS_ENCHANTMENT,oCaster))
   {
   return 6;
   }
   else if(GetHasFeat(FEAT_GREATER_SPELL_FOCUS_ENCHANTMENT,oCaster))
   {
   return 4;
   }
   else if(GetHasFeat(FEAT_SPELL_FOCUS_ENCHANTMENT,oCaster))
   {
   return 2;
   }
  }
  else if(sSchool == "V")
  {
   if(GetHasFeat(FEAT_EPIC_SPELL_FOCUS_EVOCATION,oCaster))
   {
   return 6;
   }
   else if(GetHasFeat(FEAT_GREATER_SPELL_FOCUS_EVOCATION,oCaster))
   {
   return 4;
   }
   else if(GetHasFeat(FEAT_SPELL_FOCUS_EVOCATION,oCaster))
   {
   return 2;
   }
  }
  else if(sSchool == "I")
  {
   if(GetHasFeat(FEAT_EPIC_SPELL_FOCUS_ILLUSION,oCaster))
   {
   return 6;
   }
   else if(GetHasFeat(FEAT_GREATER_SPELL_FOCUS_ILLUSION,oCaster))
   {
   return 4;
   }
   else if(GetHasFeat(FEAT_SPELL_FOCUS_ILLUSION,oCaster))
   {
   return 2;
   }
  }
  else if(sSchool == "N")
  {
   if(GetHasFeat(FEAT_EPIC_SPELL_FOCUS_NECROMANCY,oCaster))
   {
   return 6;
   }
   else if(GetHasFeat(FEAT_GREATER_SPELL_FOCUS_NECROMANCY,oCaster))
   {
   return 4;
   }
   else if(GetHasFeat(FEAT_SPELL_FOCUS_NECROMANCY,oCaster))
   {
   return 2;
   }
  }
  else if(sSchool == "T")
  {
   if(GetHasFeat(FEAT_EPIC_SPELL_FOCUS_TRANSMUTATION,oCaster))
   {
   return 6;
   }
   else if(GetHasFeat(FEAT_GREATER_SPELL_FOCUS_TRANSMUTATION,oCaster))
   {
   return 4;
   }
   else if(GetHasFeat(FEAT_SPELL_FOCUS_TRANSMUTATION,oCaster))
   {
   return 2;
   }
  }
return 0;
}


               
               

               


                     Modifié par ShaDoOoW, 17 janvier 2012 - 06:22 .
                     
                  


            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Caster Level of Items
« Reply #16 on: January 17, 2012, 06:35:07 pm »


               btw if you want this to be done in all modules I just published betaversion of patch 1.71 that should be able to allow it: Basically to do it you need to get 71_spellhook script and put the script I wrote for you in there (which won't be very easy though). But since I like yours idea I can help you with that if you decided to try this.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Caster Level of Items
« Reply #17 on: January 17, 2012, 11:49:21 pm »


               

ShaDoOoW wrote...

Lightfoot8 wrote...

We all know that I am not that much
into the spell system. However for them that are. would it not be
simple enough to just Hook the spell and if it is cast from an item.
Stop the spell from casting and then assign it to the caster to cast
with the bCheat and bInstantSpell both set to TRUE?

not at all, what OP want cannot be done via spellhook without community patch 1.70 or changes into all spells as described upwards - actioncastspell with bCheat has its own caster level which is static (10 in most cases)



Could you explain why it would not work?  I tried a simple override,  and it seemed to work just fine.   Of cource it will only take into account spells have a target currently, but that could be modified.   Here is the SpellOverride I used.

#include "x2_inc_switches"
void main()
{
  if (GetSpellCastItem() != OBJECT_INVALID)
  {
     ActionCastSpellAtObject(
                              GetSpellId(),
                              GetSpellTargetObject(),
                              METAMAGIC_ANY,
                              TRUE,0,
                              PROJECTILE_PATH_TYPE_DEFAULT,
                              TRUE
                            );
     SetModuleOverrideSpellScriptFinished();
  }
}

EDIT:The spell I tested it with was Magic missial. 
               
               

               


                     Modifié par Lightfoot8, 17 janvier 2012 - 11:50 .
                     
                  


            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Caster Level of Items
« Reply #18 on: January 18, 2012, 12:06:21 am »


               

Lightfoot8 wrote...
Could you explain why it would not work?  I tried a simple override,  and it seemed to work just fine.   Of cource it will only take into account spells have a target currently, but that could be modified.   Here is the SpellOverride I used.


The caster level used by cheat cast spells is 2 * innate level - 1 (minimum 10).  Innate level is taken from spells.2da.
               
               

               
            

Legacy_Badwater

  • Full Member
  • ***
  • Posts: 220
  • Karma: +0/-0
Caster Level of Items
« Reply #19 on: January 18, 2012, 01:14:29 am »


               

ShaDoOoW wrote...

yes, you have more choices:

...

3) using unofficial 1.70 patch, you can set variables on the item which can change the caster level/metamagic/DC for all spells cast from this item:
ITEM_CASTER_LEVEL_OVERRIDE / int / new caster level
ITEM_METAMAGIC_OVERRIDE / int / override metamagic, values match NWscript constants
ITEM_DC_OVERRIDE / int / overrides DC


Am I correct in assuming that setting the Metamagic Override to 1 is the override integer?
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Caster Level of Items
« Reply #20 on: January 18, 2012, 01:49:13 am »


               

Badwater wrote...

ShaDoOoW wrote...

yes, you have more choices:

...

3) using unofficial 1.70 patch, you can set variables on the item which can change the caster level/metamagic/DC for all spells cast from this item:
ITEM_CASTER_LEVEL_OVERRIDE / int / new caster level
ITEM_METAMAGIC_OVERRIDE / int / override metamagic, values match NWscript constants
ITEM_DC_OVERRIDE / int / overrides DC


Am I correct in assuming that setting the Metamagic Override to 1 is the override integer?

from nwscript.nss:

int    METAMAGIC_EMPOWER        = 1;
int    METAMAGIC_EXTEND         = 2;
int    METAMAGIC_MAXIMIZE       = 4;

so if you are setting these values manually on item in toolset variables window you need values of 1 for empower 2 for extend and 4 for maximize. Other metamagic doesn't have any effect.

If you are setting this feature from script you can use NWScript constant like this
SetLocalInt(oItem,"ITEM_METAMAGIC_OVERRIDE",METAMAGIC_MAXIMIZE);
               
               

               


                     Modifié par ShaDoOoW, 18 janvier 2012 - 01:57 .
                     
                  


            

Legacy_AharonShaw

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
Caster Level of Items
« Reply #21 on: January 19, 2012, 02:31:21 pm »


               @ShaDoOoW
currently, I'm more interested in playing than scripting '<img'> Both your patch and your script work perfectly, thank you very much!