GetEffectTag(effect)

From NWN Lexicon
Revision as of 13:57, 29 July 2019 by WilliamDraco (talk | contribs) (missed declaration in example)
Jump to: navigation, search
Nwnee logo.jpg Note: This article documents Neverwinter Nights: Enhanced Edition new content or changes/updates/fixes to 1.69 functions. These are all listed under the category and patches pages.
Returns the string tag set for the provided effect.
string GetEffectTag(
    effect eEffect
);

Parameters

eEffect
The effect object to get the tag from.

Description

Returns the string tag set for the provided effect. If no tag has been set, returns an empty string.

Remarks

The returned string is that which was set using TagEffect during effect application. Useful in order to check whether an effect is the result of a specific interaction (which is not a spell and therefore GetEffectSpellId would not work).

One such example might be applying a supernatural effect on being hit by a creature, which is normally undispellable, but allow a special potion to clear that effect without clearing all effects of the same type.

The example below considers an undispellable effect from entering an area and removing the same effect on exiting.

Version

1.74.8149

Example

// Applying a supernatural effect 'permanently' decreasing entering PC's strength by 1.
// Use the tag "TotallyUnique" to make this Strength decrease separate from others in effect.
void main()
{
    object oPC=GetEnteringObject();
    if(!GetIsPC(oPC)) return;
 
    effect eBad=EffectAbilityDecrease(ABILITY_STRENGTH, 1);
    eBad=SupernaturalEffect(eBad);
    eBad=TagEffect(eBad, "TotallyUnique");
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, eBad, oPC);
}
 
// When the PC leaves we want to remove the above effect, but leave other strength decreases intact.
// Instead of checking for effect type, simply check for the effect tag.
void main()
{
    object oPC=GetExitingObject();
    if(!GetIsPC(oPC)) return;
 
    effect eEffect = GetFirstEffect(oPC);
    while(GetIsEffectValud(eEffect))
    {
        if(GetEffectTag(eEffect) == "TotallyUnique")
            RemoveEffect(eEffect);
        eEffect = GetNextEffect(oPC);
    }
}

See Also

functions: TagEffect