fnc_fired_deployable_loopSoundLocal.sqf 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. params["_object", "_loopSound", "_loopDuration", "_totalDuration", "_distance"];
  2. if(!hasInterface) exitWith {
  3. diag_log "No Interface to play sounds from";
  4. };
  5. if(isNil "_object" || !alive _object) exitWith {
  6. diag_log "No target object to play remote sound";
  7. };
  8. private _currentSource = _object getVariable ["rd501_fired_deployable_loopSoundSource", objNull];
  9. systemChat str _currentSource;
  10. if(!(isNil "_currentSource") && !(_currentSource isEqualTo objNull)) exitWith {
  11. diag_log "Source already exists, removing";
  12. detach _currentSource;
  13. deleteVehicle _currentSource;
  14. _object setVariable ["rd501_fired_deployable_loopSoundSource", objNull, false];
  15. [_object, _loopSound, _loopDuration, _totalDuration, _distance] call rd501_fnc_fired_deployable_loopSoundLocal;
  16. };
  17. _currentSource = "#dynamicsound" createVehicleLocal ASLToAGL getPosWorld _object;
  18. _currentSource attachTo [_object, [0, 0, 0]];
  19. _object setVariable ["rd501_fired_deployable_loopSoundSource", _currentSource, false];
  20. private _repeats = ceil (_totalDuration / _loopDuration);
  21. for "_i" from 0 to _repeats step 1 do {
  22. private _delay = ((_loopDuration * _i) - 0.1) max 0.1; //offset by a bit to ensure loop doesn't have a hitch
  23. private _last = _repeats == _i;
  24. diag_log format["Queuing Up Repeat %1 for delay %2", _i, _delay];
  25. [
  26. {
  27. params["_currentSource", "_loopSound", "_distance", "_last"];
  28. if(isNil "_currentSource" || !alive _currentSource) exitWith { systemChat "No Source, Exiting." };
  29. [_currentSource, player] say3D [_loopSound, _distance, 1, false];
  30. if(_last) then {
  31. diag_log "Last Loop, Deleting";
  32. detach _currentSource;
  33. deleteVehicle _currentSource;
  34. };
  35. },
  36. [_currentSource, _loopSound, _distance, _last],
  37. _delay
  38. ] call CBA_fnc_waitAndExecute;
  39. };
  40. _currentSource