Jump to content
Robustcolor

Execute sounds when reloading.

Recommended Posts

Hi, is there a simple way of executing code when a player is reloading? I'm trying to add different sounds similiar to the inbuilt arma reloading function sounds but can't get it to work. How does the arma function execute it?

 

needReload > 0.99 executes all the time. needReload == 0 never executes.

initPlayerLocal.sqf

[] spawn {
	while {true} do {
		if (needReload player == 0 && someAmmo player) then {
			[player,[selectRandom ["P11","P12","P13","P14","P14","P15"],150,1]] remoteExec ["say3D"];
			sleep (random 5) + 5;
		};
		sleep 3;
	};
};

 

Share this post


Link to post
Share on other sites

This kind of work, but makes it possible spamming the reload button so it's executing the code until the reloading phase is done.

(findDisplay 46) displayAddEventHandler ["KeyDown", {
	params ["", "_key"];
    if (_key in actionKeys "ReloadMagazine" && player ammo currentMuzzle player == 0 && {_x in getArray (configFile >> "CFGWeapons" >> (currentWeapon player) >> "magazines")} count (magazines player) > 0) then {
	[player,[selectRandom ["P11","P12","P13","P14","P14","P15"],150,1]] remoteExec ["say3D"];
    };
}];

 

Share this post


Link to post
Share on other sites
2 hours ago, Robustcolor said:

This kind of work, but makes it possible spamming the reload button so it's executing the code until the reloading phase is done.

You can setVariable a time  value on the player to insure it only executes the sound once per reload.  Intialize the value to current time just before you add the eventhandler.  Then inside the event handler add an IF statement that doesn't play the sound unless current time - saved variable time > 3 seconds.  Inside the IF statement where you play the sound, reset time variable to current time.

 

That should guarantee you only play sound once per reload.  Good luck and have fun brother!

  • Like 1

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

×