Jump to content

I need help getting started scripting.


NameNotPresent

Recommended Posts

No. Event handler needs to be set once. Just setting it once after game has been restarted should be enough. Maybe it would even be possible to only ever set it once, but I have not tested it, so I cannot tell.

 

An event handler is a user-created function, another feature added by OBSE. A user-created function is defined in the editor, when writing, as an object script. But it must not be attached to anything. It needs to written, compiled as an object script and then left there. Elsewhere, in a quest, for example, that script (which is classified as an object script, but is a user-created function) is added as an event handler for an event that takes place in game. After it is added, OBSE will automatically call the function when the event, as a handler of which the function has been set, takes place and pass to it the information assocciated with the event (the things listed in OBSE Command Documentation).

 

So the function will just sit there, alone, not attached to anything. If it has been added as an event handler, OBSE will call it when necessary, after which it can continue sitting alone somewhere out of the way until it is called again. The function does not need to be attached to anything.

 

So, there only needs to be the script used as an event handler, the one defined as an object script, but that in reality is a user-created function that can be called - also on references, when it will work like a magic effect script (but still be defined as an object script).

ScriptName MyEventHandler

ref rTarget      ; The function receives this from OBSE
ref rAttacker    ; The function receives this from OBSE
ref rWeapon      ; Weapon of the attacker, the slot 16 one

Begin Function { rTarget rAttacker }

    let rWeapon := rAttacker.GetEquippedObject 16

    If ( rWeapon )
        MessageEX "Oh dear! %n hit %n with %n!", rAttacker rTarget rWeapon
    Else
        MessageEX "Oh dear! %n hit %n with no weapon in slot 16!", rAttacker rTarget
    EndIf

End

The references in {...} need to be in the same order as the ones in OBSE Command Documentation, as OBSE will send them to the function in the order described there.

 

That user-created function can then be set as an event handler in, for example, a quest script. Once when the game is restarted should be enough. It does not need to be set again every second, as it does not get "used up" in any way.

ScriptName MyQuestScript

Begin GameMode

    ; Things that need to run every time quest updates

    If ( GetGameRestarted == 0 )
        Return
    EndIf

    SetEventHandler "OnHit" MyEventHandler ; <-- No restrictions to attacker & target

    ; All other SetEventHandlers here, too, and everything else
    ; that onlt needs to be run once when game is restarted

End

When an event handler is no longer needed, it can also be removed by RemoveEventHandler command or something like it, which works like the SetEventHandler but does the opposite (tells OBSE not to call the specific function upon that specific event again, unless it is added as an event handler again).

 

Hopefully that helps a little. :smile:

Edited by PhilippePetain
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...