Difference between revisions of "ModEvent Script"

From the CreationKit Wiki
Jump to navigation Jump to search
imported>Egocarib
imported>Egocarib
Line 53: Line 53:
<source lang=papyrus>
<source lang=papyrus>
Function OnInit()
Function OnInit()
     RegisterForModEvent("ModPrefix_myCustomEvent", "OnMyCustomEvent")
     RegisterForModEvent("ModPrefix_myCustomEvent", "OnMyCustomEvent") ;(remember to re-register for events each game reload)
EndFunction
EndFunction



Revision as of 15:23, 28 April 2014


Script for ModEvents.

Definition

ScriptName ModEvent Hidden

SKSE Global Functions

Int Create(String eventName)
  • Creates a new ModEvent and returns the handle.
Bool Send(Int handle)
  • Sends the ModEvent and releases it. (Return value indicates whether it was successfully sent).
Bool Release(Int handle)
  • Releases the ModEvent without sending it.
PushBool(Int handle, Bool value)
  • Pushes a Bool param into the event.
PushInt(Int handle, Int value)
  • Pushes a Int param into the event.
PushFloat(Int handle, Float value)
  • Pushes a Float param into the event
PushString(Int handle, String value)
  • Pushes a String param into the event.
PushForm(Int handle, Form value)
  • Pushes a Form param into the event.

Example

Script that is sending the event:

SomeFunction()
    int handle = ModEvent.Create("ModPrefix_myCustomEvent")
    if (handle)
        ModEvent.PushForm(handle, self)
        ModEvent.PushForm(handle, someOtherForm)
        ModEvent.PushInt(handle, 1000)
        ModEvent.PushString(handle, "It worked!")
        UIDelegate.Send(handle)
    endIf
EndFunction

Script that wishes to receive the event:

Function OnInit()
    RegisterForModEvent("ModPrefix_myCustomEvent", "OnMyCustomEvent") ;(remember to re-register for events each game reload)
EndFunction

;note that the parameters of this event must match the number & order of parameters as they were pushed in the sending script.
Event OnMyCustomEvent(Form sender, Form theForm, int theInt, string theString)
    if (sender as Actor)
        debug.trace("Our event was received from a script attached to an Actor!")
    endif
    int goldVal = someOtherForm.GetGoldValue()
    debug.trace("The other form recieved by our event has a gold value of " + goldVal)
    debug.trace("We recieved theInt, and it equals " + theInt)
    debug.trace(theString) ;prints "It worked!"
EndEvent