Jump to content
AgentRev

Execute code when unit reloads weapon

Recommended Posts

31 minutes ago, Larrow said:

Use magazinesAmmoFull instead, and just look for the mag that is in the units current muzzle that is being used to fire?

Very slick my Meat Hula Hoop consuming friend.  Thanks alot! 

 

Thanks much to @ZaellixA and @Dedmen also.  I think I'm opting for Larrow's solution as it may be more reliable than relying on string elements present for every magazine.

  • Like 2
  • Haha 1

Share this post


Link to post
Share on other sites

Well, apparently there is a really easy way to do it. Thanks to @LarrowI found out that you can actually use weaponState to get the current ammo count. The last element of the returned variables is the ammoCount. So in the same way Larrow showed above you can

_myUnit addEventHandler["FiredMan", {
	_unit = _this select 0; // Get the unit who fired
	_numOfBullets = (weaponState _unit) select 4; // Get the amount of bullets left in the magazine
	if(_numOfBullets isEqualTo 0) then {
		systemChat "Reloading..."; // Start screaming
	} else {
		systemChat "Still plenty to shoot..."; // Keep shooting
	};
}];

Thanks Larrow for pointing to the right direction.

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites
18 minutes ago, ZaellixA said:

Well, apparently there is a really easy way to do it. Thanks to @LarrowI found out that you can actually use weaponState to get the current ammo count. The last element of the returned variables is the ammoCount. So in the same way Larrow showed above you can

Even cleaner.  Now I'm opting for this one lol.  Great job by all.

  • Haha 1

Share this post


Link to post
Share on other sites
On 6/12/2019 at 6:24 PM, Larrow said:

addEventHandler [ "FiredMan", {

55502365-e1492992786938.jpg

  • Haha 1

Share this post


Link to post
Share on other sites

In case anyone ever needs this again, there is a cleaner way now to check if a unit is currently reloading via the gestureState command:

 

gestureState

_unit = player;  
if (gestureState _unit find "reload" >= 0) then {hint "unit is reloading"};

 

  • Like 4

Share this post


Link to post
Share on other sites

But, when and how are you gonna check?

 

Is a reload guaranteed when the magazine goes empty, 'cause in this case this could very well be used in the FiredMan event handler shown above. Otherwise I can't really see an easy way to use it apart from constantly checking if the unit is reloading.

 

Do you have something specific in mind??? 

  • Like 1

Share this post


Link to post
Share on other sites
3 hours ago, ZaellixA said:

But, when and how are you gonna check?

 

Is a reload guaranteed when the magazine goes empty, 'cause in this case this could very well be used in the FiredMan event handler shown above. Otherwise I can't really see an easy way to use it apart from constantly checking if the unit is reloading.

 

Do you have something specific in mind??? 

Good point.  The firedMan example above is still very valid.  

 

My current use case is different.  I'm scripting player giving hand signals to AI and if player starts a reload, then immediately does the hand signal gesture, then the reload gesture animation is stopped, and player's weapon is not reloaded.  This is annoying and dangerous in combat.  So just before giving hand signal, I check for player currentGesture contains "reload", and skip the hand signal if he is reloading.

  • Like 1

Share this post


Link to post
Share on other sites
On 7/27/2022 at 5:51 PM, johnnyboy said:

In case anyone ever needs this again, there is a cleaner way now to check if a unit is currently reloading via the gestureState command:

 

gestureState


_unit = player;  
if (gestureState _unit find "reload" >= 0) then {hint "unit is reloading"};

 

Have you seen https://community.bistudio.com/wiki/weaponState ?

  • Like 3

Share this post


Link to post
Share on other sites
13 minutes ago, killzone_kid said:


Ahh, that's what he was using previously, but that was three years ago, before the command was updated. 
 

Quote

2.06  roundReloadPhase: Number - current ammo round reload phase (see weaponReloadingTime)

2.06  magazineReloadPhase: Number - current magazine reload phase from 1 to 0, 0 - reload complete. > 0 - reload in progress

 

Nifty!

  • Like 2

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×