jeanmoul 10 Posted September 19, 2014 (edited) Hi, I'd like to have a sound played when the player enters an area, and another sound when he's outside of it. It's an ambiant sound so I want it to loop with a short overlap between two loops for a smooth transition. So I have to use CfgSound which allows that, unlike CfgMusic. As I've read here and there, the only way to make a sound stop on demand is to make it said by an object, and then delete the object when you want it to stop. So I've done this : myinsidesound.sqf: [color="#FF8040"] insidesoundsource [color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"Empty_HeliH"[/color] [color="#191970"][b]createVehicle[/b][/color] [color="#191970"][b]position[/b][/color] [color="#000000"]player[/color][color="#8B3E2F"][b];[/b][/color] insidesoundsource [color="#191970"][b]attachTo[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#000000"]player[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b][[/b][/color][color="#FF0000"]0[/color][color="#8B3E2F"][b],[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b],[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color] [color="#191970"][b]while[/b][/color] [color="#8B3E2F"][b]{[/b][/color][color="#000000"]true[/color][color="#8B3E2F"][b]}[/b][/color] [color="#191970"][b]do[/b][/color] [color="#8B3E2F"][b]{[/b][/color] insidesoundsource [color="#191970"][b]say[/b][/color] [color="#7A7A7A"]"myinsidesound"[/color][color="#8B3E2F"][b];[/b][/color] [color="#191970"][b]sleep[/b][/color] [color="#FF0000"]20[/color][color="#8B3E2F"][b];[/b][/color] [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color][/color] I have a "myoutsidesound.sqf" that has exactly the same structure. And then the following code : [color="#FF8040"][color="#191970"][b]while[/b][/color] [color="#8B3E2F"][b]{[/b][/color][color="#000000"]true[/color][color="#8B3E2F"][b]}[/b][/color] [color="#191970"][b]do[/b][/color] [color="#8B3E2F"][b]{[/b][/color] [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#8B3E2F"][b][[/b][/color][color="#000000"]player[/color][color="#8B3E2F"][b],[/b][/color] [color="#7A7A7A"]"myinsidearea"[/color][color="#8B3E2F"][b]][/b][/color] [color="#191970"][b]call[/b][/color] CBA_fnc_inArea[color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]then[/b][/color] [color="#8B3E2F"][b]{[/b][/color] [color="#1874CD"]_inareasound[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#8B3E2F"][b]][/b][/color] [color="#191970"][b]execVM[/b][/color] [color="#7A7A7A"]"myinsidesound.sqf"[/color][color="#8B3E2F"][b];[/b][/color] [color="#191970"][b]sleep[/b][/color] [color="#FF0000"]0.1[/color][color="#8B3E2F"][b];[/b][/color] [color="#191970"][b]terminate[/b][/color] [color="#1874CD"]_outofareasound[/color][color="#8B3E2F"][b];[/b][/color] [color="#006400"][i]// (optionnal, I've removed this and it doesn't change anything) [/i][/color] [color="#191970"][b]deleteVehicle[/b][/color] outsidesoundsource[color="#8B3E2F"][b];[/b][/color] [color="#006400"][i]// (outidesoundsource is defined in myoutsidesound.sqf) [/i][/color] [color="#191970"][b]while[/b][/color] [color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b][[/b][/color][color="#000000"]player[/color][color="#8B3E2F"][b],[/b][/color] [color="#7A7A7A"]"myinsidearea"[/color][color="#8B3E2F"][b]][/b][/color] [color="#191970"][b]call[/b][/color] CBA_fnc_inArea[color="#8B3E2F"][b]}[/b][/color] [color="#191970"][b]do[/b][/color] [color="#8B3E2F"][b]{[/b][/color][color="#191970"][b]sleep[/b][/color] [color="#FF0000"]0.05[/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color] [color="#8B3E2F"][b]}[/b][/color] [color="#191970"][b]else[/b][/color] [color="#8B3E2F"][b]{[/b][/color] [color="#1874CD"]_outofareasound[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#8B3E2F"][b]][/b][/color] [color="#191970"][b]execVM[/b][/color] [color="#7A7A7A"]"myoutsidesound.sqf"[/color][color="#8B3E2F"][b];[/b][/color] [color="#191970"][b]sleep[/b][/color] [color="#FF0000"]0.1[/color][color="#8B3E2F"][b];[/b][/color] [color="#191970"][b]terminate[/b][/color] [color="#1874CD"]_inareasound[/color][color="#8B3E2F"][b];[/b][/color] [color="#191970"][b]deleteVehicle[/b][/color] insidesoundsource[color="#8B3E2F"][b];[/b][/color] [color="#191970"][b]waitUntil[/b][/color] [color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b][[/b][/color][color="#000000"]player[/color][color="#8B3E2F"][b],[/b][/color] [color="#7A7A7A"]"myinsidearea"[/color][color="#8B3E2F"][b]][/b][/color] [color="#191970"][b]call[/b][/color] CBA_fnc_inArea[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color] [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color] [color="#191970"][b]sleep[/b][/color] [color="#FF0000"]0.05[/color][color="#8B3E2F"][b];[/b][/color] [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color] [/color] It works fine exept for one big issue : When I walk inside the area, and then exit and comme back let's say 8 seconds after my first entry, the insidesound will be played as planned but after 12 seconds a second iteration of this sound will overlap the first one. It's actually the repeat of the 20 second loop initiated during my first appearance within the area. As it appears my object that I have deleted and created again when I came back inside the area have kept memory of the first loop and initialize it on top of the one that is currently running. And if I exit the zone and come back in it again, there will now be three successives loops that will be triggered, and so on... I was wondering how to avoid that, maybe by creating a different object with different value each time, but I have no clue how to do that. If someone has an idea on how to resolve this problem I would be so pleased. Edited September 20, 2014 by jeanmoul Share this post Link to post Share on other sites