| 1 | <h2>Full example</h2> |
| 2 | <pre><code>#include "script_component.hpp" |
| 3 | /* |
| 4 | * Author: BaerMitUmlaut |
| 5 | * Handles any audible, visual and physical effects of fatigue. |
| 6 | * |
| 7 | * Arguments: |
| 8 | * 0: Unit <OBJECT> |
| 9 | * 1: Fatigue <NUMBER> |
| 10 | * 2: Speed <NUMBER> |
| 11 | * 3: Overexhausted <BOOL> |
| 12 | * |
| 13 | * Return Value: |
| 14 | * None |
| 15 | * |
| 16 | * Example: |
| 17 | * [_player, 0.5, 3.3, true] call ace_advanced_fatigue_fnc_handleEffects |
| 18 | * |
| 19 | * Public: No |
| 20 | */ |
| 21 | params ["_unit", "_fatigue", "_speed", "_overexhausted"]; |
| 22 | |
| 23 | #ifdef DEBUG_MODE_FULL |
| 24 | systemChat str _fatigue; |
| 25 | systemChat str vectorMagnitude velocity _unit; |
| 26 | #endif |
| 27 | |
| 28 | // - Audible effects ---------------------------------------------------------- |
| 29 | GVAR(lastBreath) = GVAR(lastBreath) + 1; |
| 30 | if (_fatigue > 0.4 && {GVAR(lastBreath) > (_fatigue * -10 + 9)} && {!underwater _unit}) then { |
| 31 | switch (true) do { |
| 32 | case (_fatigue < 0.6): { |
| 33 | playSound (QGVAR(breathLow) + str(floor random 6)); |
| 34 | }; |
| 35 | case (_fatigue < 0.85): { |
| 36 | playSound (QGVAR(breathMid) + str(floor random 6)); |
| 37 | }; |
| 38 | default { |
| 39 | playSound (QGVAR(breathMax) + str(floor random 6)); |
| 40 | }; |
| 41 | }; |
| 42 | GVAR(lastBreath) = 0; |
| 43 | }; |
| 44 | |
| 45 | // - Visual effects ----------------------------------------------------------- |
| 46 | GVAR(ppeBlackoutLast) = GVAR(ppeBlackoutLast) + 1; |
| 47 | if (GVAR(ppeBlackoutLast) == 1) then { |
| 48 | GVAR(ppeBlackout) ppEffectAdjust [1,1,0,[0,0,0,1],[0,0,0,0],[1,1,1,1],[10,10,0,0,0,0.1,0.5]]; |
| 49 | GVAR(ppeBlackout) ppEffectCommit 1; |
| 50 | } else { |
| 51 | if (_fatigue > 0.85) then { |
| 52 | if (GVAR(ppeBlackoutLast) > (100 - _fatigue * 100) / 3) then { |
| 53 | GVAR(ppeBlackout) ppEffectAdjust [1,1,0,[0,0,0,1],[0,0,0,0],[1,1,1,1],[2,2,0,0,0,0.1,0.5]]; |
| 54 | GVAR(ppeBlackout) ppEffectCommit 1; |
| 55 | GVAR(ppeBlackoutLast) = 0; |
| 56 | }; |
| 57 | }; |
| 58 | }; |
| 59 | |
| 60 | // - Physical effects --------------------------------------------------------- |
| 61 | if (GVAR(isSwimming)) exitWith { |
| 62 | if (GVAR(setAnimExclusions) isEqualTo []) then { |
| 63 | _unit setAnimSpeedCoef linearConversion [0.7, 0.9, _fatigue, 1, 0.5, true]; |
| 64 | }; |
| 65 | if ((isSprintAllowed _unit) && {_fatigue > 0.7}) then { |
| 66 | [_unit, "blockSprint", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set); |
| 67 | } else { |
| 68 | if ((!isSprintAllowed _unit) && {_fatigue < 0.7}) then { |
| 69 | [_unit, "blockSprint", QUOTE(ADDON), false] call EFUNC(common,statusEffect_set); |
| 70 | }; |
| 71 | }; |
| 72 | }; |
| 73 | if ((getAnimSpeedCoef _unit) != 1) then { |
| 74 | if (GVAR(setAnimExclusions) isEqualTo []) then { |
| 75 | TRACE_1("reset",getAnimSpeedCoef _unit); |
| 76 | _unit setAnimSpeedCoef 1; |
| 77 | }; |
| 78 | }; |
| 79 | |
| 80 | if (_overexhausted) then { |
| 81 | [_unit, "forceWalk", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set); |
| 82 | } else { |
| 83 | if (isForcedWalk _unit && {_fatigue < 0.7}) then { |
| 84 | [_unit, "forceWalk", QUOTE(ADDON), false] call EFUNC(common,statusEffect_set); |
| 85 | } else { |
| 86 | if ((isSprintAllowed _unit) && {_fatigue > 0.7}) then { |
| 87 | [_unit, "blockSprint", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set); |
| 88 | } else { |
| 89 | if ((!isSprintAllowed _unit) && {_fatigue < 0.6}) then { |
| 90 | [_unit, "blockSprint", QUOTE(ADDON), false] call EFUNC(common,statusEffect_set); |
| 91 | }; |
| 92 | }; |
| 93 | }; |
| 94 | }; |
| 95 | |
| 96 | _unit setVariable [QGVAR(aimFatigue), _fatigue]; |
| 97 | |
| 98 | private _aimCoef = [missionNamespace, "ACE_setCustomAimCoef", "max"] call EFUNC(common,arithmeticGetResult); |
| 99 | _unit setCustomAimCoef _aimCoef; |
| 100 | </code></pre> |