Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mission - Rewrite Surrender function #662

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions addons/mission/functions/fnc_surrender.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* Arguments:
* 0: Group <GROUP>
* 1: Chance <NUMBER> (default: 5)
* 1: Surrender Chance <NUMBER> (default: 5)
* 2: Distance <NUMBER> (default: 400)
* 3: Rally Chance <NUMBER> (default: 0)
*
Expand All @@ -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];
};
};
}];
Expand Down