Skip to content

Commit 7104392

Browse files
authored
Medical - Add hooks for (de)serializing medical state (#11255)
1 parent bca6869 commit 7104392

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

addons/medical/functions/fnc_deserializeState.sqf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,6 @@ if (_currentState in ["Unconscious", "CardiacArrest"] && {_targetState in ["Defa
128128
// Manually activate if non-defaults are present
129129
[_unit] call EFUNC(medical_engine,checkForMedicalActivity);
130130

131+
[QGVAR(deserialize), [_unit, _state]] call CBA_fnc_localEvent;
132+
131133
_state call CBA_fnc_deleteNamespace;

addons/medical/functions/fnc_serializeState.sqf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ _state setVariable [VAR_MEDICATIONS, _medications];
6060
private _currentState = [_unit, GVAR(STATE_MACHINE)] call CBA_statemachine_fnc_getCurrentState;
6161
_state setVariable [QGVAR(statemachineState), _currentState];
6262

63+
[QGVAR(serialize), [_unit, _state]] call CBA_fnc_localEvent;
64+
6365
// Serialize & return
6466
private _json = [_state] call CBA_fnc_encodeJSON;
6567
_state call CBA_fnc_deleteNamespace;

docs/wiki/framework/medical-framework.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,28 @@ ace_medical_const_medicalActivity = true;
265265
unit setVariable ["ace_medical_medicalActivity", true]
266266
```
267267
Once medical activity has been enabled, you can't disable it. In other words: if you execute `unit setVariable ["ace_medical_medicalActivity", true]`, you can't disable medical activity for that specific AI anymore. If you run `ace_medical_const_medicalActivity = true;`, you can no longer set it to `false` and all AI will have their medical activity enabled.
268+
269+
## 6. Persisting medical state between missions
270+
271+
A unit's medical state can be saved to JSON by calling `ace_medical_fnc_serializeState`. This can then be persisted in `profileNamespace` or your preferred flavor of persistence:
272+
```sqf
273+
private _state = player call ace_medical_fnc_serializeState;
274+
275+
profileNamespace setVariable ["MyPlayerMedicalState", _state];
276+
saveProfileNamespace;
277+
```
278+
279+
After a mission restart, `ace_medical_fnc_deserializeState` can be called:
280+
```sqf
281+
private _state = profileNamespace getVariable ["MyPlayerMedicalState", ""];
282+
283+
[player, _state] call ace_medical_deserializeState;
284+
```
285+
286+
## 6.1 Extending with custom handling
287+
288+
You can save additional data or add custom handling by hooking into the events:
289+
| Event Name | Params | Description |
290+
| ---------- | ------ | ----------- |
291+
| ace_medical_serializeState | Unit, Namespace | Raised locally after ACE Medical's serialization has taken place |
292+
| ace_medical_deserializeState | Unit, Namepsace | Raised locally after ACE Medical's deserialization has taken place |

0 commit comments

Comments
 (0)