RegisterForCustomEvent - ScriptObject

Member of: ScriptObject Script

Registers this script to receive the specified custom event from the source object whenever that source object sends the event. The event will be relayed only to this script and will not be sent to other scripts attached to the same object, or to any aliases or magic effects attached to the object.

SyntaxEdit

Function RegisterForCustomEvent(ScriptObject akSender, CustomEventName asEventName) native

ParametersEdit

  • akSender: The ScriptObject that receives the event we want to also receive.
  • asEventName: The event we want relayed to us. This must be a raw string literal and may not be a variable.

Return ValueEdit

None

ExamplesEdit

; AmbushTriggerScript defines the Ambush custom event
AmbushTriggerScript Property kTrigger Auto Const

Event OnInit()
  ; Register for Ambush event from the trigger - note the trigger type is the script type that defines the event
  RegisterForCustomEvent(kTrigger, "Ambush")
EndEvent

; Special event to receive when the ambush event is received from a AmbushTriggerScript script
; Note the type in the event name matches the type of the first parameter, and is also the script where the
; custom event is defined.
Event AmbushTriggerScript.Ambush(AmbushTriggerScript akSender, Var[] akArgs)
  Debug.Trace("We received the ambush event from " + akSender + " with arguments " + akArgs)
EndEvent

NotesEdit

  • Aliases and quests will automatically unregister for this event when the quest stops. Active magic effects will automatically unregister when they are removed.
  • The object type in the custom event definition must be the script where the event was originally defined. For example, if the AmbushTriggerScript sends the Ambush event, you must use that and not ObjectReference, which doesn't define the event.

See AlsoEdit