Table of Contents

Class EffectRunScriptEvent

Namespace
Anvil.API.Events
Assembly
NWN.Anvil.dll

Triggered when a custom scripted effect receives an interval event, or is applied/removed.

public sealed class EffectRunScriptEvent : IEvent
Inheritance
EffectRunScriptEvent
Implements
Inherited Members
Extension Methods

Examples

public Effect GetAcidIntervalEffect(ScriptHandleFactory scriptHandleFactory)
{
  ScriptCallbackHandle handler = scriptHandleFactory.CreateUniqueHandler(OnInterval);
  return Effect.RunAction(onIntervalHandle: handler, interval: NwTimeSpan.FromRounds(1));
}

private ScriptHandleResult OnInterval(CallInfo callInfo)
{
  EffectRunScriptEvent eventData = new EffectRunScriptEvent();
  if (eventData.EventType == EffectRunScriptType.OnInterval && eventData.EffectTarget is NwGameObject gameObject)
  {
    _ = ApplyIntervalEffects(eventData.Effect?.Creator, gameObject);
  }

  return ScriptHandleResult.Handled;
}

private async Task ApplyIntervalEffects(NwObject? caster, NwGameObject target)
{
  if (caster != null && caster.IsValid)
  {
    await caster.WaitForObjectContext();
  }

  Effect damageEffect = Effect.Damage(Random.Shared.Roll(6, 2), DamageType.Acid);
  target.ApplyEffect(EffectDuration.Instant, damageEffect);
}

Remarks

This event class should be constructed manually as a part of a script handler.

Properties

Effect

Gets the associated effect with this event.

EffectTarget

Gets the target of the effect.

EventType

Gets the effect event type.