Skip to content

Commit

Permalink
Chemical - Fix - Chemical Detector (#356)
Browse files Browse the repository at this point in the history
**When merged this pull request will:**
Fix the Chemical Detector

### Tested in:
- Singleplayer
- Multiplayer (local + ds) + jip

### IMPORTANT

- [Development Guidelines](https://ace3.acemod.org/wiki/development/)
are read, understood and applied.
- Title of this PR uses our standard template `Component -
Add|Fix|Improve|Change|Make|Remove {changes}`.
  • Loading branch information
AtrixZockt authored Jun 25, 2023
1 parent f09d941 commit 974c149
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 65 deletions.
1 change: 1 addition & 0 deletions addons/chemical/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[QGVAR(gasCheck_local), LINKFUNC(gasCheckLocal)] call CBA_fnc_addEventHandler;
[QGVAR(gasCheck_ai), LINKFUNC(gasAI)] call CBA_fnc_addEventHandler;
[QGVAR(afterWait), LINKFUNC(afterWait)] call CBA_fnc_addEventHandler;
[QGVAR(enteredPoisonEvent), LINKFUNC(chemDetector)] call CBA_fnc_addEventHandler;

//Mortar Events
["Mortar_01_base_F", "fired", {call FUNC(handleFired)}] call CBA_fnc_addClassEventHandler;
Expand Down
3 changes: 1 addition & 2 deletions addons/chemical/functions/fnc_afterWait.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* NONE
*
* Example:
* [player, logic, "Toxic", 50] call kat_chemical_fnc_gasChecklocal;
* [player, logic, "Toxic", 50] call kat_chemical_fnc_afterWait;
*
* Public: No
*/
Expand Down Expand Up @@ -83,7 +83,6 @@ if ((goggles _unit) in (missionNamespace getVariable [QGVAR(availGasmaskList), [
] call CBA_fnc_addPerFrameHandler;
} else {
if (_unit getVariable [QGVAR(enteredPoison), false]) then {
systemChat str _gastype;
_unit setVariable [QGVAR(poisonType), _gastype, true];
switch (_gastype) do {
case "Toxic": {
Expand Down
80 changes: 36 additions & 44 deletions addons/chemical/functions/fnc_chemDetector.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,46 @@
*/
params ["_unit"];

"KAT_CHEM_DETECTOR" cutRsc ["RscWeaponChemicalDetector", "PLAIN", 1, false];
private _ui = GETUVAR(RscWeaponChemicalDetector,displayNull);
private _obj = _ui displayCtrl 101;

if(!(_unit getVariable [QGVAR(enteredPoison),false])) then {
_obj ctrlAnimateModel ["Threat_Level_Source", 0, true];
};

[
{
params["_args", "_pfhHandler"];
_args params ["_unit"];

"KAT_CHEM_DETECTOR" cutRsc ["RscWeaponChemicalDetector", "PLAIN", 1, false];
private _ui = GETUVAR(RscWeaponChemicalDetector,displayNull);
private _obj = _ui displayCtrl 101;

if ("ChemicalDetector_01_watch_F" in (assigneditems _unit)) then
{
params["_unit"];
_unit getVariable [QGVAR(enteredPoison), false]
},
{
params["_unit", "_obj"];
[
{
params["_args", "_pfhHandler"];
_args params ["_unit", "_obj"];
private _percent = _unit getVariable [QGVAR(gasPercentage),0];
private _thread = parseNumber (_percent toFixed 1);
if (_thread < 0) then { _thread = 0};
if (_thread > 1) then { _thread = 1};
_obj ctrlAnimateModel ["Threat_Level_Source", _thread, true];
private _percent = _unit getVariable [QGVAR(gasPercentage),0];
private _thread = parseNumber (_percent toFixed 1);
if (_thread < 0) then { _thread = 0};
if (_thread > 1) then { _thread = 1};
_obj ctrlAnimateModel ["Threat_Level_Source", _thread, true];
};

if (!(_unit getVariable[QGVAR(enteredPoison),false])) exitWith {

_obj ctrlAnimateModel ["Threat_Level_Source", 0, true];

[_pfhHandler] call CBA_fnc_removePerFrameHandler;
};
},
1, [_unit]] call CBA_fnc_addPerFramehandler;

if (!("ChemicalDetector_01_watch_F" in (assigneditems _unit)) || !(_unit getVariable[QGVAR(enteredPoison),false])) exitWith {
[_pfhHandler] call CBA_fnc_removePerFrameHandler;
[_unit] call FUNC(chemDetector);
};
},
1, [_unit, _obj]] call CBA_fnc_addPerFramehandler;
[
{
params["_args", "_pfhHandler"];
_args params ["_unit"];

if (_unit getVariable [QGVAR(chemDetectorState), false] && _unit getVariable [QGVAR(gasPercentage), 0] >= 0.1 && "ChemicalDetector_01_watch_F" in (assigneditems _unit)) then {
playSound3D [QPATHTOF(audio\chemDetector.ogg), _unit, false, getPosASL _unit, 4, 1, 10];
};
[
{
params["_args", "_pfhHandler"];
_args params ["_unit"];

if (!("ChemicalDetector_01_watch_F" in (assigneditems _unit)) || !(_unit getVariable[QGVAR(enteredPoison),false])) exitWith {
[_pfhHandler] call CBA_fnc_removePerFrameHandler;
};
if (_unit getVariable [QGVAR(chemDetectorState), false] && _unit getVariable [QGVAR(gasPercentage), 0] >= 0.1 && "ChemicalDetector_01_watch_F" in (assigneditems _unit)) then {
playSound3D [QPATHTOF(audio\chemDetector.ogg), _unit, false, getPosASL _unit, 4, 1, 10];
};

},
6, [_unit]] call CBA_fnc_addPerFramehandler;
},
[_unit, _obj]
] call CBA_fnc_waitUntilAndExecute;
if (!(_unit getVariable[QGVAR(enteredPoison),false])) exitWith {
[_pfhHandler] call CBA_fnc_removePerFrameHandler;
};

},
6, [_unit]] call CBA_fnc_addPerFramehandler;
1 change: 1 addition & 0 deletions addons/chemical/functions/fnc_gasCheckLocal.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ if (!isDamageAllowed _unit) exitWith {
_pos = _logic getVariable [QGVAR(gas_pos), [0, 0, 0]];
if (_unit distance _pos <= _radius_max && !(_unit getVariable [QGVAR(enteredPoison), false]) && !(_unit getVariable ["ACE_isUnconscious", false])) then {
_unit setVariable [QGVAR(enteredPoison), true, true];
[QGVAR(enteredPoisonEvent), [_unit], _unit] call CBA_fnc_targetEvent;
_unit setVariable [QGVAR(Poisen_logic), _logic, true];
private _timeEntered = CBA_missiontime;

Expand Down
25 changes: 6 additions & 19 deletions addons/chemical/functions/fnc_init.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ params ["_unit", ["_isRespawn", true]];

if (!local _unit) exitWith {};

if (hasinterface) then {
[_unit] call FUNC(coughing);
[_unit] call FUNC(handleGasMaskDur);
[_unit] spawn FUNC(chemDetector);
[_unit] spawn FUNC(breathing);

_unit setVariable [QGVAR(timeleft), missionNamespace getVariable [QGVAR(infectionTime), 60], true];
_unit setVariable [QGVAR(enteredPoison), false, true];
_unit setVariable [QGVAR(gasmask_durability), 10, true];
_unit setVariable [QGVAR(gasmask_durability_reset), false, true];
_unit setVariable [QGVAR(chemDetectorState), true , true];
_unit setVariable [QGVAR(airPoisoning), false, true];
_unit setVariable [QGVAR(CS), false, true];

[_unit] call FUNC(coughing);
[_unit] call FUNC(handleGasMaskDur);
[_unit] call FUNC(breathing);

[{
params ["_args", "_pfhID"];
Expand All @@ -44,16 +44,3 @@ if (hasinterface) then {
};
};
}, 2, _unit]call CBA_fnc_addPerFrameHandler;

[{
params ["_args", "_pfhID"];
_args params ["_unit"];

"KAT_CHEM_DETECTOR" cutRsc ["RscWeaponChemicalDetector", "PLAIN", 1, false];
private _ui = uiNamespace getVariable "RscWeaponChemicalDetector";
private _obj = _ui displayCtrl 101;
if (!(_unit getVariable[QGVAR(enteredPoison), false])) then {
_obj ctrlAnimatemodel ["Threat_Level_Source", 0, true];
};
}, 2, [_unit]]call CBA_fnc_addPerFrameHandler;
};

0 comments on commit 974c149

Please sign in to comment.