Guest User

Untitled

a guest
Feb 18th, 2017
83
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. TPW soap - Middle Eastern Ambience Pack
  3. Author: tpw, autigergrad
  4. Date: 20170216
  5. Version: 1.10
  6. Requires: CBA A3, tpw_core.sqf
  7. Compatibility: SP, MP client
  8.  
  9. Disclaimer: Feel free to use and modify this code, on the proviso that you post back changes and improvements so that everyone can benefit from them, and acknowledge the original author (tpw) in any derivative works.
  10.  
  11. To use:
  12. 1 - Save this script into your mission directory as eg tpw_soap.sqf
  13. 2 - Call it with 0 = [1,1,1,1,1,0,0,0] execvm "tpw_soap.sqf";
  14.  
  15. 1 = ambient sounds volume (0-2)
  16. 1 = music volume (0-2)
  17. 1 = Azan volume (0-2)
  18. 1 = house FX volume (0-2)
  19. 1 = scream volume (0-2)
  20. 0 = number of user music files in @TPW_MODS\music (0-20)
  21. 0 = number of user sound files in @TPW_MODS\sounds (0-20)
  22. 0 = region (0 = autoselect Greek/Fijian sounds on Greek/Fijian maps (1 = force Greek, 2 = force Mid East, 3 = force Fijian))
  23.  
  24. THIS SCRIPT WON'T RUN ON DEDICATED SERVERS.
  25. */
  26.  
  27. if (isDedicated) exitWith {};
  28. WaitUntil {!isNull FindDisplay 46};
  29. if (count _this < 8) exitwith {hint "TPW soap incorrect/no config, exiting."};
  30.  
  31. // READ IN CONFIGURATION VALUES
  32. tpw_soap_version = "1.10"; // Version string
  33. tpw_soap_ambientvolume = _this select 0; // Ambient sounds volume
  34. tpw_soap_musicvolume = _this select 1; // Music volume
  35. tpw_soap_azanvolume = _this select 2; // Azan volume
  36. tpw_soap_housefxvolume = _this select 3; // House fx volume
  37. tpw_soap_screamvolume = _this select 4; // Screams volume
  38.  
  39. tpw_soap_usermusic = _this select 5; // Number of user supplied songs
  40. tpw_soap_usersounds = _this select 6; // Number of user supplied sounds
  41. tpw_soap_region = _this select 7; // 0 = autodetect 1 = Greece, 2 = Mideast
  42.  
  43. // OTHER VARS
  44. tpw_soap_active = true; // Global enable/disabled
  45. tpw_soap_radius = 50; // Distance around player to spawn ambience into houses
  46. tpw_soap_attenuation = 100; // Distance over whic sound fades out
  47. tpw_soap_greeksoundlength = [60,48,87,73,61,88,87,65,72,56,72,49,69,64,85,62,76]; // Length (sec) of each ambience clip in the order of the config
  48. tpw_soap_greeksonglength = [69,187,165,149,153,181,240,194,175]; // Length (sec) of each song in the order of the config
  49. tpw_soap_mideastsoundlength = [41,25,80,47,48,65,61,57,61,61,37,81,38,38,45,108,40,52,134,82,32,28,40,81,9,15,81,64,63,59,97,101,90,66,21,52]; // Length (sec) of each ambience clip in the order of the config
  50. tpw_soap_mideastsonglength = [19,180,180,180,180,180,180,276,329,133,120]; // Length (sec) of each song in the order of the config
  51. tpw_soap_fijisoundlength = [60,70,50,50,20,30,25,20,15,25,15,10,35,45,45,55,30,45,50,45,60,35,25,20,25]; // Length (sec) of each ambience clip in the order of the config
  52. tpw_soap_fijisonglength = [220,180,40,120,120,130,150,110,80,180,180]; // Length (sec) of each song in the order of the config
  53. tpw_soap_azanlength = [223,149,128,184,173,159,120,133,120,112];// Length (sec) of each Azan in the config
  54. tpw_soap_songsplaying = 0; // How many songs
  55. tpw_soap_maxsongs = 4; // Maximum simultaneous songs allowed
  56. tpw_soap_soundsplaying = 0; // How many songs
  57. tpw_soap_maxsounds = 12; // Maximum simultaneous sounds allowed
  58. tpw_soap_dead = 0; // initial number of deaths
  59. tpw_soap_nearhouses = []; // initial number of nearby buildings
  60. tpw_soap_volume = 1; // MAster volume
  61.  
  62. // SUNRISE AND SUNSET
  63. _riseset = [] call BIS_fnc_sunriseSunsetTime;
  64. tpw_soap_sunrise = _riseset select 0;
  65. tpw_soap_sunset = _riseset select 1;
  66.  
  67. // AUTO DETECT REGION
  68. if (tpw_soap_region == 0) then
  69. {
  70. tpw_soap_region = 2;
  71. if (tolower worldname in ["altis","stratis"]) then
  72. {
  73. tpw_soap_region = 1;
  74. };
  75. if (tolower worldname in ["tanoa"]) then
  76. {
  77. tpw_soap_region = 3;
  78. };
  79. };
  80.  
  81. // IS PLAYER IN A HOUSE?
  82. tpw_soap_fnc_indoors =
  83. {
  84. private ["_pos","_highpos","_return"];
  85. _pos = eyepos player;
  86. _highpos = [_pos select 0,_pos select 1,(_pos select 2) + 10];
  87. if (lineintersects [_pos,_highpos]) then
  88. {
  89. _return = true;
  90. }
  91. else
  92. {
  93. _return = false;
  94. };
  95. _return
  96. };
  97.  
  98. // NEAREST BUILDING
  99. tpw_soap_fnc_nearestbuilding =
  100. {
  101. private ["_return"];
  102.  
  103. // Workaround for bizarre building behaviour on Kidal
  104. if (tolower worldname in ["kidal","tanoa"]) then
  105. {
  106. _return = (nearestObject [player, "House"]) distance player; // will also return walls
  107. } else
  108. {
  109. _return = (nearestbuilding player) distance player;
  110. };
  111. _return
  112. };
  113.  
  114. // MAIN LOOP
  115. tpw_soap_fnc_mainloop =
  116. {
  117.  
  118. while {true} do
  119. {
  120. // Scan houses only if fewer than maximum sounds are playing
  121. if ((tpw_soap_active) &&
  122. {tpw_soap_soundsplaying < tpw_soap_maxsounds} &&
  123. {player == vehicle player} &&
  124. {!([] call tpw_soap_fnc_indoors)}) then
  125. {
  126. tpw_soap_nearhouses = [];
  127. if ([] call tpw_soap_fnc_nearestbuilding < tpw_soap_radius) then
  128. {
  129. 0 = [] call tpw_soap_fnc_housescan;
  130. };
  131. };
  132. sleep 5.11;
  133. };
  134. };
  135.  
  136. // AZAN LOOP
  137. tpw_soap_fnc_azanloop =
  138. {
  139. tpw_soap_azanflag = 0;
  140. while {true} do
  141. {
  142. if ((tpw_soap_active) &&
  143. {tpw_soap_azanflag == 0} &&
  144. {(daytime > tpw_soap_sunrise - 1.25 && daytime < tpw_soap_sunrise - 1 ) ||
  145. (daytime > tpw_soap_sunrise && daytime < tpw_soap_sunrise + 0.25) ||
  146. (daytime > 11.75 && daytime < 12) ||
  147. (daytime > 14 && daytime < 14.25) ||
  148. (daytime > tpw_soap_sunset - 2 && daytime < tpw_soap_sunset - 1.75) ||
  149. (daytime > tpw_soap_sunset && daytime < tpw_soap_sunset + 0.25)}) then
  150. {
  151. 0 = [] call tpw_soap_fnc_mosquescan;
  152. };
  153. sleep 61.3;
  154. };
  155. };
  156.  
  157. // HOUSE SCANNING
  158. tpw_soap_fnc_housescan =
  159. {
  160. private ["_nearhouses","_house","_i"];
  161. // Region - can be changed on the fly
  162. if (tpw_soap_region == 1) then
  163. {
  164. tpw_soap_sounds = 17;
  165. tpw_soap_songs = 9;
  166. tpw_soap_path = "TPW_AMBIENCE\sounds\greek\";
  167. tpw_soap_soundlength = tpw_soap_greeksoundlength;
  168. tpw_soap_songlength = tpw_soap_greeksonglength;
  169. tpw_soap_musicfactor = 1.2; // Slightly louder Greek music
  170. };
  171.  
  172. if (tpw_soap_region == 2) then
  173. {
  174. tpw_soap_sounds = 36;
  175. tpw_soap_songs = 11;
  176. tpw_soap_path = "sounds\mideast\";
  177. tpw_soap_soundlength = tpw_soap_mideastsoundlength;
  178. tpw_soap_songlength = tpw_soap_mideastsonglength;
  179. tpw_soap_musicfactor = 0.8; // Slightly quieter Arabic music
  180. };
  181.  
  182. if (tpw_soap_region == 3) then
  183. {
  184. tpw_soap_sounds = 25;
  185. tpw_soap_songs = 11;
  186. tpw_soap_path = "TPW_AMBIENCE\sounds\fiji\";
  187. tpw_soap_soundlength = tpw_soap_fijisoundlength;
  188. tpw_soap_songlength = tpw_soap_fijisonglength;
  189. tpw_soap_musicfactor = 2; // Slightly quieter Fijian music
  190. };
  191.  
  192. // Adjust volume & chance of spawning based on time of day
  193. tpw_soap_soundvolmult = [0.3,0.2,0.1,0.1,0.1,0.5,0.6,0.7,0.8,0.9,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.9,0.8,0.6,0.6,0.5,0.3,0.3] select (round daytime);
  194. tpw_soap_musicvolmult = [0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.5,0.6,0.7,0.8,0.9,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.2,1.1,1,0.8,0.6,0.4,0.0] select (round daytime);
  195.  
  196. // Scan for habitable houses
  197. _nearhouses = [tpw_soap_radius] call tpw_core_fnc_houses;
  198. tpw_soap_nearhouses = _nearhouses;
  199.  
  200. // Loop through nearest houses, find first available
  201. for "_i" from 0 to (count tpw_soap_nearhouses - 1) do
  202. {
  203. _house = tpw_soap_nearhouses select _i;
  204.  
  205. // Play environmental ambience if not already doing so
  206. if (
  207. (_house getvariable ["tpw_soap_ambienceflag",0] == 0) &&
  208. {_house distance player > 5} &&
  209. {random 1 < tpw_soap_soundvolmult} &&
  210. {tpw_soap_soundsplaying < tpw_soap_maxsounds}
  211. ) then
  212. {
  213. tpw_soap_soundsplaying = tpw_soap_soundsplaying + 1;
  214. _house setvariable ["tpw_soap_ambienceflag",1,true];
  215. [_house] call tpw_soap_fnc_ambientsounds;
  216. };
  217.  
  218. // Occasionally play music if not already doing so
  219. if (
  220. (_house getvariable ["tpw_soap_musicflag",0] == 0) &&
  221. {_house distance player > 5} &&
  222. {random 50 < (1 * tpw_soap_musicvolmult)} &&
  223. {tpw_soap_songsplaying < tpw_soap_maxsongs}
  224. ) then
  225. {
  226. tpw_soap_songsplaying = tpw_soap_songsplaying + 1;
  227. _house setvariable ["tpw_soap_musicflag",1,true];
  228. [_house] call tpw_soap_fnc_ambientmusic;
  229. };
  230. };
  231. };
  232.  
  233. // MOSQUE SCANNING
  234. tpw_soap_fnc_mosquescan =
  235. {
  236. private ["_nearhouses","_nearmosques","_mosque","_i","_playflag"];
  237. // Scan for habitable houses - which can include mosques
  238.  
  239. _nearhouses = [250] call tpw_core_fnc_houses;
  240. _nearmosques = [];
  241.  
  242. // Grab nearest mosques - but only want one playing at a given time
  243. _playflag = 0;
  244. for "_i" from 0 to (count _nearhouses - 1) do
  245. {
  246. _mosque = _nearhouses select _i;
  247. if (["osque",str typeof _mosque] call BIS_fnc_inString) then
  248. {
  249. _nearmosques set [count _nearmosques,_mosque];
  250. };
  251. };
  252. _nearmosques = [_nearmosques,[],{player distance _x},"ASCEND"] call BIS_fnc_sortBy;
  253.  
  254. if ((count _nearmosques > 0) && {_mosque getvariable ["tpw_soap_azanflag",0] == 0}) then
  255. {
  256. _mosque = _nearmosques select 0;
  257. [_mosque] call tpw_soap_fnc_azanplay;
  258. };
  259. };
  260.  
  261. // PLAY MUSIC FROM HOUSES
  262. tpw_soap_fnc_ambientmusic =
  263. {
  264. private ["_house","_sel","_len","_finish","_clip","_pos","_pitch","_atten"];
  265. _house = _this select 0;
  266. [_house] spawn
  267. {
  268. sleep random 3;
  269. _house = _this select 0;
  270. _pitch = 1;
  271. _pos = getposasl _house;
  272. _atten = tpw_soap_attenuation + random tpw_soap_attenuation;
  273.  
  274. // Music
  275. _sel = floor (random tpw_soap_songs);
  276. _clip = format ["%1s%2.ogg",tpw_soap_path,_sel + 1];
  277. _len = tpw_soap_songlength select _sel;
  278.  
  279. // Play user song from @TPW_MODS\music
  280. if ((tpw_soap_usermusic >0) && {random 10 < 5}) then
  281. {
  282. _clip = format ["@TPW_MODS\music\%1.ogg",floor (random tpw_soap_usermusic) + 1];
  283. _len = 180;
  284. };
  285. _finish = diag_ticktime + _len - 5;
  286. _house setvariable ["tpw_soap_musicflag",_finish,true];
  287. playsound3d [_clip,_house,false,_pos,(tpw_soap_musicvolume * tpw_soap_volume * tpw_soap_musicvolmult * tpw_soap_musicfactor),_pitch,_atten];
  288. waituntil
  289. {
  290. sleep 5;
  291. (diag_ticktime > _house getvariable "tpw_soap_musicflag");
  292. };
  293. _house setvariable ["tpw_soap_musicflag",0,true];
  294. tpw_soap_songsplaying = tpw_soap_songsplaying - 1;
  295. };
  296. };
  297.  
  298. // PLAY ENVIROMENTAL AMBIENCE IN HOUSES
  299. tpw_soap_fnc_ambientsounds =
  300. {
  301. private ["_house","_sel","_len","_finish","_clip","_pos","_pitch","_atten"];
  302. _house = _this select 0;
  303. [_house] spawn
  304. {
  305. sleep random 3;
  306. _house = _this select 0;
  307. _pitch = 0.9 + random 0.2;
  308. _pos = getposasl _house;
  309. _atten = tpw_soap_attenuation + random tpw_soap_attenuation;
  310.  
  311. // Inbuilt SFX
  312. _sel = floor (random tpw_soap_sounds);
  313. _clip = format ["%1%2.ogg",tpw_soap_path,_sel + 1];
  314. _len = tpw_soap_soundlength select _sel;
  315.  
  316. // User SFX
  317. if ((tpw_soap_usersounds > 0) && {random 10 < 5}) then
  318. {
  319. _clip = format ["@TPW_MODS\sounds\%1.ogg",floor (random tpw_soap_usersounds) + 1];
  320. _len = 30;
  321. };
  322. _finish = diag_ticktime + _len - 5;
  323. _house setvariable ["tpw_soap_ambienceflag",_finish,true];
  324. playsound3d [_clip,_house,false,_pos,(tpw_soap_ambientvolume * tpw_soap_volume * tpw_soap_soundvolmult),_pitch,_atten];
  325. waituntil
  326. {
  327. sleep 5;
  328. (diag_ticktime > _house getvariable "tpw_soap_ambienceflag");
  329. };
  330. _house setvariable ["tpw_soap_ambienceflag",0,true];
  331. tpw_soap_soundsplaying = tpw_soap_soundsplaying - 1;
  332. };
  333. };
  334.  
  335. // PLAY AZAN IN NEARBY MOSQUE
  336. tpw_soap_fnc_azanplay =
  337. {
  338. private ["_mosque","_sel","_len","_finish","_song","_vol","_pos"];
  339. _mosque = _this select 0;
  340. if (player distance _mosque > 250) exitwith {};
  341. [_mosque] spawn
  342. {
  343. _mosque = _this select 0;
  344. _sel = floor random 10;
  345. _len = tpw_soap_azanlength select _sel;
  346. _song = format ["sounds\tpw_azan\sounds\%1.ogg",(_sel + 1)];
  347. _finish = diag_ticktime + _len;
  348. _mosque setvariable ["tpw_soap_azanflag",_finish,true];
  349. _vol = tpw_soap_azanvolume * 0.5 + random 0.5;
  350. _pos = getposasl _mosque;
  351. _pos = [_pos select 0, _pos select 1, (_pos select 2) + 50];
  352. playsound3d [_song,_mosque,false,_pos,_vol,1,0];
  353. tpw_soap_azanflag = 1;
  354. sleep 10;
  355. // Play prayer in nearest house
  356. playsound3d ["sounds\mideast\18.ogg",nearestbuilding player];
  357. waituntil
  358. {
  359. sleep 10;
  360. (diag_ticktime > _mosque getvariable "tpw_soap_azanflag");
  361. };
  362. _mosque setvariable ["tpw_soap_azanflag",0,true];
  363. tpw_soap_azanflag = 0;
  364. };
  365. };
  366.  
  367. // CREAKING NOISES IN HOUSES
  368. tpw_soap_fnc_housenoise =
  369. {
  370. private ["_sound","_pitch","_vol"];
  371. while {true} do
  372. {
  373. if (([] call tpw_soap_fnc_indoors) && {[] call tpw_soap_fnc_nearestbuilding < 10}) then
  374. {
  375. _pitch = 0.8 + random 0.4;
  376. _vol = (tpw_soap_housefxvolume * windstr * 0.25); // louder creaking in the wind
  377. _sound = format ["sounds\house\c%1.ogg",(ceil random 7)];
  378. playsound3d [_sound,player,false,getposasl player,_vol,_pitch,50];
  379. };
  380. sleep random 30;
  381. };
  382. };
  383.  
  384. // WIND NOISE IN HOUSES
  385. tpw_soap_fnc_windnoise =
  386. {
  387. private ["_sound","_pitch","_vol"];
  388. while {true} do
  389. {
  390. if (([] call tpw_soap_fnc_indoors) && {[] call tpw_soap_fnc_nearestbuilding < 10} && {windstr > 0.2}) then
  391. {
  392. _pitch = 0.8 + random 0.4;
  393. _vol = (tpw_soap_housefxvolume * windstr * 0.5);
  394. _sound = format ["sounds\house\w%1.ogg",(ceil random 9)];
  395. playsound3d [_sound,player,false,getposasl player,_vol,_pitch,50]; // wind
  396. sleep random 10;
  397. _sound = format ["sounds\house\r%1.ogg",(ceil random 6)]; // rattle
  398. playsound3d [_sound,player,false,getposasl player,_vol * 2,_pitch,50];
  399. };
  400. sleep 30 + random 10;
  401. };
  402. };
  403.  
  404. // MONITOR DEATHS, LOWER MASTER VOLUME FOR A FEW MINUTES AFTER EACH NEW DEATH
  405. tpw_soap_fnc_battle =
  406. {
  407. private ["_battletime","_orig_vol"];
  408. _battletime = 0;
  409. _orig_vol = tpw_soap_volume;
  410. while {true} do
  411. {
  412. if (count alldeadmen > tpw_soap_dead) then
  413. {
  414. tpw_soap_dead = count alldead;
  415. _battletime = diag_ticktime + (random 120);
  416. tpw_soap_volume = _orig_vol * 0.5;
  417. };
  418. if (diag_ticktime > _battletime) then
  419. {
  420. tpw_soap_volume = _orig_vol;
  421. };
  422. sleep 11.53;
  423. };
  424. };
  425.  
  426. // SCREAMS / BARKS IF NEARBY GUNFIRE
  427. player addeventhandler ["firednear",{0 = [player] spawn tpw_soap_fnc_scream}];
  428. tpw_soap_bulletcount = 0;
  429. tpw_soap_nextcry = 0;
  430. tpw_soap_fnc_scream =
  431. {
  432. private ["_sound","_pitch","_vol","_house","_nearhouses"];
  433. if ((tpw_soap_active) && {diag_ticktime > tpw_soap_nextcry} && {random 10 < 3}) then
  434. {
  435. tpw_soap_nextcry = diag_ticktime + random 15;
  436. sleep 1 + random 5;
  437. _nearhouses = [tpw_soap_radius * 0.75] call tpw_core_fnc_houses;
  438. if ((_nearhouses select 0 distance player < tpw_soap_radius) && {!([] call tpw_soap_fnc_indoors)}) then
  439. {
  440. _house = _nearhouses select floor (random (count _nearhouses));
  441. _vol = tpw_soap_housefxvolume * 2;
  442. _pitch = 0.9 + random 0.2;
  443. if (random 10 < 5) then
  444. {
  445. _sound = format ["sounds\fear\%1.ogg",(ceil random 12)]; // screams, babies
  446. } else
  447. {
  448. _sound = format ["sounds\tpw_sounds\sounds\dog%1.ogg",ceil (random 20)]; // barks
  449. };
  450. playsound3d [_sound,_house,false,getposasl _house,_vol,_pitch,100];
  451. };
  452. };
  453. };
  454.  
  455. // RUN IT
  456. [] spawn tpw_soap_fnc_battle;
  457. [] spawn tpw_soap_fnc_mainloop;
  458. [] spawn tpw_soap_fnc_azanloop;
  459. [] spawn tpw_soap_fnc_housenoise;
  460. [] spawn tpw_soap_fnc_windnoise;
  461.  
  462. while {true} do
  463. {
  464. // dummy loop so script doesn't terminate
  465. sleep 10;
  466. };
RAW Paste Data