This wiki is a copy of the original Oblivion CS wiki created and maintained by the UESP.net. See CSwiki:Copy Notice for more info.

SetEventHandler

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

A command for Oblivion Script Extender

Syntax:

(success:bool) SetEventHandler eventID:string functionScript:ref filter1:pair filter2:pair

Registers a user-defined function as a handler for the specified event. If the function script returns a value, it will be ignored. Two optional arguments can be supplied as key::value pairs to filter events according to the target and/or object.

For more details on events and for a list of available events to hook into, see Event_Handler_Functions.

Example

User Function Script #1

	scn FnOnHitByPlayer
	ref target
	ref attacker
	
	begin Function { target, attacker }
		attacker.PushActorAway target, 50
	end

User Function Script #2

	scn FnOnPlayerRestoreHealth
	ref target
	long effectCode
	
	begin Function { target, effectCode }
		; expecting effectCode to be "REHE"/restore health
		message "The player has been hit by a restore health effect"
	end

User Function Script #3

	scn FnOnLoadGame
	string_var filename
	
	begin Function { filename }
		print "Loading game from " + $filename
	end

Primary Script

	scn SomeQuestScript
	begin gamemode
		if getGameRestarted
			SetEventHandler "OnHit" FnOnHitByPlayer "object"::PlayerRef
			SetEventHandler "OnMagicEffectHit" FnOnPlayerRestoreHealth "ref"::PlayerRef "object"::"REHE"
			SetEventHandler "LoadGame" FnOnLoadGame
		endif
	end

Notes

_none_

See Also