NWNX:EE  8193.36.12
Effect

Readme

Provide various utility functions to manipulate builtin effect type

Environment Variables

NWNX_EFFECT_EXTEND_DURATION_TYPE = true/false

Allow ApplyEffectToObject to apply internal duration types; simply give the new constants as described below to the function.

To correctly read and iterate these functions, you need to use:

The builtin functions (GetFirstEffect, GetNextEffect, GetIsEffectValid) do not expose internal effect types.

const int DURATION_TYPE_EQUIPPED = 3;

This effect gets automatically removed when the item that created it gets unequipped.

For this to work, the effect creator needs to be a valid equipped item; you can set this either by spawning the effect from the item handler, or by using SetEffectCreator().

Behaviour without a equipped item in the effect creator slot is undefined.

const int DURATION_TYPE_INNATE = 4;

This is used by the game to represent things like racial and feat effects, as well as movement speed adjustments.

Files

file  nwnx_effect.nss
 

Classes

struct  NWNX_EffectUnpacked
 An unpacked effect. More...
 

Functions

struct NWNX_EffectUnpacked NWNX_Effect_UnpackEffect (effect e)
 Convert native effect type to unpacked structure. More...
 
effect NWNX_Effect_PackEffect (struct NWNX_EffectUnpacked e)
 Convert unpacked effect structure to native type. More...
 
int NWNX_Effect_ReplaceEffect (object obj, effect eOld, effect eNew)
 replace an already applied effect on an object Only duration, subtype, tag and spell related fields can be overwritten. More...
 
int NWNX_Effect_GetTrueEffectCount (object oObject)
 Gets the true effect count. More...
 
struct NWNX_EffectUnpacked NWNX_Effect_GetTrueEffect (object oObject, int nIndex)
 Gets a specific effect on an object. This can grab effects normally hidden from developers, such as item properties. More...
 
void NWNX_Effect_ReplaceEffectByIndex (object oObject, int nIndex, struct NWNX_EffectUnpacked e)
 Replaces an already applied effect with another. More...
 
int NWNX_Effect_RemoveEffectById (object oObject, string sID)
 Removes effect by ID. More...
 
void NWNX_Effect_Apply (effect eEffect, object oObject)
 Applys an effect, bypassing any processing done by ApplyEffectToObject. More...
 
effect NWNX_Effect_SetEffectCreator (effect eEffect, object oObject)
 Sets an effect creator. More...
 
int NWNX_Effect_GetIsEffectValid (effect eEffect)
 Checks if the given effect is valid. Unlike the game builtin, this call considers internal types too. More...
 
int NWNX_Effect_GetAppliedEffectCount (object oObject)
 Returns the number of applied effects on the given object. More...
 
effect NWNX_Effect_GetAppliedEffect (object oObject, int nNth)
 Returns the nNth applied effect on a object. More...
 

Variables

const int DURATION_TYPE_EQUIPPED = 3
 
const int DURATION_TYPE_INNATE = 4
 

Function Documentation

◆ NWNX_Effect_UnpackEffect()

struct NWNX_EffectUnpacked NWNX_Effect_UnpackEffect ( effect  e)

Convert native effect type to unpacked structure.

Parameters
eThe effect to convert.
Returns
A constructed NWNX_EffectUnpacked.

Definition at line 278 of file nwnx_effect.nss.

◆ NWNX_Effect_PackEffect()

effect NWNX_Effect_PackEffect ( struct NWNX_EffectUnpacked  e)

Convert unpacked effect structure to native type.

Parameters
eThe NWNX_EffectUnpacked structure to convert.
Returns
The effect.

Definition at line 287 of file nwnx_effect.nss.

◆ NWNX_Effect_ReplaceEffect()

int NWNX_Effect_ReplaceEffect ( object  obj,
effect  eOld,
effect  eNew 
)

replace an already applied effect on an object Only duration, subtype, tag and spell related fields can be overwritten.

Note
eNew and eOld need to have the same type.
Returns
Number of internal effects updated.

Definition at line 297 of file nwnx_effect.nss.

◆ NWNX_Effect_GetTrueEffectCount()

int NWNX_Effect_GetTrueEffectCount ( object  oObject)

Gets the true effect count.

Parameters
oObjectThe object to get the count of.
Returns
the number of effects (item properties and other non-exposed effects included)

Definition at line 310 of file nwnx_effect.nss.

◆ NWNX_Effect_GetTrueEffect()

struct NWNX_EffectUnpacked NWNX_Effect_GetTrueEffect ( object  oObject,
int  nIndex 
)

Gets a specific effect on an object. This can grab effects normally hidden from developers, such as item properties.

Parameters
oObjectThe object with the effect
nIndexThe point in the array to retrieve (0 to GetTrueEffectCount())
Returns
A constructed NWNX_EffectUnpacked.

Definition at line 319 of file nwnx_effect.nss.

◆ NWNX_Effect_ReplaceEffectByIndex()

void NWNX_Effect_ReplaceEffectByIndex ( object  oObject,
int  nIndex,
struct NWNX_EffectUnpacked  e 
)

Replaces an already applied effect with another.

Parameters
oObjectThe object with the effect to replace
nIndexThe array element to be replaced
eThe unpacked effect to replace it with.
Note
Cannot replace an effect with a different type or ID.

Definition at line 329 of file nwnx_effect.nss.

◆ NWNX_Effect_RemoveEffectById()

int NWNX_Effect_RemoveEffectById ( object  oObject,
string  sID 
)

Removes effect by ID.

Parameters
oObjectThe object to remove the effect from
sIDThe id of the effect, can be retrieved by unpacking effects.
Returns
FALSE/0 on failure TRUE/1 on success.

Definition at line 340 of file nwnx_effect.nss.

◆ NWNX_Effect_Apply()

void NWNX_Effect_Apply ( effect  eEffect,
object  oObject 
)

Applys an effect, bypassing any processing done by ApplyEffectToObject.

Parameters
eEffectThe effect to be applied.
oObjectThe object to apply it to.

Definition at line 350 of file nwnx_effect.nss.

◆ NWNX_Effect_SetEffectCreator()

effect NWNX_Effect_SetEffectCreator ( effect  eEffect,
object  oObject 
)

Sets an effect creator.

Parameters
eEffectThe effect to be modified.
oObjectThe effect creator.
Returns
The effect with creator field set.

Definition at line 358 of file nwnx_effect.nss.

◆ NWNX_Effect_GetIsEffectValid()

int NWNX_Effect_GetIsEffectValid ( effect  eEffect)

Checks if the given effect is valid. Unlike the game builtin, this call considers internal types too.

Parameters
eEffectThe effect to check
Returns
TRUE if the effect is valid (including internal types).

Definition at line 370 of file nwnx_effect.nss.

◆ NWNX_Effect_GetAppliedEffectCount()

int NWNX_Effect_GetAppliedEffectCount ( object  oObject)

Returns the number of applied effects on the given object.

Parameters
oObjectThe object to get the applied effect count for.
Returns
The number of applied effects, including internal.

Definition at line 381 of file nwnx_effect.nss.

◆ NWNX_Effect_GetAppliedEffect()

effect NWNX_Effect_GetAppliedEffect ( object  oObject,
int  nNth 
)

Returns the nNth applied effect on a object.

Parameters
oObjectThe object to get the applied effect copy for.
nNthThe effect index to get.
Note
Make sure to check with NWNX_Effect_GetIsEffectValid, as this iterator also includes internal effects.
Returns
A copy of the applied game effect, or a invalid effect.

Definition at line 392 of file nwnx_effect.nss.

Variable Documentation

◆ DURATION_TYPE_EQUIPPED

const int DURATION_TYPE_EQUIPPED = 3

EQUIPPED effects are always associated with a slotted item: Setting this duration type requires the effect creator to be set to the (already equipped) item that should remove this effect when unequipped. Removal behaviour for effects where the creator is NOT a equipped item is undefined. They are not removed by resting, cannot be dispelled, etc.

Definition at line 16 of file nwnx_effect.nss.

◆ DURATION_TYPE_INNATE

const int DURATION_TYPE_INNATE = 4

These are feat/racial effects used internally by the game to implement things like movement speed changes and darkvision. They cannot be removed by resting, dispelling, etc.

Definition at line 21 of file nwnx_effect.nss.