https://github.com/warmist/dfhack/blob/master/Lua%20API.rst#id56I'm thinking triggering on specific reaction (it has limitation that reaction must produce something (e.g. something worthless)) and then searching a cage near to the building and then running some lua that would change civ (maybe modify hist fig so it does not have "enemy to this group" entries and add "member of this group"). "Friendship" is required for different races to do jobs in fort, but e.g. catching trolls and using them as cannon fodder is possible without using Friendship (which btw needs some work >.>)
onProjItemCheckImpact-> allows exploding (or something other you could think of) on hit of any projectile (including siege weapons)
onItemContaminateWound-> allows triggering on weapon contaminating a wound (which is afaik almost always it hits) so magical weapons are possible and/or weapon wear.
https://github.com/warmist/dfhack/blob/master/Lua%20API.rst#id61This is added by ag and is the way you could "bind" those triggers to actions (i could help tweak, explain and write some of the effects). The mod should have it's own init.lua in raws dir (thus get copied when you create a world. It allows automatic loading/unloading of triggers/actions etc... (you would not want them to mess up the worlds without mod or with different mod)
edit: forgot this one:
onReactionComplete -> allows detecting/editing when reaction finishes thus allowing optional items based on skill, failing based skill (or lack of) transmuting materials in some strange way (e.g. if reagent A is mat X and reagent B is mat Y make the product mat Z), also messing with unit making the reaction (adding skill, changing traits, adding syndromes, killing/healing, making him a ghost etc...)
And other note: ghost can do jobs according to testing in advfort so using expwnent event system, when a new job is created you could check reaction name and assign a ghost to it. It might work in fort mode too.