enderalse/scripts/source/_00e_dragonpriestcombatrotationscript.psc

72 lines
1.7 KiB
Plaintext
Raw Normal View History

Scriptname _00E_DragonPriestCombatRotationScript extends activemagiceffect
{Fixes dragon priests' tendency to get stuck in combat, looking away from their combat target and so unable to attack}
Actor Property PlayerRef Auto
Actor TargetRef
Bool bTranslating
Bool bEffectFinished
Event OnEffectStart(Actor akTarget, Actor akCaster)
TargetRef = akCaster
If TargetRef == PlayerRef
Dispel()
Return
EndIf
If TargetRef
RegisterForSingleUpdate(1.0) ; Wait a bit before applying the fix, it could be a false positive
EndIf
EndEvent
Event OnEffectFinish(Actor akTarget, Actor akCaster)
bEffectFinished = True
EndEvent
Event OnDying(Actor akKiller)
bEffectFinished = True
EndEvent
Event OnUpdate()
Actor akCombatRef = TargetRef.GetCombatTarget()
If akCombatRef && Math.Abs(TargetRef.GetHeadingAngle(akCombatRef)) >= 15.0 ; && TargetRef.GetDistance(akCombatRef) < 256.0
If bEffectFinished == False
bTranslating = True
; Turn the NPC to its combat target
TargetRef.TranslateTo(TargetRef.X, TargetRef.Y, TargetRef.Z, TargetRef.GetAngleX(), TargetRef.GetAngleY(), _NormAngle(TargetRef.GetAngleZ() - TargetRef.GetHeadingAngle(akCombatRef)), 0.0, 90.0)
Utility.Wait(2.0)
; Need to force-stop translation for the NPC to start moving
_StopTranslation()
EndIf
EndIf
If bEffectFinished == False
RegisterForSingleUpdate(1.0)
EndIf
EndEvent
Event OnTranslationComplete()
_StopTranslation()
EndEvent
Event OnTranslationFailed()
_StopTranslation()
EndEvent
Float Function _NormAngle(Float fAngle)
While fAngle < 0.0
fAngle += 360.0
EndWhile
While fAngle >= 360.0
fAngle -= 360.0
EndWhile
Return fAngle
EndFunction
Function _StopTranslation()
If bTranslating
bTranslating = False
TargetRef.StopTranslation()
EndIf
EndFunction