DecrementRemainingSpellUses(object, int)

From NWN Lexicon
Jump to navigationJump to search

Decrease the number of spell uses of a particular spell for a given creature.

void DecrementRemainingSpellUses(
    object oCreature,
    int nSpell


Creature to decrement the remaining spell uses of a particular spell.


Decreases the remaining number of spell uses per day for a creature by one. A creature must have at least one spell use for this function to work. To make this work correctly, it should be used with GetHasSpell().

nSpell doesn't have to be a spell. It can be any entry in the spells.2da file.

If they do not have any castings of nSpell memorized, then nothing will happen.

Note that this has to be added into a loop, with GetHasSpell(), to remove all the available castings of nSpell.


This is most useful for removing uses of spells that, for example, get used up in special ways (sacrificing spells to power an item for example).

There is NO WAY to increment a spell, and there is no way to check if a spell *was* memorized either (so, there is no way to check if they *had* magic missile, but cast it earlier on). This will likely never be added - the only way to get back spells is resting (or ForceRest()).

Note: There is no way to specify which classes spells go first. If anyone knows the order (whether it is in order of primary class, secondary class, or order of Cleric, Druid etc.) please report it so everyone can know, although it is rarely important.

Cannot decrement spell that creature have memorized but shouldn't be able to use, for example if creature has a sixth level memorized under Spells tab but has caster ability only 15 or less, this function fails. Same spell given as Special ability is decremented properly.

Known Bugs

Prior to patch 1.28 this function did not work properly with spontaneously cast spells. Prior to 1.61, it didn't work with metamagic spells. Prior to 1.64, it didn't work with clerical domain spells.

Whew! After all of that, it should now work correctly for any spells.2da entry, including all domain spells, sub-spells, metamagic spells, and spontaneous spells.




// Decrement their remaining magic missile uses by 1, in a
// conversation.
// * Note: A conversation conditional script should check if they
//    have magic missile memorized to start with, before this fires.

void main()
    // Get the PC
    object oPC = GetPCSpeaker();

    // Decrement the spell uses
    DecrementRemainingSpellUses(oPC, SPELL_MAGIC_MISSILE);

See Also

constants:  SPELL_* Constants

 author: Charles Feduke, editor: Jasperre, additional contributor(s): Justin Koch, Jasperre