Difference between revisions of "OnTrigger"

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
imported>Kkuhlmann
imported>QQuix
(Clarified the text related to TriggerZones)
 
(10 intermediate revisions by 6 users not shown)
Line 1: Line 1:
'''Syntax:'''
'''Syntax:'''
  begin OnTrigger ''TriggeringRefID''
'''Example:'''
   begin OnTrigger
   begin OnTrigger
  begin OnTrigger player


This block will be run every frame when something triggers the scripted object by colliding with it. Note that the action ref is NOT set (so [[IsActionRef]] and [[GetActionRef]] should not be used inside this blocktype).
This block will be run when something triggers the scripted object by colliding with it. If you specify a TriggeringRefID, the block will only run when that specific reference triggers the object; otherwise, the block will run when anything triggers the scripted object.


===See Also===
However, with a TriggerZone, the block will continue running every frame until all triggering refs leave the zone.
* [[OnTriggerEnter]]
 
* [[OnTriggerLeave]]
If you want the code to run only once when triggered, you should specify a variable to register when the zone is triggered and a reset block to turn it off and allow the code to run again later on.  The reset block can either be timed or reset when the cell respawns.
 
 
'''Examples:'''
 
'''Timed Reset'''
short triggered
float timer
begin onTrigger
  if triggered == 0
  'do something
  set triggered to 1
  set timer to 2 ;2 delay before reset
  endif
end
begin gameMode
  if triggered == 1
    if  timer <= 0
      set triggered to 0
    else
      set timer to timer - getSecondsPassed
    endif
  endif
end
 
'''Reset on Cell Respawn'''
short triggered
   
   
begin onTrigger
  if triggered == 0
  'do something
  set triggered to 1
  endif
end
begin onReset
  set triggered to 0
end
==Notes==
*This delay is particularly needed when the TriggerZone is used to move the player. If a [[MoveTo]] is used on the player within the OnTrigger block, the code runs one extra time next frame and, without the delay, will move the player again, and again, ... , causing the game to (pratically) freeze.
==See Also==
[[GetActionRef]]<BR>
[[OnTriggerActor]]
[[Category: Blocktypes]]
[[Category: Blocktypes]]

Latest revision as of 18:35, 30 July 2009

Syntax:

 begin OnTrigger TriggeringRefID

Example:

 begin OnTrigger
 begin OnTrigger player 

This block will be run when something triggers the scripted object by colliding with it. If you specify a TriggeringRefID, the block will only run when that specific reference triggers the object; otherwise, the block will run when anything triggers the scripted object.

However, with a TriggerZone, the block will continue running every frame until all triggering refs leave the zone.

If you want the code to run only once when triggered, you should specify a variable to register when the zone is triggered and a reset block to turn it off and allow the code to run again later on. The reset block can either be timed or reset when the cell respawns.


Examples:

Timed Reset

short triggered
float timer

begin onTrigger
 if triggered == 0
  'do something
  set triggered to 1
  set timer to 2 ;2 delay before reset
 endif
end

begin gameMode
 if triggered == 1
   if  timer <= 0
     set triggered to 0
   else
     set timer to timer - getSecondsPassed
   endif
 endif
end

Reset on Cell Respawn

short triggered

begin onTrigger
 if triggered == 0
  'do something
  set triggered to 1
 endif
end

begin onReset
  set triggered to 0
end

Notes[edit | edit source]

  • This delay is particularly needed when the TriggerZone is used to move the player. If a MoveTo is used on the player within the OnTrigger block, the code runs one extra time next frame and, without the delay, will move the player again, and again, ... , causing the game to (pratically) freeze.


See Also[edit | edit source]

GetActionRef
OnTriggerActor