ItemPropertyOnHitCastSpell(int, int)

From NWN Lexicon
Jump to navigationJump to search

Sets an "on hit cast spell" item property.

itemproperty ItemPropertyOnHitCastSpell(
    int nSpell,
    int nLevel
);

Parameters

nSpell
IP_CONST_ONHIT_CASTSPELL_*
nLevel
Level at which to cast the spell; it goes into a spell scripts GetCasterLevel amount.


Description

Creates an item property that (when applied to a weapon item) causes a spell to be cast when a successful strike is made, or (when applied to armor or shield) when it is struck by an opponent.

nSpell uses the IP_CONST_ONHIT_CASTSPELL_* constants which are a reference to iprp_onhitspell.2da

The spell fires the spell script with GetSpellCastItem as the one with the item property, and GetCasterLevel being the same as nLevel. GetSpellSaveDC will default to the standard item formula, 10 + Innate spell level + 3.


Remarks

The itemproperty commands are special constructors - they construct an itemproperty "object" which can then be applied to an item using the AddItemProperty command, much like effects need to be first constructed, then applied with ApplyEffectToObject.

It will often be a good idea to remove similar itemproperties from the item first. There's a command in the "x2_inc_itemprop" include file called IPSafeAddItemProperty which will do that for you. Check IPSafeAddItemProperty for current bug report.

The IP_CONST_ONHIT_CASTSPELL_* constant can be retrieved off this type of item property using GetItemPropertySubType. The caster level can be retrieved using GetItemPropertCostTableValue.

An attack against a Plot placeable is not considered a 'successful strike' and therefore this event will not fire.

If more than one On Hit: Cast Spell is on an item, only one will fire, likely the first one applied. This is different from ItemPropertyOnHitProps which appears to fire every one.

Design Warning: There is for some reason no % chance of the spell firing unlike ItemPropertyOnHitProps, which means by default if you applied On Hit Cast Spell: Finger of Death, you will have that spell fire (albeit with a reasonably low DC) every time you made a successful hit. At higher levels on a competent fighter this can mean a lot of hits.

The same occurs on armor and shields, where a spell will fire potentially excessively if a player decides to lower their AC enough.

To work around this either add additional checks in the spell script such as the example item-only spell "Chaos Shield" script x2_s3_chaosshld which defaults to 2% per Caster Level which is actually on the item.

Version

1.61

Example

#include "x2_inc_itemprop"
//The include contains IPSafeAddItemProperty function

//Makes the PC speaker's armor cast daze when hit, at level 5
void main()
{
    object oPC = GetPCSpeaker();
    object oItem = GetItemInSlot(INVENTORY_SLOT_CHEST, oPC);
    if (!GetIsObjectValid(oItem)) return;

    itemproperty ipAdd = ItemPropertyOnHitCastSpell(IP_CONST_ONHIT_CASTSPELL_DAZE, 5);

    IPSafeAddItemProperty(oItem, ipAdd);
}

See Also

functions: 

ItemPropertyOnMonsterHitProperties

constants: 

IP_CONST_ONHIT_CASTSPELL_* Constants



 author: Lilac Soul, editor: Peter Busby, Aschent