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.

Difference between revisions of "SetEventHandler"

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
imported>8asrun6aer
(Created page with "A command for Oblivion Script Extender '''Syntax:''' (success:bool) SetEventHandler eventID:string functionScript:ref filter1:pair fil...")
 
imported>8asrun6aer
m
 
(10 intermediate revisions by the same user not shown)
Line 4: Line 4:
  (success:bool) SetEventHandler eventID:string functionScript:ref filter1:pair filter2:pair
  (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.
Registers a user-defined function script as a handler for the specified event. If the user-defined function script returns a value, it will be ignored.


For more details on events and for a list of available events to hook into, see [http://obse.silverlock.org/obse_command_doc.html#Events| OBSE Command Documentation for events].
Two optional arguments can be supplied to '''SetEventHandler''' by using the unique syntax of ''"key"''::''value'' pairs to filter events according to the target and/or object.  The ''"key"'' part is a string (must be enclosed in quotes) and is generally expected to be either "ref" (generally referring to the target or first argument in your custom function) or "object" (generally referring to the source or second argument in your custom function), regardless of the names of the argument variables in your function script (exception: for OnHealthDamage, "object" refers to the damaged actor).
 
For more details on events and for a list of available events to hook into, see [[Event Handler Functions]].


== Example ==
== Example ==
User Function Script #1
<pre>
<pre>
scn FnOnHitByPlayer
scn FnOnHitByPlayer
Line 15: Line 18:
begin Function { target, attacker }
begin Function { target, attacker }
; we know the attacker must be the player, but the argument is still required
attacker.PushActorAway target, 50
print $target + " was hit by the player"
end
end
-------------
</pre>
User Function Script #2
<pre>
scn FnOnPlayerRestoreHealth
scn FnOnPlayerRestoreHealth
ref target
ref target
Line 24: Line 28:
begin Function { target, effectCode }
begin Function { target, effectCode }
print "The player has been hit by a restore health effect"
; expecting effectCode to be "REHE"/restore health
message "The player has been hit by a restore health effect"
end
end
--------------
</pre>
User Function Script #3
<pre>
scn FnOnLoadGame
scn FnOnLoadGame
string_var filename
string_var filename
Line 33: Line 40:
print "Loading game from " + $filename
print "Loading game from " + $filename
end
end
---------------
</pre>
Primary Script
<pre>
scn SomeQuestScript
scn SomeQuestScript
begin gamemode
begin gamemode
if getGameRestarted
if getGameRestarted
SetEventHandler "OnHit" FnOnHitByPlayer object::PlayerRef
SetEventHandler "OnHit" FnOnHitByPlayer "object"::Player
SetEventHandler "OnMagicEffectHit" FnOnPlayerRestoreHealth ref::PlayerRef object::"REHE"
SetEventHandler "OnMagicEffectHit" FnOnPlayerRestoreHealth "ref"::Player "object"::"REHE"
SetEventHandler "LoadGame" FnOnLoadGame
SetEventHandler "LoadGame" FnOnLoadGame
endif
endif
Line 44: Line 53:


</pre>
</pre>
With the the above four scripts compiled and loaded and the quest script ''SomeQuestScript'' activated, you should then see the following new effects in game:
# Whenever the player hits another actor, that actor will be knocked back 50 feet/units.
# Whenever the "REHE" magic effect is applied to the player, you should see a message: "The player has been hit by a restore health effect"
# Whenever a game is loaded, you should see a console message: "Loading game from ''filename''"
==Notes==
==Notes==
* When compiling scripts with this function, CS may generate a "expected string" error for the "filter" arguments.  Generally, this error can be ignored if the script still successfully compiles.  Be sure to run a live test of any script to ensure it runs in-game successfully.
'''none'''


==See Also==
==See Also==
* [[RemoveEventHandler]]
* [[RemoveEventHandler]]
* [[GetCurrentEventName]]
* [[GetCurrentEventName]]
* [[User_Functions]]
* [[Event Handler Functions]]
* [[User Functions]]


[[Category: Functions]]
[[Category: Functions]]
[[Category: Functions (OBSE)]]
[[Category: Functions (OBSE)]]
[[Category: Event Handler Functions]]

Latest revision as of 20:39, 4 January 2012

A command for Oblivion Script Extender

Syntax:

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

Registers a user-defined function script as a handler for the specified event. If the user-defined function script returns a value, it will be ignored.

Two optional arguments can be supplied to SetEventHandler by using the unique syntax of "key"::value pairs to filter events according to the target and/or object. The "key" part is a string (must be enclosed in quotes) and is generally expected to be either "ref" (generally referring to the target or first argument in your custom function) or "object" (generally referring to the source or second argument in your custom function), regardless of the names of the argument variables in your function script (exception: for OnHealthDamage, "object" refers to the damaged actor).

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

Example[edit | edit source]

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"::Player
			SetEventHandler "OnMagicEffectHit" FnOnPlayerRestoreHealth "ref"::Player "object"::"REHE"
			SetEventHandler "LoadGame" FnOnLoadGame
		endif
	end

With the the above four scripts compiled and loaded and the quest script SomeQuestScript activated, you should then see the following new effects in game:

  1. Whenever the player hits another actor, that actor will be knocked back 50 feet/units.
  2. Whenever the "REHE" magic effect is applied to the player, you should see a message: "The player has been hit by a restore health effect"
  3. Whenever a game is loaded, you should see a console message: "Loading game from filename"

Notes[edit | edit source]

none

See Also[edit | edit source]