Jump to content
Robustcolor

Add ADS sound with a displayaddEH

Recommended Posts

Is it possible to add a ADS sound from initPlayerLocal? I've been trying to solve it with the code below but it wont play any sound.

initPlayerLocal.sqf

(findDisplay 46) displayAddEventHandler ["MouseButtonClick", {
params ["_control", "_button"];
if (_button == 1) then {
if (cameraView == "GUNNER") then {
playSound [ironsightsout, true];
}else{
playSound [ironsightsin, true];
};
};
}];

 

Share this post


Link to post
Share on other sites
9 minutes ago, gc8 said:

are you passing string as the soundName to playSound?

 

https://community.bistudio.com/wiki/playSound

Description.EXT

class CfgSounds
{
	class ironsightsin
	{
		name = "ironsightsin";
		sound[] = {"\ironsights_in.ogg", 1, 1};
		titles[]={0,""};
	};
	class ironsightsout
	{
		name = "ironsightsout";
		sound[] = {"\ironsights_out.ogg", 1, 1};
		titles[]={0,""};
	};
};

 

Share this post


Link to post
Share on other sites

yeah you should definitely add quotation marks:

 

playSound ["ironsightsout", true];

 

  • Like 1

Share this post


Link to post
Share on other sites
12 minutes ago, gc8 said:

yeah you should definitely add quotation marks:

 


playSound ["ironsightsout", true];

 

Thanks, yes i missed adding quotation marks. But my code still don't work.

Share this post


Link to post
Share on other sites

Make sure display 46 is available before adding the event. InitPlayerLocal.sqf runs before it is available.

//initPlayerLocal.sqf

h = [] spawn {
	disableSerialization;

	_display = findDisplay 46; //Immediately get display 46

	waitUntil{ !isNull ( findDisplay 46 ) }; //Wait until display is available

	hint format[ "D: %1", _display ]; //Show initial = No Display

	_display = findDisplay 46; //Get display gain
  
	sleep 1; //Quick pause just to make sure we see systemchat
  
	systemChat format[ "D: %1", _display ]; //Show after = Display 46
};

 

  • Like 1

Share this post


Link to post
Share on other sites

Any suggestion how i can disable the playSound if a player only zooms and not aiming down sights? I'm using !(weaponlowered) and !(Visiblemap) so it don't execute the code in those conditions.

 

If a player has the weapon raised and zooms it executes the playSound, how can i prevent it from executing when doing this? If the weapon is lowered and the player zooms it don't execute as wanted.

waituntil {!isnull (finddisplay 46)};
(findDisplay 46) displayAddEventHandler ["MouseButtonDown", {
params ["_control", "_button"];

if ((_button == 1) && ((!(weaponLowered player) && !(visibleMap))
then {
if (cameraView isEqualTo "GUNNER") then {
playSound ["ironsightsout", true];
};
if (cameraView isEqualTo "INTERNAL" || {cameraView isEqualTo "EXTERNAL"}) then {
playSound ["ironsightsin", true];
};};
}];

 

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

×