Jump to content

[Papyrus F4] Detecting when the player fires a weapon.


customtemplar

Recommended Posts

I need a way, preferably an Event, that will let me trigger a script every time the player fires a weapon, including each time it cycles for automatic weapons. There is already an event OnPlayerFireWeapon, but this is only active when the player is out of combat.

 

I could use a magic effect attached to the weapon for what I want to do, but I'm looking for a way that is more ambiguous and doesn't require editing every weapon or projectile entry. Another option is to edit the event OnPlayerFireWeapon to activate regardless of if the player is in combat, but I don't know how or if it's possible to make new events.

 

If anyone is aware of an method I can do this, it would be huge help, this is the only barrier to the mod I'm near releasing.

Link to comment
Share on other sites

The best way, I think, would be to use Weapon's GetAmmo() function (first using Game.GetPlayer().GetEquippedWeapon(0) to get the Weapon form), then check whether the player's ammo has dropped from the previous OnTimer(int aiTimerID) event. All of this would be in a quest, of course.

Link to comment
Share on other sites

The event you're looking for is the weaponFire anim event on the player!

RegisterForAnimationEvent(Game.GetPlayer(), "weaponFire")

Event OnAnimationEvent(ObjectReference akSource, string asEventName)
	If (akSource == Game.GetPlayer() && asEventName == "weaponFire")
		Debug.Notification("The player fired his weapon.")
	EndIf
EndEvent

Fires each round for automatic weapons too. If you need any reference code, Car Launcher (a for-fun mod - don't judge) fires a random car each time the player fires if you have the Car Launcher barrel attached to a Fat Man or SMG.

Link to comment
Share on other sites

The event you're looking for is the weaponFire anim event on the player!

RegisterForAnimationEvent(Game.GetPlayer(), "weaponFire")

Event OnAnimationEvent(ObjectReference akSource, string asEventName)
	If (akSource == Game.GetPlayer() && asEventName == "weaponFire")
		Debug.Notification("The player fired his weapon.")
	EndIf
EndEvent
Fires each round for automatic weapons too. If you need any reference code, Car Launcher (a for-fun mod - don't judge) fires a random car each time the player fires if you have the Car Launcher barrel attached to a Fat Man or SMG.

 

Sure. Find a simple and elegant solution, why don't'cha. :tongue:
Link to comment
Share on other sites

One of the rare moments Papyrus decides to allow it... :P

 

And as usual with Papyrus (no surprises there) there is a caveat - weaponFire also fires when throwing grenades (but with the difference that weaponAttach fires beforehand), so you should watch out for that if it's important that you not act on grenade throwing events.

Link to comment
Share on other sites

  • 1 month later...

Thanks this helps quite a bit for something I'm working on too!

 

Now would you by chance happen to know what the name for the reload animation is, or where to find a list of all animations is, so I can look for it myself? I tried "weaponReload" & "Reloadweapon" but neither seemed to worked.

 

 

Cheers,

Mechtechnal

Link to comment
Share on other sites

Thanks this helps quite a bit for something I'm working on too!

 

Now would you by chance happen to know what the name for the reload animation is, or where to find a list of all animations is, so I can look for it myself? I tried "weaponReload" & "Reloadweapon" but neither seemed to worked.

 

 

Cheers,

Mechtechnal

As far as I can tell, there isn't an animation event for reloading a weapon.

Link to comment
Share on other sites

Ehm. Sorry to cut in again. :P

 

reloadComplete is fired when a reload finishes.

 

If you want to find out a list of animation events, you can extract the HKX animation files from Fallout4 - Animations.ba2, then unpack the ones you want to examine with hkxpack.

 

Animation events that will be fired by that file will be in the annotations node, together with the time and sequence in which they will be fired.

 

 

http://i.imgur.com/vHj99k8.png

Link to comment
Share on other sites

Same here, registrator2000! :cool: Out of curiosity what tool did you use to extract the .hkx files with?

 

Also worth noting is that an ultimate end here is to create a weapon "jam" effect with a failure chance tied to the grade of the receiver on a weapon, if you have any suggestions for how to accomplish such a feat of modding, by all means feel free to cut in.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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