From 94b6a59a07a72aa757e25f49437f96ab99aa32b9 Mon Sep 17 00:00:00 2001 From: Mike-MF Date: Thu, 11 Jan 2024 14:17:01 +0000 Subject: [PATCH] Update Surrender function --- addons/mission/functions/fnc_surrender.sqf | 52 +++++++++++----------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/addons/mission/functions/fnc_surrender.sqf b/addons/mission/functions/fnc_surrender.sqf index 6d7f2dad..51222421 100644 --- a/addons/mission/functions/fnc_surrender.sqf +++ b/addons/mission/functions/fnc_surrender.sqf @@ -7,7 +7,7 @@ * * Arguments: * 0: Group - * 1: Chance (default: 5) + * 1: Surrender Chance (default: 5) * 2: Distance (default: 400) * 3: Rally Chance (default: 0) * @@ -18,37 +18,37 @@ * [My_Group, 50] call MFUNC(surrender) */ -params ["_group", ["_chance", 5], ["_distance", 400], ["_rally", 0]]; +params ["_group", ["_surrenderChance", 5], ["_minimumDistance", 400], ["_rallyChance", 0]]; -_group setVariable [QGVAR(surrenderParams), [_chance, _distance, _rally], true]; +_group setVariable [QGVAR(surrenderParams), [_surrenderChance, _minimumDistance, _rallyChance], true]; { _x addEventHandler ["Suppressed", { params ["_unit", "", "_shooter"]; - (group _unit getVariable [QGVAR(surrenderParams), 0]) params ["_chance", "_distance", "_rally"]; - private _randomChance = round random 100; - private _rallyChance = round random 100; - - // Distance checks - private _distanceCheck = _unit distance2d _shooter; - - if (_distanceCheck <= _distance) then { - // If the random number is lower than the chance of surrender it passes. - if (_randomChance < _chance) then { - ["ACE_captives_setSurrendered", [_unit, true], _unit] call CBA_fnc_targetEvent; - - // If units are going to Rally don't remove EH. - if (_rallyChance >= _rally) then { - _unit removeEventHandler [_thisEvent, _thisEventHandler]; - }; - - if (_rallyChance < _rally) then { - [{ - params ["_unit"]; - ["ACE_captives_setSurrendered", [_unit, false], _unit] call CBA_fnc_targetEvent; - }, [_unit], (random 110) + 10] call CBA_fnc_waitAndExecute; - }; + (group _unit getVariable [QGVAR(surrenderParams), 0]) params ["_surrenderChance", "_minimumDistance", "_rallyChance"]; + + // Distance Check, no point continuing if distance has failed. + private _distanceCheck = (_unit distance2d _shooter) > _minimumDistance; + if (!_distanceCheck) exitWith {}; + + // % chance of surrendering and rallying. + private _willSurrender = random 100 < _surrenderChance; + private _willRally = random 100 < _rallyChance; + + if (_willSurrender) then { + ["ACE_captives_setSurrendered", [_unit, true], _unit] call CBA_fnc_targetEvent; + ["ocap_customEvent", ["generalEvent", format ["%1 has Surrendered!", name _unit]]] call CBA_fnc_serverEvent; + + // If unit is going to rally, delay and un-surrender, else remove eventhandler. + if (_willRally) then { + [{ + params ["_unit"]; + ["ACE_captives_setSurrendered", [_unit, false], _unit] call CBA_fnc_targetEvent; + ["ocap_customEvent", ["generalEvent", format ["%1 has Rallied!", name _unit]]] call CBA_fnc_serverEvent; + }, [_unit], (random 110) + 10] call CBA_fnc_waitAndExecute; + } else { + _unit removeEventHandler [_thisEvent, _thisEventHandler]; }; }; }];