Difference between revisions of "GetEffectTag"

From NWN Lexicon
Jump to: navigation, search
(Version: added version info and link)
(Remarks on use and Example (Including how to callback))
Line 15: Line 15:
  
 
===Remarks===
 
===Remarks===
{{stub section}}
+
 
 +
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).<br /><br />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.<br /><br />The example below considers an undispellable effect from entering an area and removing the same effect on exiting.
  
 
===Version===
 
===Version===
Line 21: Line 22:
  
 
===Example===
 
===Example===
{{examples needed}}
+
 
 +
<nwscript>
 +
// 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;
 +
 
 +
    eEffect = GetFirstEffect(oPC);
 +
    while(GetIsEffectValud(eEffect))
 +
    {
 +
        if(GetEffectTag(eEffect) == "TotallyUnique")
 +
            RemoveEffect(eEffect);
 +
        eEffect = GetNextEffect(oPC);
 +
    }
 +
}
 +
</nwscript>
  
 
===See Also===
 
===See Also===

Revision as of 06:07, 1 July 2019

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;
 
    eEffect = GetFirstEffect(oPC);
    while(GetIsEffectValud(eEffect))
    {
        if(GetEffectTag(eEffect) == "TotallyUnique")
            RemoveEffect(eEffect);
        eEffect = GetNextEffect(oPC);
    }
}

See Also

functions: TagEffect