Jump to content

I need help on simple code involving OnHit and PushActorAway


Recommended Posts

Hello, I am very new to all of this and wanted to just make a simple mod that sent all enemies flying away when hit. I have made the little script in the screenshot, but I am not sure what the reference number I should be adding to the PushActorAway command. I figured it was just the target reference but when I go to compile it just says "type mismatch on parameter 1 - cannot pass a objectreference to a actor". I am assuming I need to change the value where the reference number should be, but I am not sure how to reference the character being hit in this case. I am sure it is something simple I missed, but I'd appreciate any help. Thanks!

 

 image.thumb.png.d58d862ab5363dee689955b057cdc48a.png

Link to comment
Share on other sites

You'll need to register the script for the OnHit event because the native code only sends this event to registered Papyrus scripts.

Scriptname YOURSCRIPTNAME extends Actor

Event OnInit()		; event is sent when this script is initialized (e.g. installed the mod the Actor is part of, started a new game if vanilla, etc.)
	RegisterForHitEvent(akTarget = Self)
EndEvent

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

	If akTarget as Actor		; akTarget is an Actor
		(akTarget as Actor).PushActorAway(akAggressor, 100.0)		; akTarget (the Actor this script is attached to) will be pushed back
	EndIf
	RegisterForHitEvent(akTarget = Self)		; native code unregisters the script for OnHit after it is sent so you need to reregister

EndEvent

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

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