Jump to content

Can't seem to get OnHit to fire on player alias script


AsteroidLeaf

Recommended Posts

I'm at a bit of a loss here. I've been trying every way possible I know how to debug to figure out why this OnHit event is not firing in my script.

I have a player alias attached to a quest. The quest itself doesn't do anything (i.e no stages, no quest script)

My script is attached to the player alias which is correctly linked to the player reference.

In my script OnPlayerLoad, i RegisterForHitEvent(Self) which i have confirmed using message box debugs that it is firing and is targeting Self as an Actor.

However, I set up a basic OnHit() event and the only thing in it at all is a debug message at this point that's just supposed to tell me when the event fires, regardless of any other codition.

In game All of my other events fire as expected, however, I can't seem to get OnHit to do anything at all, even if only to just tell me it was triggered and do nothing.

I have tried shooting, bashing, grenades, melee weapons all to try and see if any kind of damage would be registered, to no avial.

My goal is to have the event fire when the player does damage to another actor (akTarget) labeling the player as (akAgressor) so that i can perform some checks and perform other logic.

I've also tried perusing bethesda's source files to see if they are using it differently then i expect. It appears like the function itself needs very little in the way of conditions in order to fire and I haven't done anything out of the ordinary.

Any ideas?

EDIT: one idea i had was perhaps needing to create a property within the script for the player reference and somehow let OnHit know it needs to be listening to the Player's actions. However, I didn't think this would be necessary considering The alias script itself is attached already to the player, and the register event from before correctly identified as an Actor.

Link to comment
Share on other sites

The ReferenceAlias must hold the reference that is hit by the player, due to how OnHit works.

If you attach a script like the one below to the player, the script would receive the OnHit event when the player is hit.

Scriptname YOURSCRIPTNAME extends ReferenceAlias Const


Event OnAliasInit()
	ObjectReference myAliasedRef = GetReference()
	If !myAliasedRef
		Debug.MessageBox("RefAlias is not filled")
		Return None
	EndIf
	RegisterForHitEvent(akTarget = Self, akAggressorFilter = Game.GetPlayer())
EndEvent


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

	; your code


	; reregister if needed as the game unregisters this script after the first sent OnHit

EndEvent

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

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