Activate

From the Oblivion ConstructionSet Wiki
Revision as of 23:38, 12 July 2007 by imported>Haama (Extra Failed Activation note)
Jump to navigation Jump to search

Syntax:

Activate ActivatorID (optional), NormalActivationFlag (optional) 

Example:

Activate player 
Activate 
Activate player, 1 

This function tells the object to perform its default activation.

If ActivatorID is omitted, the Activate command will use the calling reference's "current activator". This is very useful inside of OnActivate blocks where you want the activation to proceed normally except under certain circumstances.


That means that this:

Activate

Is equivalent to this:

ref actingref
set actingref to GetActionRef
Activate actingref


If ActivatorID is included, the calling reference will perform its default activation as if activated by ActivatorID.


Object Type Activation
NPC Dialogue
Container Opens
Door Opens
Weapon, armor, etc Picks Up
Book/Scroll Reads


If NormalActivationFlag is omitted, the calling reference performs its default activation, bypassing any OnActivate script that might be on it. This is often how you want to use Activate, since most times you are calling Activate on the object itself from inside an OnActivate block after performing some check or other action.

If the NormalActivationFlag is 1, the calling reference will not bypass any OnActivate script on it. This flag basically is an override of default activation as represented in the above chart. Use this with care -- if you call Activate on the object itself from inside an OnActivate block you will trigger an infinite loop.

When used with care, this can be an extremely powerful tool to cause calls to Activate to be used as pseudo function calls between scripted objects and even spells. The reference passed in can be used as arguments to tell the object being activated what to do. This use of Activate is not as intended and requires very careful planning and execution.

Example 1:

If you call this script on a door, the door will behave as if the player had activated it (i.e. if a load door, the player will be teleported to the door's target location).

Activate player 


Example 2:

Whatever triggered the OnActivate block will also Activate, just as if this script wasn't here.

begin OnActivate 
if MyCrazyCondition == 1 
  Activate
else 
  ; do something else 
endif 
end 


Example 3:

This script will trigger an infinite loop -- once the scripted object is activated the OnActivate block will continue to be run forever.

float infinity 
begin OnActivate 
  ; you should NEVER do this!! 
  set infinity to infinity + .1 
  message "Infinity = %.1f", infinity 
  activate player 1 
end 

(I doubt this, see Nesting info below--Haama 00:32, 13 July 2007 (EDT))


Example 4:

This is the proper way to use the NormalActivationFlag

begin OnActivate 
  ; trigger some other reference when I am activated by the player 
  if IsActionRef player == 1 
     MyGate.Activate player 1 
  endif 
end 


Nesting

You can nest activations within other activations. For example, a quest script activates an activator

SomeActivator.Activate player, 1

which in turn activates another activator

scn SomeActivatorScript

begin onActivate
  SomeOtherActivator.Activate player, 1
end

Note, however, that you can only nest 5 activations at a time. At a time is a little hard to define here, since onActivate blocks run instantly and before the next line of code is processed. This really means that if 4 other scripts are still being processed and an activation is made during the 5th script, that last activation will be ignored (the script skips the line). This applies to any activation, even if they're different objects or different scripts.