NameNotPresent Posted June 23, 2015 Author Share Posted June 23, 2015 The event handler script is an object script attached to an item in the player's inventory. Don't the event handlers need to be set each time after they have been used? Link to comment Share on other sites More sharing options...
Surilindur Posted June 23, 2015 Share Posted June 23, 2015 (edited) 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 EndThe 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 EndWhen 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 June 23, 2015 by PhilippePetain Link to comment Share on other sites More sharing options...
Recommended Posts