Event Handler Functions

From the Oblivion ConstructionSet Wiki
Revision as of 23:06, 3 January 2012 by imported>8asrun6aer
Jump to navigation Jump to search

An event handler is a user-defined function designed to respond to game events. Rather than calling the function directly, you use SetEventHandler to register your user defined function as a handler for a specific event. Then, when ever the associated event occurs during gameplay, OBSE will invoke your script, passing information about the event to your function through its arguments.

Events include block types such as "OnHit", "OnDeath", and so on, as well as other events involving loading, saving, and exiting the game. Each event expects its handlers to accept a specific set of arguments. The supported events, including any required arguments (listed in the order in which they should appear in the function definition) are listed below:

Events

Event Name StringParametersNotes
OnHittarget:ref attacker:ref
OnHitWithtarget:ref weapon:form
OnMagicEffectHittarget:ref magicEffectCode:string (4 characters)
OnActorEquiptarget:ref item:form
OnDeath target:ref killer:form
OnMurdertarget:ref killer:form
OnKnockouttarget:ref
OnActorUnequiptarget:ref item:form
OnAlarm TrespassalarmedActor:ref criminal:ref
OnAlarm StealalarmedActor:ref criminal:ref
OnAlarm AttackalarmedActor:ref criminal:ref
OnAlarm PickpocketalarmedActor:ref criminal:ref
OnAlarm MurderalarmedActor:ref criminal:ref
OnPackageChangetarget:ref package:form
OnPackageStarttarget:ref package:form
OnPackageDonetarget:ref package:form
OnStartCombattarget:ref opponent:ref
OnActivateactivatedRef:ref activatingRef:ref
OnVampireFeedNONEinvoked after player finishes feeding as a vampire
OnSkillUpskillActorValueCode:intinvoked after skill increases through use
OnScriptedSkillUpskillActorValueCode:int amount:intwhen ModPCSkill/AdvanceSkill are used to increase skill, invoked before the skill is modified
OnDrinkPotiondrinker:ref potion:form
OnEatIngredienteater:ref ingredient:formalso triggers OnActorEquip event
OnActorDrop dropper:ref droppedItem:refdroppedItem is the new reference in the game world to the dropped item
OnSpellCast caster:ref spell:form
OnScrollCastcaster:ref scrollEnchantment:form
OnFallImpactfaller:refinvoked when a falling actor hits the ground with sufficient velocity to be potentially damaging, before damage is applied
OnMapMarkerAddmapMarker:ref
OnHealthDamagedamage:float attacker:refInvoked on the actor taking damage (i.e. GetSelf will return the damaged actor) whenever damage is taken. "Attacker" may be zero e.g. when taking damage from falling. The handler is invoked just before the damage is applied, so it can be nullified by commands like ModActorValue. Use the object filter to specify the damaged actor to which your event handler should be attached, if any.
OnCreateSpellspell:refwhen player creates a new spell
OnCreatePotionpotion:ref isUnique:intwhen player creates a new potion. The second argument is 1 if the resulting potion is a new base object, 0 if a previously-created potion has the same effects as the newly-created one (in which case the existing base object is used).
OnEnchantenchantedItem:refwhen player enchants an item.
OnAttackactor:refSlightly misnamed. Invoked whenever actor begins the animation sequence for a melee or staff attack or a spell cast. Use commands like IsCasting to determine the current action.
OnBowAttackactor:refactor begins the animation of drawing his bowstring
OnReleaseactor:refanimation begun by OnAttack or OnBowAttack completes - e.g., actor releases an arrow shot, swings his weapon, or releases a spell projectile.
OnBlockactor:refactor begins block animation
OnRecoilactor:refactor begins recoil animation
OnStaggeractor:refactor begins stagger animation
OnDodgeactor:refactor begins dodge animation
LoadGamefilename:string
SaveGamefilename:string
PostLoadGamegameLoadedSuccessfully:bool0 if error occurred during load (corrupt savegame?), 1 otherwise
ExitGameNONEexiting from main menu or in-game menu
ExitToMainMenuNONEexiting from in-game menu to main menu
QQQ NONEexiting via QQQ/QuitGame console command
OnNewGameNONEuser starts a new game from the main menu


For events associated with block types, you may provide a specific value for any, all, or none of the arguments when registering an event handler. The first argument is referred to by the name "ref" and the second as "object", regardless of the names of the argument variables in your function script (exception: for OnHealthDamage, "object" refers to the damaged actor). Doing so allows you to filter out events you're not interested in.

For instance, to handle events involving the player being hit by another actor, use:

SetEventHandler "OnHit", yourScript, "ref"::playerRef

To handle events in which the player, and only the player, hits anyone else, use:

SetEventHandler "OnHit", yourScript, "object"::playerRef

To handle the player being affected by a Restore Health magic effect, use:

SetEventHandler "OnMagicEffectHit", yourScript, "ref"::playerRef "object"::"REHE"

Notes

  • Avoid using AddSpell to add an ability or disease to an actor from within an OnMagicEffectHit handler, as doing so may cause the game to become unstable.
  • Event handler scripts are invoked at the moment the event is registered by the game. For example, an "OnEquip" handler is invoked when an actor decides to equip an item, but before the item is actually equipped, which means that trying to unequip the item from within the handler will fail.
  • It is recommended that you prefer to filter events as strictly as possible to allow OBSE to avoid calling your handler for events you're not interested in. Further, once an event handler becomes unneeded (for instance, if the target of the handler dies), use RemoveEventHandler to remove it; this prevents OBSE from having to check against the defunct handler when processing events.


See Also