Difference between revisions of "OnActivate"

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
imported>Elim Garak
imported>Syscrusher
(→‎Notes: Fixed a grammatical error, and added a precautionary note about recursive Activate calls.)
 
(18 intermediate revisions by 8 users not shown)
Line 4: Line 4:
This block will be run once when the scripted reference is activated.
This block will be run once when the scripted reference is activated.


'''Notes:'''
==Notes==
*Using OnActivate will prevent normal activation of the object. To use the object's default activation you must call [[Activate]] on it.
*Using OnActivate will prevent normal activation of the object. To use the object's default activation you must call [[Activate]] on it. If the second argument to this [[Activate]] call (whether or not to run the OnActivate block) is true, you will call this same block recursively, which can cause a game hang or crash to desktop.
 
*Animations on activators are carried out using [[PlayGroup]]. This is helpful if your activator has an animation associated with it.


*If you want to do something specific depending on what activated the object, use [[IsActionRef]] or [[GetActionRef]] inside the OnActivate block. They won't return the correct ActionRef in any other block.
*If you want to do something specific depending on what activated the object, use [[IsActionRef]] or [[GetActionRef]] inside the OnActivate block. They won't return the correct ActionRef in any other block.


*This block (and perhaps the entire script --[[User:Haama|Haama]] 18:52, 13 July 2007 (EDT)) runs immediately when called from an external script. There were a few things that were posted before that this should clarify:
*The activator type of object has NO default activation.  
#Activation occurs before the next line of code of the calling script is processed, and not in the next frame
 
#Any number of objects can activate one object, within one frame, and they will all be run (though see notes on [[Activate#Nesting|Nesting]])
*Locked doors, containers and books are activated a second time automatically when you open the lock or take the book. To find out when a door was unlocked, for example, you can wait for '''[[GetLocked]] == 0''' in the OnActivate-block.


*It's possible to nest activations. However, you can only have 5-6 nests at any given time (see [[Activate#Nesting|Nesting]] for more information)
*Clicking on items in inventory causes the [[onEquip]] block to run, not the '''onActivate''' block.
**However, you can make an item run its own onActivate block in the inventory menu (MenuMode 1008, MenuMode, onEquip, etc.) with '''''Activate player, 1'''''.


*The activator type of object has NO default activation.  
*If you create an object and activate it in the same frame, its OnActivate block may not run. See [[PlaceAtMe#Usage_in_same_frame_as_creation|PlaceAtMe]] more info.


*Locked doors, containers and books are activated a second time automatically when you open the lock or take the book. To find out when a door was unlocked, for example, you can wait for '''[[GetLocked]] == 0''' in the OnActivate-block.
*''OnActivate player'' will compile but act as ''OnActivate'' - meaning when an NPC activates the object its normal activation will be prevented. A common mistake.


*Reading a Book in the world will fire OnActivate, but reading it in the inventory will fire OnEquip.
*If the player activates any object while sitting, then any failure to call Activate in the OnActivate block of that object will force the player to stand up. There is currently no way to allow the player to remain seated while activating an object that overrides the default activation.


==See Also==  
==See Also==  
[[Begin]]
*[[Begin]]
 
*[[IsActionRef]]
[[IsActionRef]]
*[[GetActionRef]]
*[[Crashes#Activating_a_Container_.28including_NPC.29|Activating a Container (including NPCs)]] (CTD related to '''Activate'''/'''OnActivate''')
[[GetActionRef]]
*[[PlayGroup]]


[[Category: Blocktypes]]
[[Category: Blocktypes]]

Latest revision as of 00:07, 26 December 2013

Syntax:

 begin OnActivate 

This block will be run once when the scripted reference is activated.

Notes[edit | edit source]

  • Using OnActivate will prevent normal activation of the object. To use the object's default activation you must call Activate on it. If the second argument to this Activate call (whether or not to run the OnActivate block) is true, you will call this same block recursively, which can cause a game hang or crash to desktop.
  • Animations on activators are carried out using PlayGroup. This is helpful if your activator has an animation associated with it.
  • If you want to do something specific depending on what activated the object, use IsActionRef or GetActionRef inside the OnActivate block. They won't return the correct ActionRef in any other block.
  • The activator type of object has NO default activation.
  • Locked doors, containers and books are activated a second time automatically when you open the lock or take the book. To find out when a door was unlocked, for example, you can wait for GetLocked == 0 in the OnActivate-block.
  • Clicking on items in inventory causes the onEquip block to run, not the onActivate block.
    • However, you can make an item run its own onActivate block in the inventory menu (MenuMode 1008, MenuMode, onEquip, etc.) with Activate player, 1.
  • If you create an object and activate it in the same frame, its OnActivate block may not run. See PlaceAtMe more info.
  • OnActivate player will compile but act as OnActivate - meaning when an NPC activates the object its normal activation will be prevented. A common mistake.
  • If the player activates any object while sitting, then any failure to call Activate in the OnActivate block of that object will force the player to stand up. There is currently no way to allow the player to remain seated while activating an object that overrides the default activation.

See Also[edit | edit source]