mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Updated playInjured
Removed sleep. Made use of waitUnitl execute. Changed MP sound broadcasting. No longer using the broadcastSound_F function.
This commit is contained in:
@ -1,10 +1,13 @@
|
|||||||
/**
|
/**
|
||||||
* fn_playInjuredSound.sqf
|
* fn_playInjuredSound.sqf
|
||||||
* @Descr: N/A
|
* @Descr: Play the injured sound for a unit if the unit is damaged. The sound broadcasted across MP.
|
||||||
|
* Will not play if the unit has already played a sound within to close a time frame.
|
||||||
|
* Delay: With minimal damage (below 1), the delay is (10 + random(50)) seconds. Otherwise it is 60 seconds / damage.
|
||||||
|
*
|
||||||
* @Author: Glowbal
|
* @Author: Glowbal
|
||||||
*
|
*
|
||||||
* @Arguments: []
|
* @Arguments: [unit OBJECT]
|
||||||
* @Return:
|
* @Return: nil
|
||||||
* @PublicAPI: false
|
* @PublicAPI: false
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -14,8 +17,11 @@ private ["_unit","_amountOfDamage","_bodyPartStatus","_availableSounds_A","_avai
|
|||||||
_unit = _this select 0;
|
_unit = _this select 0;
|
||||||
if (!local _unit) exitwith{};
|
if (!local _unit) exitwith{};
|
||||||
|
|
||||||
|
// Lock if the unit is already playing a sound.
|
||||||
if ((_unit getvariable [QGVAR(playingInjuredSound),false])) exitwith {};
|
if ((_unit getvariable [QGVAR(playingInjuredSound),false])) exitwith {};
|
||||||
_unit setvariable [QGVAR(playingInjuredSound),true];
|
_unit setvariable [QGVAR(playingInjuredSound),true];
|
||||||
|
|
||||||
|
// Classnames of the available sounds.
|
||||||
_availableSounds_A = [
|
_availableSounds_A = [
|
||||||
"WoundedGuyA_01",
|
"WoundedGuyA_01",
|
||||||
"WoundedGuyA_02",
|
"WoundedGuyA_02",
|
||||||
@ -44,16 +50,19 @@ _availableSounds_C = [
|
|||||||
"WoundedGuyC_05"
|
"WoundedGuyC_05"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// TODO Maybe base this off hitpoint damage
|
||||||
|
// Find the amount of damage for this unit, based upon body part status.
|
||||||
_bodyPartStatus = [_unit,QGVAR(bodyPartStatus)] call EFUNC(common,getDefinedVariable);
|
_bodyPartStatus = [_unit,QGVAR(bodyPartStatus)] call EFUNC(common,getDefinedVariable);
|
||||||
|
|
||||||
_amountOfDamage = 0;
|
_amountOfDamage = 0;
|
||||||
{
|
{
|
||||||
_amountOfDamage = _amountOfDamage + _x;
|
_amountOfDamage = _amountOfDamage + _x;
|
||||||
}foreach _bodyPartStatus;
|
}foreach _bodyPartStatus;
|
||||||
|
|
||||||
|
// Play the sound if there is any damage present.
|
||||||
if (_amountOfDamage > 0) then {
|
if (_amountOfDamage > 0) exitwith {
|
||||||
_sound = "";
|
_sound = "";
|
||||||
|
|
||||||
|
// Select the to be played sound based upon damage amount.
|
||||||
if (_amountOfDamage > 1) then {
|
if (_amountOfDamage > 1) then {
|
||||||
if (random(1) > 0.5) then {
|
if (random(1) > 0.5) then {
|
||||||
_sound = _availableSounds_A select (round(random((count _availableSounds_A) - 1)));
|
_sound = _availableSounds_A select (round(random((count _availableSounds_A) - 1)));
|
||||||
@ -63,13 +72,24 @@ if (_amountOfDamage > 0) then {
|
|||||||
} else {
|
} else {
|
||||||
_sound = _availableSounds_B select (round(random((count _availableSounds_B) - 1)));
|
_sound = _availableSounds_B select (round(random((count _availableSounds_B) - 1)));
|
||||||
};
|
};
|
||||||
[[_unit,_sound], QUOTE(EFUNC(common,broadcastSound3D_F)), true] call EFUNC(common,execRemoteFnc);
|
|
||||||
|
// Play the sound
|
||||||
|
playSound3D [((getArray(configFile >> "CfgSounds" >> _sound >> "sound") select 0)), _unit, false, getPos _unit, 2, 1, 15]; // +2db, 15 meters.
|
||||||
|
|
||||||
|
// Figure out what the delay will be before it is possible to play a sound again.
|
||||||
|
private "_delay";
|
||||||
|
_delay = 1;
|
||||||
if (_amountOfDamage < 1) then {
|
if (_amountOfDamage < 1) then {
|
||||||
sleep 10;
|
_delay = 10 + random(50);
|
||||||
sleep (random(50));
|
|
||||||
} else {
|
} else {
|
||||||
sleep (60 / _amountOfDamage);
|
_delay = (60 / _amountOfDamage);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Clean up the lock
|
||||||
|
[{
|
||||||
|
(_this select 0) setvariable [QGVAR(playingInjuredSound),nil];
|
||||||
|
}, [_unit], _delay, _delay] call EFUNC(common,waitAndExecute);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Clean up in case there has not been played any sounds.
|
||||||
_unit setvariable [QGVAR(playingInjuredSound),nil];
|
_unit setvariable [QGVAR(playingInjuredSound),nil];
|
Reference in New Issue
Block a user