Jump to content
Sign in to follow this  
madbilly

Script help: play sound and kill sound

Recommended Posts

Hi everyone,

I am trying to run a trigger to simulate incoming artillery sounds and explosions. As a test I have something like:

incomingShell = createSoundSource ["Sound_Alarm", getMarkerPos "_btarget0_g0", [], 0]; 
nul=createVehicle ["LIB_OF471_HE", getMarkerPos "_btarget0_g0",[], 400, "FLY"];

This plays "Sound_Alarm" noise and then almost immediately the indicated explosion sound "LIB_OF471_HE". I have two problems with this:

1) I would like to know a list of native cfgVehicles sounds that I can use in substitution for "Sound_Alarm". If no good shell sound exists then I will have to define a custom sound.

2) This is harder. Using the createSoundSource[] call, the sound continues playing. I need to close it down. I tried the following, with no success:

incomingShell = createSoundSource ["Sound_Alarm", getMarkerPos "_btarget0_g0", [], 0]; 
sleep 2;
deleteVehicle incomingShell;
nul=createVehicle ["LIB_OF471_HE", getMarkerPos "_btarget0_g0",[], 400, "FLY"];

The idea above is that the "Sound_Alarm" sound plays for two seconds, then is terminated, then the explosion occurs. However the code above fails with the deleteVehicle call, and this failure prevents the "Sound_Alarm" (or whatever sound is used) from being played at all. I have seen mention of this bug before, but I was wondering if people have elegant and simple scripting means to order, play and cut short sounds at a specific location in MP missions.

Cheers,

Mad Billy

Edited by MadBilly

Share this post


Link to post
Share on other sites

OK, I will try to update the code as I solve it. I learnt about the scheduled/non-scheduled issue with sleep. Now I am using a spawn to successfully put together two sounds in the trigger onAct script:

_nul = [] spawn {
_alarm = createSoundSource ["Sound_Alarm", getMarkerPos "_btarget0_g0", [], 0]; 
sleep 1; 
deleteVehicle _alarm; 
sleep 2; 
nul=createVehicle ["LIB_OF471_HE", getMarkerPos "_btarget0_g0",[], 100, "FLY"];
};

This works beautifully, so it seems I have answered my second question above. :bounce3:

So now I am working on the first question - how to find the correct names of the inbuilt sound effects. The sound I really want to play with createSoundSource is listed under the trigger Effects menu as "PMC - Incoming 1". If selected, this expands to "PMC_Incoming1" inside the .sqm file. So, naively, I tried swapping "PMC_Incoming1" in for "Sound_Alarm" in the createSoundSource. This gives me the following error:

No entry bin\config.bin/cfgVehicles.PMC_Incoming1

So what I am trying to do now is learn how to play builtin sounds using createSoundSource for a MP environment. If anyone has any ideas/tips then please let me know.

Cheers,

Mad Billy

Share this post


Link to post
Share on other sites

Continuing my journey of discovery about scripting triggers to play sounds in a programmed sequence ...

I have now finally understood that createSoundObject is not the best function to use, as it can only recognize a small subset of inbuilt sounds, and I don't want to release custom sounds with every mission I make. The obvious replacement is say3D which has automatic access to all inbuilt sounds I need. The only thing is that say3D is applied to a unit/vehicle/logic object so it cannot be run on a marker. So I have to create an invisible logic object on the map at the location of my barrage target and then get the logic object to say3d the incoming shell noise.

The trigger onAct code then looks simply like (for a single incoming shell):

_nul = [] spawn {
mylogic say3D ""PMC_Incoming1""; 
sleep 2; 
nul=createVehicle [""ARTY_Sh_81_HE"", getPos mylogic,[], 100, ""FLY""]; 
};

"mylogic" is the invisible logic object at the barrage location - I don't need the marker object any more.

This is the essence of the solution. In my mission generation script I have elaborated it quite a bit to have a barrage of different ammo types continuing for a configurable total number of shells, fired in short configurable salvoes with a configurable salvo reload period and configurable shot dispersion etc. I have also made it MP-safe by including isServer in the trigger validity condition, so the trigger actions are not replicated on each client.

It has taken some time for me to get to this result. I am new to A2 scripting and there is plenty of good advice in old threads on the forums, but you need a certain level of knowledge to understand it. Hopefully others can read this thread and take a couple of shortcuts!

Cheers,

Mad Billy

Share this post


Link to post
Share on other sites

I have a totally different solution.

In a trigger menu, in the bottom left corner select Effects.

This gives a list of many sounds. Artillery falling, explosions, gunshots, dogs barking, ducks quacking etc etc

Select a sound and when the trigger fires the sound plays.

AH! I hear you say. You don't want the sound of artillery falling on me! You want the sound to be in the distance.

Solution: Place the trigger say 400 meters from your position. Have the trigger fired by an independent or by some other means.

Then you get the sound of artillery falling some distance away!

.

.

Share this post


Link to post
Share on other sites

Hi Joe,

The problem is that the trigger sound effects play AFTER the trigger fires. So in my case you would hear an explosion and then you would hear the shell falling. :) I wanted the sounds to play in the reverse order so I had to forget the Effects route and script the sound in order directly.

Cheers,

Mad Billy

Share this post


Link to post
Share on other sites

Hi Joe,

My learning continues! You were correct. Once I have the scheduled timing with sleep sorted out I can indeed use the Effects sounds directly. But I'll stick with the explicit script approach.

I found an issue with say3D - it only works for the client so is not good for MP missions. So I have had to go to an MP safe version.

Replace

mylogic say3D ""PMC_Incoming1"";

with

[mylogic, "PMC_Incoming1",300] call CBA_fnc_globalSay3d;

Cheers,

Mad Billy

Edited by MadBilly

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
Sign in to follow this  

×