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