Jump to content
Sign in to follow this  
tron34

How to stop playing music when someone dies

Recommended Posts

I'm trying to make mission for myself(I don't plan on putting it in the Steam workshop, because it's going to be a mission made by an amateur) and I've been trying to figure this out.

I figured out how to get music to play when an OPFOR soldier is alerted to my presence, but I can't figure out how to get the music to stop playing when the alerted AI(s) is dead. Anyone know how to do this?

Share this post


Link to post
Share on other sites

I did this a while back with a siren and a vehicle. It's a bit of a complicated script but I'll try and break it down.

[_car] spawn {
   scopeName "logicScope";
   private ["_glogic","_car"];
   _car = _this select 0;
   _glogic = "Land_HelipadEmpty_F" createVehicle (getposATL _car);
   _glogic attachTo [_car,[0,0,2]];

       while {siren} do {
       // Scope name for use in for loop
       scopeName "sirenloop";

       // Play siren sound.
       _glogic say "elsiren";
           // Checks condition of !siren for 5 secs, breaks out to sirenLoop if siren is false.
           for "_s" from 0 to 5 do {
           if !(siren) then {breakTo "sirenloop"};
           sleep 1;
           };
       // Break out to logic scope.
       if !(siren) then {breakTo "logicScope"};
       };
   deleteVehicle _glogic;
};

As you can see it covers creation aswell. The basic concept is that it creates a helipad, attaches it to the car and makes that helipad "say" a sound pre-defined in the description.ext (Link). It then has a for loop for 5 seconds, which is basically the duration of the actual sound you're going to play, and in that for loop it checks for a global variable. If it's false, it exits to the while loop (scope name sirenloop), and consecutively it exits that aswell and deletes the siren.

Basic application to your situation would break down to this:

1. Replace [_car] next to spawn with [unitName].

2. Replace every condition using global siren variable with !alive _car.

You can replace _car with _unit if you want to, but it'd require you to replace all the other _car variables with _unit aswell (for instance (getposATL _car) becomes (getosATL _unit) etc). If you're lazy, don't do it.

Oh and there's probably an easier method which I never get.

Share this post


Link to post
Share on other sites

Yeah, if you've got it set up in a way that the actual AI unit is playing the sound (AIUnitName say "sound"), then you can delete the unit with that. Some example code:

AIUnitName addEventHandler ["Killed",{deleteVehicle (_this select 0)}];

I'm assuming that you're making a singleplayer mission.

Share this post


Link to post
Share on other sites
Yeah, if you've got it set up in a way that the actual AI unit is playing the sound (AIUnitName say "sound"), then you can delete the unit with that. Some example code:

AIUnitName addEventHandler ["Killed",{deleteVehicle (_this select 0)}];

I'm assuming that you're making a singleplayer mission.

Yeah, just a little single player mission for myself since a certain idea crossed my mind.

You might be right that I shouldn't try it since that's a lot scripting to get it to do one thing. I'll try and come up with some sort of idea.

Edited by tron34

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  

×