Skip to content

Commit ea3f6ee

Browse files
DartRuffianjohnb432PabstMirror
authored
Fire - Add ability to customize screams when on fire (#10890)
* Add ability to customize screams when on fire * Add docs * Add check for empty class * Update headers * Apply suggestions from code review Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com> * Handle extra cases * _overwrite -> _append * Apply suggestions from code review Co-authored-by: PabstMirror <pabstmirror@gmail.com> * Apply suggestion from @PabstMirror Co-authored-by: PabstMirror <pabstmirror@gmail.com> * Change function and hashmap name to be more consistent * Update docs/wiki/framework/fire-framework.md --------- Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com> Co-authored-by: PabstMirror <pabstmirror@gmail.com>
1 parent 06747e1 commit ea3f6ee

File tree

7 files changed

+147
-2
lines changed

7 files changed

+147
-2
lines changed

addons/fire/CfgVehicles.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,13 @@ class CfgVehicles {
44
scope = 1;
55
displayName = "";
66
};
7+
8+
class Man;
9+
class CAManBase: Man {
10+
GVAR(screamSounds)[] = {
11+
QGVAR(scream_1), QGVAR(scream_2), QGVAR(scream_3), QGVAR(scream_4), QGVAR(scream_5),
12+
QGVAR(scream_6), QGVAR(scream_7), QGVAR(scream_8), QGVAR(scream_9), QGVAR(scream_10),
13+
QGVAR(scream_11), QGVAR(scream_12), QGVAR(scream_13), QGVAR(scream_14), QGVAR(scream_15)
14+
};
15+
};
716
};

addons/fire/XEH_PREP.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
PREP(addScreamSounds);
12
PREP(burn);
23
PREP(burnEffects);
34
PREP(burnIndicator);
45
PREP(burnReaction);
56
PREP(burnSimulation);
67
PREP(fireManagerPFH);
8+
PREP(getScreamSounds);
79
PREP(initUnit);
810
PREP(isBurning);
911
PREP(medical_canPatDown);

addons/fire/XEH_preInit.sqf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ PREP_RECOMPILE_END;
88

99
#include "initSettings.inc.sqf"
1010

11+
GVAR(screamSounds) = createHashMap;
12+
1113
ADDON = true;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include "..\script_component.hpp"
2+
/*
3+
* Author: DartRuffian
4+
* Adds custom fire scream sounds for a unit class.
5+
*
6+
* Arguments:
7+
* 0: Unit class <STRING>
8+
* 1: Array of CfgSounds classes <ARRAY of STRINGs>
9+
* 2: Append to existing sounds array <BOOL> (default: true)
10+
* - true : Passed sounds will be added to unit's existing sounds
11+
* - false: Passed sounds will replace unit's existing sounds
12+
*
13+
* Return Value:
14+
* Succeeded <BOOL>
15+
*
16+
* Example:
17+
* [typeOf player, ["sound1", "sound2"]] call ace_fire_fnc_addScreamSounds
18+
*
19+
* Public: Yes
20+
*/
21+
22+
params [["_unitClass", "", [""]], ["_screams", [], [[]]], ["_append", true, [false]]];
23+
TRACE_3("fnc_addScreamSounds",_unitClass,_screams,_overwrite);
24+
25+
if (_unitClass == "" || _screams isEqualTo [] || !(_unitClass isKindOf "CAManBase")) exitWith { false };
26+
27+
if (_append) then {
28+
private _existingScreams = _unitClass call FUNC(getScreamSounds);
29+
_existingScreams append _screams;
30+
GVAR(screamSounds) set [_unitClass, _existingScreams];
31+
} else {
32+
GVAR(screamSounds) set [_unitClass, _screams];
33+
};
34+
35+
true // return

addons/fire/functions/fnc_burnReaction.sqf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,9 @@ if (
2323
_unit call EFUNC(common,throwWeapon);
2424
};
2525

26-
[QGVAR(playScream), [format [QGVAR(scream_%1), floor (1 + random 15)], _unit]] call CBA_fnc_globalEvent;
26+
// There is a potential issue if a client side mod defines new sounds and adds them
27+
// Since the class that's broadcasted would not be defined on other clients
28+
private _scream = selectRandom (_unit call FUNC(getScreamSounds));
29+
if (!isNil "_scream" && {_scream != ""}) then {
30+
[QGVAR(playScream), [_scream, _unit]] call CBA_fnc_globalEvent;
31+
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include "..\script_component.hpp"
2+
/*
3+
* Author: DartRuffian
4+
* Returns a list of scream sounds that a unit will play when on fire.
5+
*
6+
* Arguments:
7+
* 0: Unit <OBJECT or STRING>
8+
*
9+
* Return Value:
10+
* Scream sounds <ARRAY of STRINGs>
11+
*
12+
* Example:
13+
* player call ace_fire_fnc_getScreamSounds
14+
*
15+
* Public: Yes
16+
*/
17+
18+
params [["_unitClass", objNull, [objNull, ""]]];
19+
TRACE_1("fnc_getScreamSounds",_unitClass);
20+
21+
if (_unitClass isEqualType objNull) then {
22+
_unitClass = typeOf _unitClass;
23+
};
24+
if (_unitClass == "" || !(_unitClass isKindOf "CAManBase")) exitWith { [] };
25+
26+
// If unit is defined in hash, grab sounds and return
27+
// If not, check each parent of the class until a value is defined
28+
GVAR(screamSounds) getOrDefaultCall [toLowerANSI _unitClass, {
29+
private _cfg = configFile >> "CfgVehicles" >> _unitClass;
30+
private _return = getArray (_cfg >> QGVAR(screamSounds));
31+
while {!isNull _cfg} do {
32+
_cfg = inheritsFrom _cfg;
33+
if ((toLowerANSI configName _cfg) in GVAR(screamSounds)) exitWith { _return = GVAR(screamSounds) get (toLowerANSI configName _cfg) };
34+
};
35+
_return
36+
}, true] // return

docs/wiki/framework/fire-framework.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Use `CBA_fnc_serverEvent` to use the following features. Events are defined only
3636

3737
| | Arguments | Type(s) | Optional (default value) |
3838
|----| --------- | ------- | ------------------------ |
39-
| 0 | Fire source ID | Array/Boolean/Code/Config/Group/Namespace/NaN/Number/Object/Side/String | Required |
39+
| 0 | Fire source ID | Array/Boolean/Code/Config/Group/Namespace/NaN/Number/Object/Side/String | Required |
4040

4141
## 2. Variables
4242

@@ -47,6 +47,7 @@ _unit setVariable ["ace_fire_enableScreams", false, _isGlobal];
4747
```
4848

4949
## 3. Config Values
50+
5051
### 3.1 Adding fire protection to a uniform
5152

5253
{% raw %}
@@ -59,3 +60,58 @@ class CfgWeapons {
5960
};
6061
```
6162
{% endraw %}
63+
64+
### 3.2 Custom scream sounds
65+
66+
{% raw %}
67+
```cpp
68+
class CfgVehicles {
69+
class CAManBase;
70+
class yourManClass: CAManBase {
71+
ace_fire_screamSounds[] = {
72+
"sound_name" // Name of sound(s) in CfgSounds
73+
};
74+
};
75+
};
76+
```
77+
{% endraw %}
78+
79+
## 4. Scripting
80+
81+
### 4.1 Setting/Adding Custom Screaming Sounds
82+
83+
`ace_fire_fnc_addScreamSounds`
84+
85+
```sqf
86+
* Adds custom fire scream sounds for a unit class.
87+
*
88+
* Arguments:
89+
* 0: Unit class <STRING>
90+
* 1: Array of CfgSounds classes <ARRAY of STRING>
91+
* 2: Append to existing sounds array <BOOL> (default: true)
92+
* - true : Passed sounds will be added to unit's existing sounds
93+
* - false: Passed sounds will replace unit's existing sounds
94+
*
95+
* Return Value:
96+
* Succeeded <BOOL>
97+
*
98+
* Example:
99+
* [typeOf player, ["sound1", "sound2"]] call ace_fire_fnc_addScreamSounds
100+
```
101+
102+
### 4.1 Getting Screaming Sounds
103+
104+
`ace_fire_fnc_getScreamSounds`
105+
106+
```sqf
107+
* Returns a list of scream sounds that a unit will play when on fire.
108+
*
109+
* Arguments:
110+
* 0: Unit <OBJECT or STRING>
111+
*
112+
* Return Value:
113+
* Scream sounds <ARRAY of STRINGs>
114+
*
115+
* Example:
116+
* player call ace_fire_fnc_getScreamSounds
117+
```

0 commit comments

Comments
 (0)