DispatchEvent

From GECK
Jump to: navigation, search


A function added by the New Vegas Script Extender.

Description

Dispatches a User-Defined Event that any mod can register to with SetEventHandler / SetEventHandlerAlt. This allows for easy communication between mods.

The listening mod receives a string map array in its handler script. By default it will contain the event name under the "eventName" key, and the dispatching mod name under the "eventSender" key, both as strings.

The dispatching mod can choose to override this behavior by

  • setting an optional infomap parameter to a custom stringmap that listening mod will receive.
  • setting an optional AlternativeSenderString string that will replace "eventSender" key.

Syntax

[help]
DispatchEvent eventID:string infomap:stringmap AlternativeSenderString:string 

Example

This example script dispatches a custom event to all listeners. Dispatching mod name is "MyMod.esp"

scn BasicDispatch

Begin GameMode

  DispatchEvent "My Mod Is Ready"

endif

End 

This example listener script registers handler scripts to receive two custom events - "My Mod Is Ready" and "Sending Local Actor Refs"

scn RegisteringHandlers

Begin GameMode

  if GetGameLoaded
    SetEventHandler "My Mod Is Ready", fnBasicEventHandler
    SetEventHandler "Sending Local Actor Refs", fnExtendedEventHandler
  endif

End 

This example handler script receives the custom event "My Mod Is Ready" and parses its default parameters: eventName and eventSender.

scn fnBasicEventHandler

array_var aArgs

Begin Function {aArgs}

  Print "Received '" + $aArgs["eventName"] + "' from '" + $aArgs["eventSender"] + "'"
  ; "Received 'My Mod Is Ready' from 'MyMod.esp'
  ; do stuff

End 

This example script dispatches a custom event with an optional infomap and a custom string for eventSender parameter.

scn ExtendedDispatch

array_var aArgs

Begin GameMode

    let aArgs := ar_construct "stringmap"
    let aArgs["list"] := GetRefs 200
    DispatchEvent "Sending Local Actor Refs", aArgs, "ExtendedDispatch"

End 

This example handler script receives the custom "Sending Local Actor Refs" event with a custom infomap and eventSender.

scn fnExtendedEventHandler
array_var aArgs

array_var aRefs

Begin Function {aArgs}

  Print "Received '" + $aArgs["eventName"] + "' from script '" + $aArgs[eventSender] + "'"
  ; "Received 'Sending Local Actor Refs' from script 'ExtendedDispatch'
  let aRefs := aArgs["list"]
  ; do stuff

End 


See Also

External Links