Jump to content

Dirty Tutorial: Dynamically getting events from nearby NPCs


MofoMojo

Recommended Posts

I see a lot of questions about getting events, such as onhit, of nearby NPCs and there's a VERY easy way to do this. ActiveScriptEffects can access ANY events of actors that they are applied to. For instance, I have my own "Breath of Frost" script that I use because I don't like the way paralysis works in the game. I wanted the target actor to be frozen in place when they were HIT and the effect was applied. Here's my sample script:

 

Scriptname mm_BeluaBreathOfFrostScript extends ActiveMagicEffect  

Spell Property mm_BeluaVampireBreathOfFrostSpell Auto
Actor TheTarget

Event OnEffectStart(Actor target, Actor caster)
if caster.GetActorValue("Magicka") < 25
	caster.UnEquipSpell(mm_BeluaVampireBreathOfFrostSpell,2)
	Self.Dispel()
	target.DispelSpell(mm_BeluaVampireBreathOfFrostSpell)
else
	caster.DamageActorValue("Magicka",25)
	TheTarget = target
endif
EndEvent

Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)
TheTarget.EnableAI(false)
utility.wait(5)
TheTarget.EnableAI(true)
EndEvent

 

Ignore the magicka checks and damage to the player. As long as the effect is applied to the target, the OnHit even will trigger when the target is hit. In this case, it disables the target's AI for 5 seconds every time they're hit. But you can access any of the events on an Actor or the events in ObjectReference for that Actor while the effect is still in duration on the target.

 

So, to expand this a bit more, create a dummy effect script that contains all your events you might be interested in and associate that with a magic effect and a spell to reference that script. Create a cloak effect whose Assoc item 1. points to this spell. Finally, create a new spell that references THIS effect and provide a magnitude as your radius of affected NPCs that you want to intercept those specific events from the first effect script and you should be done. If you need access to your target NPC's Actor or ObjectReference from within the event, just use a script variable like I did above with TheTarget and reference that in your events.

 

Hope that helps some.

 

-MM

Edited by MofoMojo
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...