From NWN Lexicon
Jump to: navigation, search

Determines the level of caster for a creature or PC casting a spell.

int GetCasterLevel(
    object oCreature


Creature or PC casting a spell.


Get the Caster Level of oCreature in a Spell Script or Area of Effect OnEnter, OnExit or OnHeartbeat. If the creature or PC is multiclassed, this function returns the level of the class used to cast the spell.

Return a value of 0 on error.


This only works with PC and creature type objects, else it returns 0. For placeables casting spells they have to cheat spell, which will automatically does caster levels in the range of 10 - 17. Code: min(10, (Innate Spell Level * 2) - 1).

This function only works properly when oCreature is casting a spell. It is certainly the only reliable place. If used outside a spell script, it will return the last caster level of the last spell cast by oCreature - IE, some Area-of-Effect spells do this, to get how much damage dice to use. You could also use in the OnSpellCastAt reasonably accurately.

It is affected by EffectNegativeLevel having -1 to the value (so can reach 0, for multi-classed character!) for each negative level applied.

Known Bugs

In all versions of NWN there are bugs regarding the function changing after-the-fact on Area of Effect objects (which should be able to call it on itself and retrieve a stored value). As a multiclass wizard 20/druid 1 you first cast Grease (level 1 spell) then a wizard spell such as Magic Missile, the Grease suddenly gets a higher caster level of 20 versus 1 before.

Additionally Feats and Items may correctly get a caster level with this function (mostly), but the resulting effect may not have a valid caster level when retrieved with GetEffectCasterLevel. In particular feat-like spells and items casting spells are affected. This affects EffectDispelMagicAll and EffectDispelMagicBest primarily.




// Example 1 - Gets the casting level of the object that last cast
// a spell, if that object is a PC or Creature.  For fun, the object
// then says its caster level.
/* note the bug above; this example may not work properly */
void main()
    // Get the object that last cast a spell.
    object oCreature = GetLastSpellCaster();
    // Get out if it is not a creature (PC or mob)
    if (GetObjectType(oCreature) != OBJECT_TYPE_CREATURE) return;
    // Get the casting level of the creature.
    int nCLevel = GetCasterLevel(oCreature);
    // Just for fun...
    string sLevel = IntToString(nCLevel);
    AssignCommand(oCreature,SpeakString("I'm a level " + sLevel + " caster!",TALKVOLUME_TALK));

See Also


GetLastSpellCaster GetEffectCasterLevel

 author: Brett Lathrope, editor: Jasperre, additional contributor(s): Alec Usticke