GetCasterLevel(object)

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

int GetCasterLevel(
    object oCreature
);

Parameters

oCreature

Creature or PC casting a spell.


Description

Get the Caster Level of oCreature. 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.



Remarks

This only works with PC and creature type objects, else it returns 0.

This function only works properly when oCreature is casting a spell. It is cirtainly 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.


Version

1.61

Example

// 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

functions: GetCharacterLevel | GetLastSpellCaster
categories: Get Data from Creature Functions | Spells Functions


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