Implemented a setDead function. Allows for interception of all kills and using a revive script instead.

Added playInjuredSound for damaged units.
Fixed some mistakes with variable names.
This commit is contained in:
Glowbal 2015-02-08 13:18:08 +01:00
parent a3c4c60b7f
commit a609d00730
8 changed files with 151 additions and 14 deletions

View File

@ -43,14 +43,14 @@ GVAR(effectUnconsciousUnit) = objNull;
GVAR(playingHeartBeatSound) = true;
_sleep = 60 / _heartRate;
if (_heartRate < 60) then {
_sound = _hbSoundsSlow select (random((count _hbSoundsSlow) -1));
_sound = GVAR(heartBeatSounds_Slow) select (random((count GVAR(heartBeatSounds_Slow)) -1));
playSound _sound;
[{
GVAR(playingHeartBeatSound) = false;
}, [], _sleep, _sleep] call EFUNC(common,waitAndExecute);
} else {
if (_heartRate > 120) then {
_sound = _hbSoundsFast select (random((count _hbSoundsFast) -1));
_sound = GVAR(heartBeatSounds_Fast) select (random((count GVAR(heartBeatSounds_Fast)) -1));
playSound _sound;
[{
GVAR(playingHeartBeatSound) = false;

View File

@ -23,6 +23,8 @@ PREP(addToInjuredCollection);
PREP(setUnconscious);
PREP(getUnconsciousCondition);
PREP(addUnconsciousCondition);
PREP(setDead);
PREP(playInjuredSound);
GVAR(injuredUnitCollection) = [];

View File

@ -38,7 +38,7 @@ if ([_unit] call FUNC(hasMedicalEnabled)) then {
if (random(1) > 0.6) then {
[_unit] call FUNC(setUnconscious);
};
//[_unit] call FUNC(playInjuredSound);
[_unit] call FUNC(playInjuredSound);
};
};
}, 1, [_unit]] call CBA_fnc_addPerFrameHandler;

View File

@ -43,7 +43,7 @@ if ((_unit call FUNC(getBloodLoss)) > 0) then {
};
};
_painStatus = _unit getvariable [QGVAR(amountOfPain), 0];
_painStatus = _unit getvariable [QGVAR(pain), 0];
if (_painStatus > 0) then {
if !(_unit getvariable [QGVAR(hasPain), false]) then {
_unit setvariable [QGVAR(hasPain), true, true];
@ -56,7 +56,7 @@ if (_painStatus > 0) then {
if (_bloodVolume < 30) exitwith {
// [_unit] call FUNC(setDead);
[_unit] call FUNC(setDead);
};
if ([_unit] call EFUNC(common,isAwake)) then {

View File

@ -0,0 +1,97 @@
/*
* Author: Glowbal
* 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.
*
* Arguments:
* 0: The Unit <OBJECT>
*
* ReturnValue:
* <NIL>
*
* Public: No
*/
#include "script_component.hpp"
private ["_unit","_amountOfDamage","_bodyPartStatus","_availableSounds_A","_availableSounds_B","_availableSounds_C","_sound"];
_unit = _this select 0;
if (!local _unit) exitwith{};
// Lock if the unit is already playing a sound.
if ((_unit getvariable [QGVAR(playingInjuredSound),false])) exitwith {};
_unit setvariable [QGVAR(playingInjuredSound),true];
// Classnames of the available sounds.
_availableSounds_A = [
"WoundedGuyA_01",
"WoundedGuyA_02",
"WoundedGuyA_03",
"WoundedGuyA_04",
"WoundedGuyA_05",
"WoundedGuyA_06",
"WoundedGuyA_07",
"WoundedGuyA_08"
];
_availableSounds_B = [
"WoundedGuyB_01",
"WoundedGuyB_02",
"WoundedGuyB_03",
"WoundedGuyB_04",
"WoundedGuyB_05",
"WoundedGuyB_06",
"WoundedGuyB_07",
"WoundedGuyB_08"
];
_availableSounds_C = [
"WoundedGuyC_01",
"WoundedGuyC_02",
"WoundedGuyC_03",
"WoundedGuyC_04",
"WoundedGuyC_05"
];
// TODO 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);
_amountOfDamage = 0;
/*{
_amountOfDamage = _amountOfDamage + _x;
}foreach _bodyPartStatus;*/
// Play the sound if there is any damage present.
if (_amountOfDamage > 0) exitwith {
_sound = "";
// Select the to be played sound based upon damage amount.
if (_amountOfDamage > 1) then {
if (random(1) > 0.5) then {
_sound = _availableSounds_A select (round(random((count _availableSounds_A) - 1)));
} else {
_sound = _availableSounds_B select (round(random((count _availableSounds_B) - 1)));
};
} else {
_sound = _availableSounds_B select (round(random((count _availableSounds_B) - 1)));
};
// 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 {
_delay = 10 + random(50);
} else {
_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];

View File

@ -40,8 +40,7 @@ _timer = 0;
[(_this select 1)] call cba_fnc_removePerFrameHandler;
};
if (_counter - _timer < 1) exitwith {
//[_unit] call FUNC(setDead);
[_unit] call FUNC(setDead);
[(_this select 1)] call cba_fnc_removePerFrameHandler;
_unit setvariable [QGVAR(inCardiacArrest), nil,true];
};

View File

@ -0,0 +1,36 @@
/*
* Author: Glowbal
* Either kills a unit or puts the unit in a revivable state, depending on the settings.
*
* Arguments:
* 0: The unit that will be killed <OBJECT>
*
* ReturnValue:
* <NIL>
*
* Public: yes
*/
#include "script_component.hpp"
private ["_unit"];
_unit = _this select 0;
_force = false;
if (count _this >= 2) then {
_force = _this select 1;
};
if (!alive _unit) exitwith{};
if (!local _unit) exitwith {
[[_unit, _force], QUOTE(FUNC(setDead)), _unit, false] call EFUNC(common,execRemoteFnc);
};
if (missionName getVariable [QGVAR(enableRevive), false]) exitwith {
// TODO Implement the revive state
};
_unit setvariable ["ACE_isDead", true, true];
if (isPLayer _unit) then {
_unit setvariable ["isDeadPlayer", true, true];
};
_unit setdamage 1;

View File

@ -1,11 +1,14 @@
/**
* fn_setUnconsciousState.sqf
* @Descr: Sets a unit in the unconscious state
* @Author: Glowbal
/*
* Author: Glowbal
* Sets a unit in the unconscious state.
*
* @Arguments: [unit OBJECT]
* @Return: void
* @PublicAPI: true
* Arguments:
* 0: The unit that will be put in an unconscious state <OBJECT>
*
* ReturnValue:
* <NIL>
*
* Public: yes
*/
#include "script_component.hpp"