Jump to content

Is there a way to detect when the player has started reloading?


NoCashNoExp

Recommended Posts

Just to give some context on what I am doing. I am trying to modify the scrounger perk so it works on reload instead of when firing the last bullet using scripting. Instead of refunding a full mag, it should refund maximum magazine capacity - current ammo left in magazine. There's no way to get the ammo count left in the player's magazine in papyrus so I tried to simulate the weapon magazine in my script.

 

My first solution was listen to "weaponFire" animation but this quickly didn't work because the animation is fired multiple times for each shot from an automatic weapon. My second solution was to listen to "onItemAdded" and "onItemRemoved" events on the player with the premise that if one bullet was removed than it might be a bullet that was fired from their gun. There were so many edge cases and I had to listen to menus opening and closing to make sure whether the player dropped/sold/moved one bullet or actually fired it and in the end it didn't work quite well.

 

Finally, I decided to take the value from the source literally. I made an F4SE plugin that reads the int value from the memory address where the actual magazine count is stored after quite an extensive research on reverse engineering completely forgetting that in my papyrus code I was listening to "reloadComplete" animation event and there's no reload start event. The problem with that is the value is updated before I can read the old value so it always refunds 0 ammo.

 

I could just slap the update ammo count code on "weaponFire" event and call it a day but as I said it's fired multiple times so it's a bit inefficient but it should still be correct. I am not experienced enough with the game internals and F4SE to know if there's any performance penalties for continuously calling a function from a dll so I was honestly hoping for a better solution.

 

Edit: Calling the update ammo code from "weaponFire" event works on semi auto weapons but not automatic ones (the return value from the C++ function is incorrect), I am assuming calling a function from F4SE multiple times within the span of milliseconds isn't a great of idea which is what I thought.

Edited by NoCashNoExp
Link to comment
Share on other sites

I thought only weaponfire goes off multiple times? In any case, you should take a look at BCR and see how they pulled it off.

Thank you, I actually did take a look at that mod, they have an article explaining how to use their system for external mods. They edit the animations files and add more events to the animations but my mod is honestly very simple, I would prefer to leave editing animations for other mods.

Link to comment
Share on other sites

You could reframe it a bit I suppose. ie it only works for manual reloads? Because the only way I can think of is putting a script on a player alias to register for the reload key and then get the int of the ammo count at that point. I don't make F4SE plugins though, so I assume there's a slightly more elegant way to register for key presses.

Link to comment
Share on other sites

You could reframe it a bit I suppose. ie it only works for manual reloads? Because the only way I can think of is putting a script on a player alias to register for the reload key and then get the int of the ammo count at that point. I don't make F4SE plugins though, so I assume there's a slightly more elegant way to register for key presses.

Thank you so much dude that is actually 100% going to work, I am going to test it right now. F4SE already exports a registerforkey to papyrus so I don't have to write my own.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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