Jump to content

How to run a script when a weapon is fired?


Recommended Posts

I want to add a script to certain receivers for a certain weapon that runs when the weapon is fired. For simplicity sake, I want to run a debug message every third shot. I've drilled down to the receiver properties for the weapon, but where would I go to attach the script?

Link to comment
Share on other sites

The only reliable way I've found to determine if a weapon is fired would be to check the player's inventory for the amount of ammo they have for the gun. Animations tend to be tricky to get working, or so I've seen based on the multiple topics related to checking if a weapon is fired.

Edited by Reneer
Link to comment
Share on other sites

The only reliable way I've found to determine if a weapon is fired would be to check the player's inventory for the amount of ammo they have for the gun. Animations tend to be tricky to get working, or so I've seen based on the multiple topics related to checking if a weapon is fired.

That might be tricky, because the mod would be modifying remaining ammo. That also seems like it's running a constant "while" script, which isn't that reliable if a gun is rapid-fire.

I'll keep digging.

Link to comment
Share on other sites

That might be tricky, because the mod would be modifying remaining ammo. That also seems like it's running a constant "while" script, which isn't that reliable if a gun is rapid-fire.

I'll keep digging.

The script could easily be written to compensate for rapid-fire. Just saying. And the only other working method is to use weapon animations.
Link to comment
Share on other sites

 

That might be tricky, because the mod would be modifying remaining ammo. That also seems like it's running a constant "while" script, which isn't that reliable if a gun is rapid-fire.

I'll keep digging.

The script could easily be written to compensate for rapid-fire. Just saying. And the only other working method is to use weapon animations.

 

Well, what triggers the weapon firing sound? Perhaps I could piggyback on that.

Link to comment
Share on other sites

Well, what triggers the weapon firing sound? Perhaps I could piggyback on that.

Good thought, but there is no way to check to see if a particular sound is playing or not.

 

Edit: Sorry, I knew I had been in this discussion before, but it's late and I couldn't remember the easy solution, which is here.

Edited by Reneer
Link to comment
Share on other sites

I suppose you could try attaching the script to the weapon itself, check for the desired receiver mods, and use a recycling counter to increment every time the weapon is fired. I haven't done enough scripting to know if papyrus supports modulus arithmetic. If it does, then you can use counter mod 3. Whenever it equals 0, you'd trigger your debug. The problem with this being the eventuality that you overflow the variable (unlikely, depending on the refire rate of the weapon). The safe way to do it is to reset your counter variable after triggering your debug.
Link to comment
Share on other sites

  • Recently Browsing   0 members

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