Jump to content
finicu

Custom Action that triggers custom say3D sound

Recommended Posts

Hi. I want to add a custom action to a player that, when triggered, will play a custom sound "sound1.ogg" inside my mission file\music\ folder.

 

My description.ext works properly, here it is:

class CfgSounds
{
sounds[] = {01,02};
class 01
{
	name = "01";
	sound[] = {"music\sound1.ogg", db+10, 1.0};
	titles[] = {0,""};
};
class 02
{
	name = "02";
	sound[] = {"music\sound2.ogg", db+10, 1.0};
	titles[] = {0,""};
};


};

Note that sound2.ogg is not used yet.

 

 

In the init field of the player that can play the sound, I have tried to make the custom action:

this addAction ["Play Sound", this say3D "01"]

but here's the problem:

when I run the scenario, the sound is played at the beginning, right after the players spawn in, and there is no custom action on the player.

 

If I forgot to add anything, please ask, this is my first post so I might have missed something...

Share this post


Link to post
Share on other sites

Pay attention to the addAction wiki page.

"this" does not exist within the code called from the addAction, only "_this", which is an array containing the object the action is attached to, the caller who activated the action and the ID of the action.

It also requires either string "" or code {}, you used neither.

 

Use it like this:

this addAction ["Play Sound", {

params ["_object","_caller","_ID"];
_object say3D "01";

}];

 

On a sidenote get used to have your own naming convention for stuff, naming your sounds "01","02" is just a recipe for disaster, name them like "FIN_sound_test1" or similar to get a unique identifier that also works when using other mods/scripts.

This also improves readability when coming back to older projects or when debugging your code.

 

Cheers

  • Like 2

Share this post


Link to post
Share on other sites

Hi! Thanks, the script works! Also, yes, I am aware that naming sounds that way will mean bad things.

 

I have run into a small problem - When the player dies, the player loses the action. Not just that, but if one of the player has the option and is looking at someone else with the action, that player will get 2 of those actions.

 

Is there another way to respawn players so that they don't lose the action when they die? (or respawn)

Share this post


Link to post
Share on other sites

You can solve this by executing your action in the respective event scripts.

Simply create an initPlayerLocal.sqf and an onPlayerRespawn.sqf file in the mission root and paste the action in them.

 

For your action visibility you'd need to adjust the condition:

 

this addAction ["Play Sound", {

params ["_object","_caller","_ID"];
_object say3D "01";

},[],0,true,true,"","_target isEqualTo _this"];

The last string contains the condition when the action will be visible.

The condition returns true if the caller is the same unit as the object the action is attached to, so other players will never see actions attached to other players.

You can add other checks in there, so the action only becomes visible outside of vehicles and when the players weapon is lowered etc.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

Thank you! It works perfectly! Thanks a lot for the help ;)

 

EDIT: And thanks a lot for linking the event scripts, they will help a lot in the future!

Edited by finicu

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

×