Jump to content

[LE] OnHit and filtering out enchantment hits


Recommended Posts

So I've been struggling for the past two days trying to nail down this issue... While attempting to set up an "OnHit" event and filter out enchantment hits, I've come to the conclusion that the wiki entry for the event is either out of date or just plain wrong in just about every way for Skyrim SE.

 

According to the wiki, doing something as simple as this (corrected a few issues as the wiki's entry as it is is both incomplete and incorrect);

Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, \
bool abBashAttack, bool abHitBlocked)

Form RightHandSword = (akAggressor as Actor).GetEquippedWeapon(0); this gets the sword that the enemy had in their right hand and stores it as an object variable

If (akSource as Weapon) == RightHandSword

;do code stuff

EndIf
EndEvent

Should be enough to filter out any and all enchantments on a weapon so that the event is only triggered once regardless of how many enchants are on the weapon. However in my testing - several hours mind you - this is not the case. If you use the above code it will still proc the event twice - once for the weapon and once for the enchantment.

 

I've tried changing cast types, and everything else I could think of all to no avail. The event will always fire at least twice if the item in question has an enchantment on it.

 

Below is the trace log for this code snippet in a brand new game with the following mods; Address Library for SKSE Plugins, Stay At The System Page, Unofficial Skyrim SE Patch, SkyUI SE, and of course SKSE 2.0.19 (bare minimum for testing purposes):

 

Code

 

 

 

Form RightHandSword = (akAggressor as Actor).GetEquippedWeapon(0)

If ((akSource as weapon) == RightHandSword)
    Debug.Trace("Weapon ID: "+RightHandSword)
EndIf

 

 

 

Log

 

 

 

 

[01/02/2021 - 01:21:27AM] Papyrus log opened (PC)
[01/02/2021 - 01:21:27AM] Update budget: 1.200000ms (Extra tasklet budget: 1.200000ms, Load screen budget: 500.000000ms)
[01/02/2021 - 01:21:27AM] Memory page: 128 (min) 512 (max) 153600 (max total)
[01/02/2021 - 01:21:34AM] VM is freezing...
[01/02/2021 - 01:21:34AM] VM is frozen
[01/02/2021 - 01:21:34AM] Reverting game...
[01/02/2021 - 01:21:39AM] Loading game...
[01/02/2021 - 01:21:40AM] VM is thawing...
[01/02/2021 - 01:21:40AM] InitWidgetLoader()
[01/02/2021 - 01:21:55AM] Weapon ID: [WEAPON < (00012EB7)>]
[01/02/2021 - 01:22:04AM] Weapon ID: [WEAPON < (00012EB7)>]
[01/02/2021 - 01:22:05AM] Weapon ID: [WEAPON < (00012EB7)>]
[01/02/2021 - 01:22:09AM] Weapon ID: [WEAPON < (00012EB7)>]
[01/02/2021 - 01:22:14AM] Weapon ID: [WEAPON < (00012EB7)>]
[01/02/2021 - 01:22:17AM] Weapon ID: [WEAPON < (00012EB7)>]
[01/02/2021 - 01:22:21AM] Weapon ID: [WEAPON < (00012EB7)>]
[01/02/2021 - 01:22:23AM] Weapon ID: [WEAPON < (00012EB7)>]
[01/02/2021 - 01:22:35AM] Weapon ID: [WEAPON < (00028DE8)>]- switched to enchanted mace
[01/02/2021 - 01:22:35AM] Weapon ID: [WEAPON < (00028DE8)>]
[01/02/2021 - 01:22:41AM] Weapon ID: [WEAPON < (00028DE8)>]-
[01/02/2021 - 01:22:41AM] Weapon ID: [WEAPON < (00028DE8)>]
[01/02/2021 - 01:22:47AM] Weapon ID: [WEAPON < (00028DE8)>]-
[01/02/2021 - 01:22:47AM] Weapon ID: [WEAPON < (00028DE8)>]
[01/02/2021 - 01:23:03AM] Weapon ID: [WEAPON < (00028DE8)>]-
[01/02/2021 - 01:23:03AM] Weapon ID: [WEAPON < (00028DE8)>]

 

 

 

As you can see, the weapon without the enchant procs the event once, while the enchanted weapon procs the event twice. Note the double timestamps.

 

The script in question is applied via a magic effect which is on a Constant > Self ability that is attached to the Player Reference (alias) on the ParentQuest for my mod.

 

Are other people having this issue? Am I the only one affected? Perhaps it's my set up? I don't know. I could use more eyes on this problem and if it isn't just me, the wiki needs to be updated at the very least.

 

Believe me when I say I've scoured everywhere trying to find an answer and I'm usually one to never ask for help but this leaves me at a complete loss given the information that the wiki is giving me. Either it works or it doesn't, and right now it doesn't, but why?

 

Any help would be much appreciated. Thanks.

 

Cyan Ian

Link to comment
Share on other sites

Just a thought, but have you tried doing:

Weapon RightHandSword = (akAggressor as Actor).GetEquippedWeapon(0)

You can also try putting in a time check to force it if nothing else works, something like this:

Float TimeCheck = 0.0


Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, \
bool abBashAttack, bool abHitBlocked)

Weapon RightHandSword = (akAggressor as Actor).GetEquippedWeapon(0); this gets the sword that the enemy had in their right hand and stores it as an object variable

If (akSource as Weapon) == RightHandSword
    Float CurrentTime = Game.GetRealHoursPassed()
    If (CurrentTime - TimeCheck) > 1
        TimeCheck = CurrentTime
        ;do code stuff
    Endif
EndIf
EndEvent
Link to comment
Share on other sites

 

Just a thought, but have you tried doing:

Weapon RightHandSword = (akAggressor as Actor).GetEquippedWeapon(0)

You can also try putting in a time check to force it if nothing else works, something like this:

Float TimeCheck = 0.0


Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, \
bool abBashAttack, bool abHitBlocked)

Weapon RightHandSword = (akAggressor as Actor).GetEquippedWeapon(0); this gets the sword that the enemy had in their right hand and stores it as an object variable

If (akSource as Weapon) == RightHandSword
    Float CurrentTime = Game.GetRealHoursPassed()
    If (CurrentTime - TimeCheck) > 1
        TimeCheck = CurrentTime
        ;do code stuff
    Endif
EndIf
EndEvent

 

 

Yes, I have. As stated before I've tried casting of every sort that I could think of and while a time check is an interesting idea, it doesn't quite address the fact that the OnHit event isn't functioning like it's supposed to. At the moment I'm just trying to ascertain whether this is a 'me' issue, or if OnHit somehow got broken between Oldrim and SE.

 

Thank you for the time check idea at the very least. If this is just the nature of the event I may have to use it.

Link to comment
Share on other sites

Ahh gotcha, I can't be sure about that. I haven't really needed to use the OnHit event for anything recently.

 

Well, I ran a test using your method and changed the 1 to 0.000138889 (0.5 second interval of an hour) and it's working, so there 'is' that. In the event anyone else stumbles across this issue and needs to do something similar they can use this to start:

;Local Variable
Float TimeCheck = 0.0

Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)
	Weapon RightHandSword = (akAggressor as Actor).GetEquippedWeapon(0)
	If (akSource as Weapon) == RightHandSword
		Float CurrentTime = Game.GetRealHoursPassed()
		If (CurrentTime - TimeCheck) > 0.000138889
			TimeCheck = CurrentTime
			Debug.Trace("Weapon ID: "+RightHandSword)
		EndIf
	EndIf
EndEvent

I still would like to know if anyone else is experiencing the same thing. ;/

Link to comment
Share on other sites

Not able to test but is it possible to cast the akSource as a magic effect or something, rather than a weapon, and disregard it?

 

Not to my knowledge. The wiki states "akSource: The Weapon, Spell, Explosion, Ingredient, Potion, or Enchantment that hit this reference". However if you look at the ObjectReference script it states specifically "Event received when this object is hit by a source (weapon, spell, explosion) or projectile attack". I've yet to have any issues with weapon or spell - haven't tried doing anything with explosion or projectile - but as you can see it completely omits ingredient, potion, and enchantment. It's quite possible that they're omitted for a reason.

 

 

If you use SKSE you can add a trace to print the type, see if it differentiates between weapon and magic/enchantment.

 

Form.GetType()

 

I'll get back to you on that. :wink:

 

EDIT

 

Trace returns 41 which is kWeapon form every time you get hit regardless of whether it's the enchant proc or not. I expected as much since the wiki itself states that:

 

 

Also, if this reference is an Actor and the projectile was caused by a weapon enchant, the enchanted weapon will be in akSource.

This event is called multiple times when akSource has associated magic effects. If a sword has an enchantment with 2 effects, OnHit will be called 3 times - once for the physical damage of the sword and once for each magic effect. In all cases, akSource is the sword and not the enchantment. This also applies to spells (one hit for the spell projectile, and one for each associated magic effect).
Essentially it can't distinguish between the two for whatever reason though you'd think going by what the wiki states, it's supposed to. I never scripted with Oldrim so I can't say for sure whether that behavior was indeed the case but it certainly appears not to be in Skyrim SE.
Also, casting as MagicEffect returns "None" in all instances.
Link to comment
Share on other sites

Just sharing some data.


The 'OnHit()' event will always fire more than once if the object that hit it has an enchantment.


I have encountered this issue about a year ago with my main boss fight, although everything work as they should with normal weapons when i test the fight scene using my mod's weapons which are unenchanted but they fire multiple enchanted projectiles, explosions and spells, EVERYTHING GOT COMPLETLY F***** UP !!!!.


In my case it was easy to resolve, i just added "Empty" states to all the scene scripts that had or were affected by the 'OnHit()' event.


For example:

STATE SEQ01

Event OnHit()

GoToState("Empty")

" Receives only one hit "


;Do All My Stuff


GoToState("SEQ01")

Endevent

EndState


I believe that the first "OnHit" event with an enchanted weapon will always be the weapon itself and then the rests of the events are the 'Enchantments'.


Happy new year everybody !.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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