MSFD Checking activation of an item and activating it
An item is usually activated when you press the spacebar to "use" it. Most items have a standard action that is performed when they are activated: Doors open, chests display their content, Actors initiate dialogue etc. The OnActivate function allows you to intercept the standard action and do something else or check a condition first:
OnActivate
If ( OnActivate == 1 )
This get set to one for one frame when the object is activated. OnActivate resets itself as soon as the function is called, so only one script can report OnActivate successfully, and you should only have one OnActivate call in your script at each moment. OnActivate short-circuits the normal behavior of the object -to perform the standard action of the object once OnActivate has been called, you have to use the activate command:
Activate
activate (if script is on the object to activate)
Activate can be used to trigger the standard action of an object, after OnActivate has been called.
Standard actions called by Activate are:
Doors -> Open (Possibly broken in Original MW, with v1.6.1820 it definitely works).
LoadDoors -> Open (If used with OnActivate)
Containers -> Open (show contents)
Books/scrolls -> Display text to read.
Activators -> Nothing
Actors -> Dialogue
Weapon -> Pick up
Armor -> Pick up
Miscellaneous -> Pick up
Not tested, but I assume:
Equip. Lights -> Pick up
Other Lights -> Nothing
Probes -> Pick up
Apparatus -> Pick up
Example script:
The following script demonstrates the use of OnActivate nicely. It is attached to a container object, a chest that does NOT advertise its trap like the normal in-game ones do:
Begin Trap_script
short done
if ( OnActivate == 1 )
if ( done == 1 ) ;do-once condition
Activate
return
else
Cast, "flame", Player ;damage to player
set done to 1
Activate ; Call standard action: the chest opens
endif
endif
End trap_script
Notes: According to my testing, the activate function can not be used by itself, without OnActivate in the same script. The OnActivate and Activate functions can be in different parts of the script, though. However, Activate will not work before OnActivate has not at least been called once. There have been reports that the object also must have been manually activated at least once within the last 72 hours, so apparently the game eventually forgets that OnActivate has been called previously. Containers require manual activation each load session (forum info / Phaedrus). Play around with this testscript (I had it attached to a door) to see for yourself:
Begin GBG_closing_door
Short done
if ( OnActivate == 1 )
MessageBox "Thank you for activating"
endif
if ( done == 0 )
If ( GetDistance, Player < 100 )
set done to 1
MessageBox "Player close"
endif
endif
if ( done == 1 )
If ( GetDistance, Player > 200 )
MessageBox "Sesame"
Activate
set done to 0
endif
endIf
End
There have also been various reports about difficulties with on OnActivate in general, in my experience, avoiding to use more than one OnActivate in a script is the safest way to go. Also be aware that for items in your inventory, OnPCEquip may be the function to use instead of OnActivate, as OnActivate does not get called by moving the item over the Player icon.
Info from the UESP: There is an undocumented feature in the Activate function by specifying the player after the function, for example:
begin RemoteContainer
short OnPCEquip
if ( OnPCEquip == 1 )
set OnPCEquip to 0
"dh_remote_chest_01"->Activate, player
endif
end
If the container is persistent (references persist) this script should open the container wherever the player is. This is a great way to create 'carryable' containers by attaching a script similar to the above to a ring or similar item.