Say you use a Perk with an activation entry point, to give the player additional options when activating certain objects. When that option is chosen, you can then run additional script, but until now I had never found a way to get a reference to the object that was activated, which could then be used in subsequent script.
What I found is that when used in the Perk Entry result script, the FOSE function http://fose.silverlock.org/fose_command_doc.html#GetCrosshairRef will return a reference to the object that was just activated by the Player. Since you can't define variables in result scripts, it needs to be assigned to
I'll illustrate with a specific example: After seeing http://www.fallout3nexus.com/downloads/file.php?id=13267, I started fiddling with a little mod that would let you harvest the brains from corpses (muahahaha!). I wanted to use an activation perk so it would be similar to the way the Cannibal Perk works, that is, when activating a corpse (with an intact head of course) you get an option to harvest the brain, and when chosen the head is dismembered and a brain is added to Player inventory. Adding the brain to inventory is simple (and even getting the Player to run a custom 3rd-person idle animation wasn't that hard - but that's another story), but in order to dismember that corpse's head I needed a reference to that actor. Here's a http://www.youtube.com/watch?v=Y8TFRJjrKcI to show what I wanted to do.
So here's the "trick". In the perk result script, I did this:
set BrainHarvest.rTarget to GetCrosshairRefStartQuest BrainHarvest
...and here's a simplified version of the BrainHarvest quest script:
ScriptName BrainHarvestScriptref rTargetBegin GameMode PrintToConsole "ActionRef: %n" rTarget rTarget.Kill Player 1 rTarget.AddItem BrainHarvestToken 1 Player.AddItem BrainHuman 1 ResetQuest BrainHarvest End
Of course, the http://fose.silverlock.org/fose_command_doc.html#PrintToConsole line is unnecessary, but it's a quick and simple way to demonstrate that the activated target ref was assigned correctly. Also, it's not strictly necessary to encapsulate the bulk of the code in a quest script - you could just as easily continue to use the quest variable
So why do it this way instead of using an OnActivate block in an object script attached to the specific objects you want to affect? At least three reasons I can think of at the moment:
Mod compatibility -
By adding or modifying an object script on existing vanilla objects, the object's or script's record is completely overridden, creating potential mod conflicts. This is why http://www.fallout3nexus.com/downloads/file.php?id=4447 and http://www.fallout3nexus.com/downloads/file.php?id=3388 use activation perk to add options to the workbench. Many previous and beginner modders modified workbenches by directly altering the vanilla workbench script, meaning none of them can work together unless someone manually combined (re-wrote) their scripts to integrate them (if even possible), something that cannot be automated.
Conditions -
By using a Perk Entry, you have access to the editor's built-in http://geck.gamesas.com/index.php/Category:Conditions forms, a simple, powerful, and more efficient way to narrow down the specific conditions under which your script will run. For example, in my example above, at the moment the "Harvest Brain" option is only presented if the Player is sneaking, the activated actor is not a creature, is dead, has a head, and does not contain the BrainHarvestToken flagging it as already harvested (hmm... I guess that one's unnecessary now). All that would otherwise create at least several lines of code to clutter up script.
Convenience -
This doesn't really apply if you're only interested in doing something on activation on one particular base object, but an activation perk allows you to add an activation option to EVERY object that can be activated in the game at once. Of course, you almost certainly want to narrow this down with Conditions, but again take my example. To do the same thing via OnActivate blocks, I'd need to add/modify the script on every NPC, and that would still not cover any NPCs added by other mods.
Hmm... this turned into a bit of an article. Well, if you understood the first few sentences, that's all you really need ^_^
EDIT: forgot to add the video!