From a224f8de00b1d9f57f85053f0c30c163a4d85252 Mon Sep 17 00:00:00 2001 From: Ravenger2709 Date: Tue, 17 Sep 2024 12:48:32 +0300 Subject: [PATCH 01/15] Added DMS_fnc_TargetsKilledPercent function, to check alive bots and if count <= value in DMS_AI_KillPercent - go nect to playerNear condition and finish mission Changed bandit.sqf mission to demonstrate function working. Change DMS_fnc_MissionSuccessState function to work with new condition. --- .../addons/a3_dms/missions/bandit/bandits.sqf | 2 +- .../a3_dms/scripts/fn_MissionSuccessState.sqf | 6 +-- .../scripts/fn_TargetsKilledPercent.sqf | 41 +++++++++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 @ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf diff --git a/@ExileServer/addons/a3_dms/missions/bandit/bandits.sqf b/@ExileServer/addons/a3_dms/missions/bandit/bandits.sqf index 2757554..d19f8fc 100644 --- a/@ExileServer/addons/a3_dms/missions/bandit/bandits.sqf +++ b/@ExileServer/addons/a3_dms/missions/bandit/bandits.sqf @@ -139,7 +139,7 @@ _added = _pos, [ [ - "kill", + "killpercent", _group ], [ diff --git a/@ExileServer/addons/a3_dms/scripts/fn_MissionSuccessState.sqf b/@ExileServer/addons/a3_dms/scripts/fn_MissionSuccessState.sqf index c0c57d0..1f3a8b2 100644 --- a/@ExileServer/addons/a3_dms/scripts/fn_MissionSuccessState.sqf +++ b/@ExileServer/addons/a3_dms/scripts/fn_MissionSuccessState.sqf @@ -55,12 +55,12 @@ private _exit = false; { _success = _completionArgs call DMS_fnc_TargetsKilled; }; - /* + case "killpercent": { - _success = _completionArgs call DMS_fnc_TargetsKilledPercent;//<---TODO + _success = _completionArgs call DMS_fnc_TargetsKilledPercent; }; - */ + case "playernear": { _success = _completionArgs call DMS_fnc_IsPlayerNearby; diff --git a/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf b/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf new file mode 100644 index 0000000..c6e642a --- /dev/null +++ b/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf @@ -0,0 +1,41 @@ +/* + DMS_fnc_TargetsKilledPercent + Created by Ravenger2709 + + Usage: + [ + _unit, + _group, + _object + ] call DMS_fnc_TargetsKilledPercent; + + Will accept non-array argument of group, unit, or object. +*/ + +if (_this isEqualTo []) exitWith +{ + diag_log "DMS ERROR :: Calling DMS_TargetsKilled with empty array!"; +}; + +private _killedpercent = false; + +// Get the kill percent value from config +private _killPercent = DMS_AI_KillPercent; + +// Get all living AI units +private _allUnits = _this call DMS_fnc_GetAllUnits; +private _totalUnits = count _allUnits; + +// Calculate the number of units that need to be killed +private _unitsToKill = ceil((_killPercent / 100) * _totalUnits); + +// Check if the number of living units is less than or equal to the required kill percent +if (_totalUnits <= _unitsToKill) then +{ + _killedpercent = true; +}; + +// Log the result using DMS_fnc_DebugLog +[_killedpercent, "Targets Killed Percent"] call DMS_fnc_DebugLog; + +_killedpercent; From 4cd86d0b2f79d88d52d780f38d58def123cf17c0 Mon Sep 17 00:00:00 2001 From: Ravenger2709 Date: Tue, 17 Sep 2024 12:57:03 +0300 Subject: [PATCH 02/15] FIX - Added TargetsKilledPercent class to config.cpp --- @ExileServer/addons/a3_dms/config.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/@ExileServer/addons/a3_dms/config.cpp b/@ExileServer/addons/a3_dms/config.cpp index cad366c..adabe6b 100644 --- a/@ExileServer/addons/a3_dms/config.cpp +++ b/@ExileServer/addons/a3_dms/config.cpp @@ -90,6 +90,7 @@ class CfgFunctions class SpawnStaticMission {}; class SubArr {}; class TargetsKilled {}; + class TargetsKilledPercent {}; }; }; }; From fc0c835a27217cf4c96f63c3d793b7b5f5560bc4 Mon Sep 17 00:00:00 2001 From: Ravenger2709 Date: Tue, 17 Sep 2024 15:37:11 +0300 Subject: [PATCH 03/15] delete debug logging for new function --- @ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf | 3 --- 1 file changed, 3 deletions(-) diff --git a/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf b/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf index c6e642a..46c9c88 100644 --- a/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf +++ b/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf @@ -35,7 +35,4 @@ if (_totalUnits <= _unitsToKill) then _killedpercent = true; }; -// Log the result using DMS_fnc_DebugLog -[_killedpercent, "Targets Killed Percent"] call DMS_fnc_DebugLog; - _killedpercent; From f39bf0d88d8495425e184960b0091d0decae7183 Mon Sep 17 00:00:00 2001 From: Ravenger2709 Date: Tue, 17 Sep 2024 18:26:16 +0300 Subject: [PATCH 04/15] changed logic on count living units and save it count on mission start --- .../a3_dms/scripts/fn_TargetsKilledPercent.sqf | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf b/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf index 46c9c88..6061ea8 100644 --- a/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf +++ b/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf @@ -22,15 +22,21 @@ private _killedpercent = false; // Get the kill percent value from config private _killPercent = DMS_AI_KillPercent; +// Static variable to store initial unit count +if (isNil "DMS_initialUnitCount") then +{ + DMS_initialUnitCount = count (_this call DMS_fnc_GetAllUnits); +}; + +// Calculate the acceptable number of remaining units based on initial unit count +private _unitsThreshold = floor((100 - _killPercent) * DMS_initialUnitCount / 100); + // Get all living AI units private _allUnits = _this call DMS_fnc_GetAllUnits; private _totalUnits = count _allUnits; -// Calculate the number of units that need to be killed -private _unitsToKill = ceil((_killPercent / 100) * _totalUnits); - -// Check if the number of living units is less than or equal to the required kill percent -if (_totalUnits <= _unitsToKill) then +// Check if the number of living units is less than or equal to the threshold +if (_totalUnits <= _unitsThreshold) then { _killedpercent = true; }; From c500a9194f35ac4412a2e47f0306ad6ce0589582 Mon Sep 17 00:00:00 2001 From: Ravenger2709 Date: Tue, 17 Sep 2024 19:26:53 +0300 Subject: [PATCH 05/15] have not idea now ho to fix it --- .../a3_dms/scripts/fn_MissionSuccessState.sqf | 145 +++++++++--------- 1 file changed, 71 insertions(+), 74 deletions(-) diff --git a/@ExileServer/addons/a3_dms/scripts/fn_MissionSuccessState.sqf b/@ExileServer/addons/a3_dms/scripts/fn_MissionSuccessState.sqf index 1f3a8b2..8358f13 100644 --- a/@ExileServer/addons/a3_dms/scripts/fn_MissionSuccessState.sqf +++ b/@ExileServer/addons/a3_dms/scripts/fn_MissionSuccessState.sqf @@ -1,95 +1,92 @@ /* - DMS_fnc_MissionSuccessState - Created by eraser1 + DMS_fnc_MissionSuccessState + Created by eraser1 - Usage: - [ - [_completionType1,_completionArgs1,_isAbsoluteCondition], - [_completionType2,_completionArgs2,_isAbsoluteCondition], - ... - [_completionTypeN,_completionArgsN,_isAbsoluteCondition] - ] call DMS_fnc_MissionSuccessState; + Usage: + [ + [_completionType1,_completionArgs1,_isAbsoluteCondition], + [_completionType2,_completionArgs2,_isAbsoluteCondition], + ... + [_completionTypeN,_completionArgsN,_isAbsoluteCondition] + ] call DMS_fnc_MissionSuccessState; */ if !(_this isEqualType []) exitWith { - diag_log format ["DMS ERROR :: DMS_fnc_MissionSuccessState called with invalid parameter: %1",_this]; + diag_log format ["DMS ERROR :: DMS_fnc_MissionSuccessState called with invalid parameter: %1",_this]; }; private _success = true; private _exit = false; { - if (_exit) exitWith {}; + if (_exit) exitWith {}; - try - { - if !(_x params - [ - "_completionType", - "_completionArgs" - ]) - then - { - diag_log format ["DMS ERROR :: DMS_fnc_MissionSuccessState has invalid parameters in: %1",_x]; - throw "ERROR"; - }; + try + { + if !(_x params + [ + "_completionType", + "_completionArgs" + ]) + then + { + diag_log format ["DMS ERROR :: DMS_fnc_MissionSuccessState has invalid parameters in: %1",_x]; + throw "ERROR"; + }; + private _absoluteWinCondition = _x param [2, false, [true]]; - private _absoluteWinCondition = _x param [2, false, [true]]; + if (!_success && {!_absoluteWinCondition}) then + { + throw format ["Skipping completion check for condition |%1|; Condition is not absolute and a previous condition has already been failed.",_x]; + }; - if (!_success && {!_absoluteWinCondition}) then - { - throw format ["Skipping completion check for condition |%1|; Condition is not absolute and a previous condition has already been failed.",_x]; - }; + if (DMS_DEBUG) then + { + (format ["MissionSuccessState :: Checking completion type ""%1"" with argument |%2|. Absolute: %3",_completionType,_completionArgs,_absoluteWinCondition]) call DMS_fnc_DebugLog; + }; + switch (toLower _completionType) do + { + case "kill": + { + _success = _success && (_completionArgs call DMS_fnc_TargetsKilled); + }; + + case "killpercent": + { + _success = _success && (_completionArgs call DMS_fnc_TargetsKilledPercent); + }; + + case "playernear": + { + _success = _success && (_completionArgs call DMS_fnc_IsPlayerNearby); + }; + case "external": // This is a special completion type. It is intended to be a flag for people who want to control mission completion using _onMonitorStart and _onMonitorEnd through array manipulation. You probably don't want to use this unless you know what you're doing. + { + _success = _success && _completionArgs; + }; + default + { + diag_log format ["DMS ERROR :: Invalid completion type (%1) with args: %2",_completionType,_completionArgs]; + throw "ERROR"; + }; + }; - if (DMS_DEBUG) then - { - (format ["MissionSuccessState :: Checking completion type ""%1"" with argument |%2|. Absolute: %3",_completionType,_completionArgs,_absoluteWinCondition]) call DMS_fnc_DebugLog; - }; - - switch (toLower _completionType) do - { - case "kill": - { - _success = _completionArgs call DMS_fnc_TargetsKilled; - }; - - case "killpercent": - { - _success = _completionArgs call DMS_fnc_TargetsKilledPercent; - }; - - case "playernear": - { - _success = _completionArgs call DMS_fnc_IsPlayerNearby; - }; - case "external": // This is a special completion type. It is intended to be a flag for people who want to control mission completion using _onMonitorStart and _onMonitorEnd through array manipulation. You probably don't want to use this unless you know what you're doing. - { - _success = _completionArgs; - }; - default - { - diag_log format ["DMS ERROR :: Invalid completion type (%1) with args: %2",_completionType,_completionArgs]; - throw "ERROR"; - }; - }; - - - if (_success && {_absoluteWinCondition}) then - { - _exit = true; - throw format ["Mission completed because of absolute win condition: %1",_x]; - }; - } - catch - { - if (DMS_DEBUG) then - { - (format ["MissionSuccessState :: %1",_exception]) call DMS_fnc_DebugLog; - }; - }; + if (_success && {_absoluteWinCondition}) then + { + _exit = true; + throw format ["Mission completed because of absolute win condition: %1",_x]; + }; + } + catch + { + if (DMS_DEBUG) then + { + (format ["MissionSuccessState :: %1",_exception]) call DMS_fnc_DebugLog; + }; + }; } forEach _this; _success; From 621e4bdc17ef4e2170b0d4c70fac9f6b5ec565a5 Mon Sep 17 00:00:00 2001 From: Ravenger2709 Date: Tue, 17 Sep 2024 19:38:44 +0300 Subject: [PATCH 06/15] forgotten commit --- .../a3_dms/scripts/fn_MissionSuccessState.sqf | 2 ++ .../scripts/fn_TargetsKilledPercent.sqf | 29 +++++++++---------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/@ExileServer/addons/a3_dms/scripts/fn_MissionSuccessState.sqf b/@ExileServer/addons/a3_dms/scripts/fn_MissionSuccessState.sqf index 8358f13..e225fff 100644 --- a/@ExileServer/addons/a3_dms/scripts/fn_MissionSuccessState.sqf +++ b/@ExileServer/addons/a3_dms/scripts/fn_MissionSuccessState.sqf @@ -35,6 +35,8 @@ private _exit = false; throw "ERROR"; }; + private _completionType = _x select 0; + private _completionArgs = _x select 1; private _absoluteWinCondition = _x param [2, false, [true]]; if (!_success && {!_absoluteWinCondition}) then diff --git a/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf b/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf index 6061ea8..9adfe25 100644 --- a/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf +++ b/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf @@ -6,37 +6,36 @@ [ _unit, _group, - _object + _object, + _threshold ] call DMS_fnc_TargetsKilledPercent; Will accept non-array argument of group, unit, or object. */ -if (_this isEqualTo []) exitWith +if (!(_this isEqualType [])) exitWith { - diag_log "DMS ERROR :: Calling DMS_TargetsKilled with empty array!"; + diag_log "DMS ERROR :: Calling DMS_TargetsKilled with non-array argument!"; }; -private _killedpercent = false; - -// Get the kill percent value from config -private _killPercent = DMS_AI_KillPercent; - -// Static variable to store initial unit count -if (isNil "DMS_initialUnitCount") then +if (count _this < 4) exitWith { - DMS_initialUnitCount = count (_this call DMS_fnc_GetAllUnits); + diag_log "DMS ERROR :: Calling DMS_TargetsKilled with insufficient parameters!"; }; -// Calculate the acceptable number of remaining units based on initial unit count -private _unitsThreshold = floor((100 - _killPercent) * DMS_initialUnitCount / 100); +private _unit = _this select 0; +private _group = _this select 1; +private _object = _this select 2; +private _threshold = _this select 3; + +private _killedpercent = false; // Get all living AI units -private _allUnits = _this call DMS_fnc_GetAllUnits; +private _allUnits = [_unit, _group, _object] call DMS_fnc_GetAllUnits; private _totalUnits = count _allUnits; // Check if the number of living units is less than or equal to the threshold -if (_totalUnits <= _unitsThreshold) then +if (_totalUnits <= _threshold) then { _killedpercent = true; }; From 9acced3985bb4686a4c0dd3417331d3b40ced8fc Mon Sep 17 00:00:00 2001 From: Ravenger2709 Date: Tue, 17 Sep 2024 20:49:00 +0300 Subject: [PATCH 07/15] another try --- .../addons/a3_dms/scripts/fn_MissionSuccessState.sqf | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/@ExileServer/addons/a3_dms/scripts/fn_MissionSuccessState.sqf b/@ExileServer/addons/a3_dms/scripts/fn_MissionSuccessState.sqf index e225fff..dbec8f4 100644 --- a/@ExileServer/addons/a3_dms/scripts/fn_MissionSuccessState.sqf +++ b/@ExileServer/addons/a3_dms/scripts/fn_MissionSuccessState.sqf @@ -35,8 +35,6 @@ private _exit = false; throw "ERROR"; }; - private _completionType = _x select 0; - private _completionArgs = _x select 1; private _absoluteWinCondition = _x param [2, false, [true]]; if (!_success && {!_absoluteWinCondition}) then @@ -53,21 +51,21 @@ private _exit = false; { case "kill": { - _success = _success && (_completionArgs call DMS_fnc_TargetsKilled); + _success = _completionArgs call DMS_fnc_TargetsKilled; }; case "killpercent": { - _success = _success && (_completionArgs call DMS_fnc_TargetsKilledPercent); + _success = _completionArgs call DMS_fnc_TargetsKilledPercent; }; case "playernear": { - _success = _success && (_completionArgs call DMS_fnc_IsPlayerNearby); + _success = _completionArgs call DMS_fnc_IsPlayerNearby; }; - case "external": // This is a special completion type. It is intended to be a flag for people who want to control mission completion using _onMonitorStart and _onMonitorEnd through array manipulation. You probably don't want to use this unless you know what you're doing. + case "external": { - _success = _success && _completionArgs; + _success = _completionArgs; }; default { From 0b27f36ab5b461efa1628d321872b901a55b043e Mon Sep 17 00:00:00 2001 From: Ravenger2709 Date: Tue, 17 Sep 2024 20:56:25 +0300 Subject: [PATCH 08/15] and another try... --- .../addons/a3_dms/scripts/fn_MissionSuccessState.sqf | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/@ExileServer/addons/a3_dms/scripts/fn_MissionSuccessState.sqf b/@ExileServer/addons/a3_dms/scripts/fn_MissionSuccessState.sqf index dbec8f4..e225fff 100644 --- a/@ExileServer/addons/a3_dms/scripts/fn_MissionSuccessState.sqf +++ b/@ExileServer/addons/a3_dms/scripts/fn_MissionSuccessState.sqf @@ -35,6 +35,8 @@ private _exit = false; throw "ERROR"; }; + private _completionType = _x select 0; + private _completionArgs = _x select 1; private _absoluteWinCondition = _x param [2, false, [true]]; if (!_success && {!_absoluteWinCondition}) then @@ -51,21 +53,21 @@ private _exit = false; { case "kill": { - _success = _completionArgs call DMS_fnc_TargetsKilled; + _success = _success && (_completionArgs call DMS_fnc_TargetsKilled); }; case "killpercent": { - _success = _completionArgs call DMS_fnc_TargetsKilledPercent; + _success = _success && (_completionArgs call DMS_fnc_TargetsKilledPercent); }; case "playernear": { - _success = _completionArgs call DMS_fnc_IsPlayerNearby; + _success = _success && (_completionArgs call DMS_fnc_IsPlayerNearby); }; - case "external": + case "external": // This is a special completion type. It is intended to be a flag for people who want to control mission completion using _onMonitorStart and _onMonitorEnd through array manipulation. You probably don't want to use this unless you know what you're doing. { - _success = _completionArgs; + _success = _success && _completionArgs; }; default { From d6880f15f444bee1ec9552bad671396677939045 Mon Sep 17 00:00:00 2001 From: Ravenger2709 Date: Tue, 17 Sep 2024 21:18:18 +0300 Subject: [PATCH 09/15] lost variable --- .../a3_dms/scripts/fn_TargetsKilledPercent.sqf | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf b/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf index 9adfe25..341fef1 100644 --- a/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf +++ b/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf @@ -30,12 +30,18 @@ private _threshold = _this select 3; private _killedpercent = false; -// Get all living AI units +// Получение значения DMS_AI_KillPercent из config.sqf +private _killPercent = DMS_AI_KillPercent; + +// Получение всех живых AI юнитов private _allUnits = [_unit, _group, _object] call DMS_fnc_GetAllUnits; private _totalUnits = count _allUnits; -// Check if the number of living units is less than or equal to the threshold -if (_totalUnits <= _threshold) then +// Подсчет убитых юнитов +private _killedUnits = _totalUnits - {alive _x} count _allUnits; + +// Проверка, если процент убитых юнитов больше или равен DMS_AI_KillPercent +if ((_killedUnits / _totalUnits) * 100 >= _killPercent) then { _killedpercent = true; }; From 8781e12b239a755ead904d9ecb912b8cb1ab782d Mon Sep 17 00:00:00 2001 From: Ravenger2709 Date: Wed, 18 Sep 2024 10:41:10 +0300 Subject: [PATCH 10/15] Changed global vars to local, changed DMS_fnc_MissionSuccessState to working with more args in killpercent case, now we take initial count of bots on mission then mission start --- .../addons/a3_dms/missions/bandit/bandits.sqf | 4 +- .../a3_dms/scripts/fn_MissionSuccessState.sqf | 79 +++++++------------ .../scripts/fn_TargetsKilledPercent.sqf | 47 +++++------ 3 files changed, 56 insertions(+), 74 deletions(-) diff --git a/@ExileServer/addons/a3_dms/missions/bandit/bandits.sqf b/@ExileServer/addons/a3_dms/missions/bandit/bandits.sqf index d19f8fc..6777732 100644 --- a/@ExileServer/addons/a3_dms/missions/bandit/bandits.sqf +++ b/@ExileServer/addons/a3_dms/missions/bandit/bandits.sqf @@ -133,6 +133,8 @@ _markers = // Record time here (for logging purposes, otherwise you could just put "diag_tickTime" into the "DMS_AddMissionToMonitor" parameters directly) _time = diag_tickTime; +private _initialUnitCount = _AICount; //Get inital count of bots then mission starts. It need only for "killpercent" condnition. Look for deatiled info in DMS_fnc_TargetsKilledPercent + // Parse and add mission info to missions monitor _added = [ @@ -140,7 +142,7 @@ _added = [ [ "killpercent", - _group + [_initialUnitCount, _group] ], [ "playerNear", diff --git a/@ExileServer/addons/a3_dms/scripts/fn_MissionSuccessState.sqf b/@ExileServer/addons/a3_dms/scripts/fn_MissionSuccessState.sqf index e225fff..8e5b9df 100644 --- a/@ExileServer/addons/a3_dms/scripts/fn_MissionSuccessState.sqf +++ b/@ExileServer/addons/a3_dms/scripts/fn_MissionSuccessState.sqf @@ -11,8 +11,7 @@ ] call DMS_fnc_MissionSuccessState; */ -if !(_this isEqualType []) exitWith -{ +if !(_this isEqualType []) exitWith { diag_log format ["DMS ERROR :: DMS_fnc_MissionSuccessState called with invalid parameter: %1",_this]; }; @@ -22,70 +21,50 @@ private _exit = false; { if (_exit) exitWith {}; - try - { - if !(_x params - [ - "_completionType", - "_completionArgs" - ]) - then - { + try { + if !(_x params ["_completionType", "_completionArgs"]) then { diag_log format ["DMS ERROR :: DMS_fnc_MissionSuccessState has invalid parameters in: %1",_x]; throw "ERROR"; }; - private _completionType = _x select 0; - private _completionArgs = _x select 1; private _absoluteWinCondition = _x param [2, false, [true]]; - if (!_success && {!_absoluteWinCondition}) then - { + if (!_success && {!_absoluteWinCondition}) then { throw format ["Skipping completion check for condition |%1|; Condition is not absolute and a previous condition has already been failed.",_x]; }; - if (DMS_DEBUG) then - { + if (DMS_DEBUG) then { (format ["MissionSuccessState :: Checking completion type ""%1"" with argument |%2|. Absolute: %3",_completionType,_completionArgs,_absoluteWinCondition]) call DMS_fnc_DebugLog; }; - switch (toLower _completionType) do - { - case "kill": - { - _success = _success && (_completionArgs call DMS_fnc_TargetsKilled); - }; - - case "killpercent": - { - _success = _success && (_completionArgs call DMS_fnc_TargetsKilledPercent); - }; - - case "playernear": - { - _success = _success && (_completionArgs call DMS_fnc_IsPlayerNearby); - }; - case "external": // This is a special completion type. It is intended to be a flag for people who want to control mission completion using _onMonitorStart and _onMonitorEnd through array manipulation. You probably don't want to use this unless you know what you're doing. - { - _success = _success && _completionArgs; - }; - default - { - diag_log format ["DMS ERROR :: Invalid completion type (%1) with args: %2",_completionType,_completionArgs]; - throw "ERROR"; - }; - }; + switch (toLower _completionType) do { + case "kill": { + _success = _completionArgs call DMS_fnc_TargetsKilled; + }; + case "killpercent": { + private _initialUnitCount = _completionArgs select 0; + private _args = _completionArgs select [1, count _completionArgs - 1]; //Look for bandit.sqf mission for "killpercent" condnition example. + _success = [_initialUnitCount, _args] call DMS_fnc_TargetsKilledPercent; + }; + case "playernear": { + _success = _completionArgs call DMS_fnc_IsPlayerNearby; + }; + case "external": { + _success = _completionArgs; + }; + default { + diag_log format ["DMS ERROR :: Invalid completion type (%1) with args: %2",_completionType,_completionArgs]; + throw "ERROR"; + }; + }; + - if (_success && {_absoluteWinCondition}) then - { + if (_success && {_absoluteWinCondition}) then { _exit = true; throw format ["Mission completed because of absolute win condition: %1",_x]; }; - } - catch - { - if (DMS_DEBUG) then - { + } catch { + if (DMS_DEBUG) then { (format ["MissionSuccessState :: %1",_exception]) call DMS_fnc_DebugLog; }; }; diff --git a/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf b/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf index 341fef1..8f1f1f3 100644 --- a/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf +++ b/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf @@ -4,46 +4,47 @@ Usage: [ + _initialUnitCount, _unit, _group, - _object, - _threshold + _object ] call DMS_fnc_TargetsKilledPercent; Will accept non-array argument of group, unit, or object. */ -if (!(_this isEqualType [])) exitWith -{ - diag_log "DMS ERROR :: Calling DMS_TargetsKilled with non-array argument!"; +if (_this isEqualTo []) exitWith { + diag_log "DMS ERROR :: Calling DMS_TargetsKilled with empty array!"; }; -if (count _this < 4) exitWith -{ - diag_log "DMS ERROR :: Calling DMS_TargetsKilled with insufficient parameters!"; -}; - -private _unit = _this select 0; -private _group = _this select 1; -private _object = _this select 2; -private _threshold = _this select 3; - +private _initialUnitCount = _this select 0; +private _args = _this select [1, count _this - 1]; private _killedpercent = false; -// Получение значения DMS_AI_KillPercent из config.sqf +// Get the kill percent value from config private _killPercent = DMS_AI_KillPercent; +diag_log format ["DMS DEBUG :: Kill percent value: %1", _killPercent]; +diag_log format ["DMS DEBUG :: Initial unit count: %1", _initialUnitCount]; + +// Calculate the acceptable number of killed units based on initial unit count +private _unitsThreshold = ceil(_killPercent * _initialUnitCount / 100); +diag_log format ["DMS DEBUG :: Units threshold (killed units): %1", _unitsThreshold]; -// Получение всех живых AI юнитов -private _allUnits = [_unit, _group, _object] call DMS_fnc_GetAllUnits; +// Get all living AI units +private _allUnits = _args call DMS_fnc_GetAllUnits; private _totalUnits = count _allUnits; +diag_log format ["DMS DEBUG :: Total living units: %1", _totalUnits]; -// Подсчет убитых юнитов -private _killedUnits = _totalUnits - {alive _x} count _allUnits; +// Calculate the number of killed units +private _killedUnits = _initialUnitCount - _totalUnits; +diag_log format ["DMS DEBUG :: Total killed units: %1", _killedUnits]; -// Проверка, если процент убитых юнитов больше или равен DMS_AI_KillPercent -if ((_killedUnits / _totalUnits) * 100 >= _killPercent) then -{ +// Check if the number of killed units is greater than or equal to the threshold +if (_killedUnits >= _unitsThreshold) then { _killedpercent = true; + diag_log "DMS DEBUG :: Kill percent condition met"; +} else { + diag_log "DMS DEBUG :: Kill percent condition not met"; }; _killedpercent; From 8c411554822b8607c8a4620deeb2224f389714fe Mon Sep 17 00:00:00 2001 From: Ravenger2709 Date: Wed, 18 Sep 2024 10:43:40 +0300 Subject: [PATCH 11/15] turn off debug messages --- .../a3_dms/scripts/fn_TargetsKilledPercent.sqf | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf b/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf index 8f1f1f3..20c3884 100644 --- a/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf +++ b/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf @@ -23,28 +23,28 @@ private _killedpercent = false; // Get the kill percent value from config private _killPercent = DMS_AI_KillPercent; -diag_log format ["DMS DEBUG :: Kill percent value: %1", _killPercent]; -diag_log format ["DMS DEBUG :: Initial unit count: %1", _initialUnitCount]; +//diag_log format ["DMS DEBUG :: Kill percent value: %1", _killPercent]; +//diag_log format ["DMS DEBUG :: Initial unit count: %1", _initialUnitCount]; // Calculate the acceptable number of killed units based on initial unit count private _unitsThreshold = ceil(_killPercent * _initialUnitCount / 100); -diag_log format ["DMS DEBUG :: Units threshold (killed units): %1", _unitsThreshold]; +//diag_log format ["DMS DEBUG :: Units threshold (killed units): %1", _unitsThreshold]; // Get all living AI units private _allUnits = _args call DMS_fnc_GetAllUnits; private _totalUnits = count _allUnits; -diag_log format ["DMS DEBUG :: Total living units: %1", _totalUnits]; +//diag_log format ["DMS DEBUG :: Total living units: %1", _totalUnits]; // Calculate the number of killed units private _killedUnits = _initialUnitCount - _totalUnits; -diag_log format ["DMS DEBUG :: Total killed units: %1", _killedUnits]; +//diag_log format ["DMS DEBUG :: Total killed units: %1", _killedUnits]; // Check if the number of killed units is greater than or equal to the threshold if (_killedUnits >= _unitsThreshold) then { _killedpercent = true; - diag_log "DMS DEBUG :: Kill percent condition met"; + //diag_log "DMS DEBUG :: Kill percent condition met"; } else { - diag_log "DMS DEBUG :: Kill percent condition not met"; + //diag_log "DMS DEBUG :: Kill percent condition not met"; }; _killedpercent; From fab3d7e771a0d8c79d1c1e96a4063d4c778ec058 Mon Sep 17 00:00:00 2001 From: Ravenger2709 Date: Wed, 18 Sep 2024 11:58:48 +0300 Subject: [PATCH 12/15] small fix for Total killed units --- .../a3_dms/scripts/fn_TargetsKilledPercent.sqf | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf b/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf index 20c3884..cbcb3d6 100644 --- a/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf +++ b/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf @@ -23,28 +23,28 @@ private _killedpercent = false; // Get the kill percent value from config private _killPercent = DMS_AI_KillPercent; -//diag_log format ["DMS DEBUG :: Kill percent value: %1", _killPercent]; -//diag_log format ["DMS DEBUG :: Initial unit count: %1", _initialUnitCount]; +diag_log format ["DMS DEBUG :: Kill percent value: %1", _killPercent]; +diag_log format ["DMS DEBUG :: Initial unit count: %1", _initialUnitCount]; // Calculate the acceptable number of killed units based on initial unit count private _unitsThreshold = ceil(_killPercent * _initialUnitCount / 100); -//diag_log format ["DMS DEBUG :: Units threshold (killed units): %1", _unitsThreshold]; +diag_log format ["DMS DEBUG :: Units threshold (killed units): %1", _unitsThreshold]; // Get all living AI units private _allUnits = _args call DMS_fnc_GetAllUnits; private _totalUnits = count _allUnits; -//diag_log format ["DMS DEBUG :: Total living units: %1", _totalUnits]; +diag_log format ["DMS DEBUG :: Total living units: %1", _totalUnits]; // Calculate the number of killed units -private _killedUnits = _initialUnitCount - _totalUnits; -//diag_log format ["DMS DEBUG :: Total killed units: %1", _killedUnits]; +private _killedUnits = if (_initialUnitCount - _totalUnits > 0) then {_initialUnitCount - _totalUnits} else {0}; +diag_log format ["DMS DEBUG :: Total killed units: %1", _killedUnits]; // Check if the number of killed units is greater than or equal to the threshold if (_killedUnits >= _unitsThreshold) then { _killedpercent = true; - //diag_log "DMS DEBUG :: Kill percent condition met"; + diag_log "DMS DEBUG :: Kill percent condition met"; } else { - //diag_log "DMS DEBUG :: Kill percent condition not met"; + diag_log "DMS DEBUG :: Kill percent condition not met"; }; _killedpercent; From f834f39d9e84ab657aee7ced41a69624f7d8ae40 Mon Sep 17 00:00:00 2001 From: Ravenger2709 Date: Wed, 18 Sep 2024 12:00:03 +0300 Subject: [PATCH 13/15] comment debug messages --- .../a3_dms/scripts/fn_TargetsKilledPercent.sqf | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf b/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf index cbcb3d6..7e86390 100644 --- a/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf +++ b/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf @@ -23,28 +23,28 @@ private _killedpercent = false; // Get the kill percent value from config private _killPercent = DMS_AI_KillPercent; -diag_log format ["DMS DEBUG :: Kill percent value: %1", _killPercent]; -diag_log format ["DMS DEBUG :: Initial unit count: %1", _initialUnitCount]; +//diag_log format ["DMS DEBUG :: Kill percent value: %1", _killPercent]; +//diag_log format ["DMS DEBUG :: Initial unit count: %1", _initialUnitCount]; // Calculate the acceptable number of killed units based on initial unit count private _unitsThreshold = ceil(_killPercent * _initialUnitCount / 100); -diag_log format ["DMS DEBUG :: Units threshold (killed units): %1", _unitsThreshold]; +//diag_log format ["DMS DEBUG :: Units threshold (killed units): %1", _unitsThreshold]; // Get all living AI units private _allUnits = _args call DMS_fnc_GetAllUnits; private _totalUnits = count _allUnits; -diag_log format ["DMS DEBUG :: Total living units: %1", _totalUnits]; +//diag_log format ["DMS DEBUG :: Total living units: %1", _totalUnits]; // Calculate the number of killed units private _killedUnits = if (_initialUnitCount - _totalUnits > 0) then {_initialUnitCount - _totalUnits} else {0}; -diag_log format ["DMS DEBUG :: Total killed units: %1", _killedUnits]; +//diag_log format ["DMS DEBUG :: Total killed units: %1", _killedUnits]; // Check if the number of killed units is greater than or equal to the threshold if (_killedUnits >= _unitsThreshold) then { _killedpercent = true; - diag_log "DMS DEBUG :: Kill percent condition met"; + //diag_log "DMS DEBUG :: Kill percent condition met"; } else { - diag_log "DMS DEBUG :: Kill percent condition not met"; + //diag_log "DMS DEBUG :: Kill percent condition not met"; }; _killedpercent; From 88314021f35a83d2eb9b51e6ffe8a3631bcdfc8b Mon Sep 17 00:00:00 2001 From: Ravenger2709 Date: Wed, 18 Sep 2024 16:23:26 +0300 Subject: [PATCH 14/15] now bots in turrets and vehicle counted too --- .../addons/a3_dms/missions/bandit/bandits.sqf | 2 +- .../addons/a3_dms/scripts/fn_GetAllUnits.sqf | 32 ++++++++++++------- .../scripts/fn_TargetsKilledPercent.sqf | 14 ++++---- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/@ExileServer/addons/a3_dms/missions/bandit/bandits.sqf b/@ExileServer/addons/a3_dms/missions/bandit/bandits.sqf index 6777732..3f1c3ab 100644 --- a/@ExileServer/addons/a3_dms/missions/bandit/bandits.sqf +++ b/@ExileServer/addons/a3_dms/missions/bandit/bandits.sqf @@ -133,7 +133,7 @@ _markers = // Record time here (for logging purposes, otherwise you could just put "diag_tickTime" into the "DMS_AddMissionToMonitor" parameters directly) _time = diag_tickTime; -private _initialUnitCount = _AICount; //Get inital count of bots then mission starts. It need only for "killpercent" condnition. Look for deatiled info in DMS_fnc_TargetsKilledPercent +private _initialUnitCount = count (_group call DMS_fnc_GetAllUnits); //Get inital count of bots then mission starts. It need only for "killpercent" condnition. Look for detailed info in DMS_fnc_TargetsKilledPercent // Parse and add mission info to missions monitor _added = diff --git a/@ExileServer/addons/a3_dms/scripts/fn_GetAllUnits.sqf b/@ExileServer/addons/a3_dms/scripts/fn_GetAllUnits.sqf index 61b648a..66bd27b 100644 --- a/@ExileServer/addons/a3_dms/scripts/fn_GetAllUnits.sqf +++ b/@ExileServer/addons/a3_dms/scripts/fn_GetAllUnits.sqf @@ -2,7 +2,6 @@ DMS_fnc_GetAllUnits Created by eraser1 - Usage: [ _unitOrGroupOrArray1, @@ -14,12 +13,14 @@ Returns all living units from a given array of groups or objects. */ -if !(_this isEqualType []) then -{ +if !(_this isEqualType []) then { _this = [_this]; }; private _units = []; +private _footUnits = []; +private _vehicleUnits = []; +private _staticUnits = []; { private _parameter = _x; @@ -35,10 +36,18 @@ private _units = []; case "OBJECT": { - [ - [], - [_parameter] - ] select (alive _parameter); + if (alive _parameter) then { + if (_parameter isKindOf "LandVehicle" || _parameter isKindOf "Air" || _parameter isKindOf "Ship") then { + _vehicleUnits append (crew _parameter select {alive _x}); + } else if (_parameter isKindOf "StaticWeapon") then { + _staticUnits append (crew _parameter select {alive _x}); + } else { + _footUnits pushBack _parameter; + }; + [_parameter]; + } else { + []; + }; }; case "GROUP": @@ -55,10 +64,11 @@ private _units = []; ); } forEach _this; -if (DMS_DEBUG) then -{ - (format ["GetAllUnits :: Input (%1) produced units: %2",_this,_units]) call DMS_fnc_DebugLog; +if (DMS_DEBUG) then { + diag_log format ["GetAllUnits :: Foot units: %1", _footUnits]; + diag_log format ["GetAllUnits :: Vehicle units: %1", _vehicleUnits]; + diag_log format ["GetAllUnits :: Static units: %1", _staticUnits]; + diag_log format ["GetAllUnits :: Total units: %1", _units]; }; - _units diff --git a/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf b/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf index 7e86390..cbcb3d6 100644 --- a/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf +++ b/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf @@ -23,28 +23,28 @@ private _killedpercent = false; // Get the kill percent value from config private _killPercent = DMS_AI_KillPercent; -//diag_log format ["DMS DEBUG :: Kill percent value: %1", _killPercent]; -//diag_log format ["DMS DEBUG :: Initial unit count: %1", _initialUnitCount]; +diag_log format ["DMS DEBUG :: Kill percent value: %1", _killPercent]; +diag_log format ["DMS DEBUG :: Initial unit count: %1", _initialUnitCount]; // Calculate the acceptable number of killed units based on initial unit count private _unitsThreshold = ceil(_killPercent * _initialUnitCount / 100); -//diag_log format ["DMS DEBUG :: Units threshold (killed units): %1", _unitsThreshold]; +diag_log format ["DMS DEBUG :: Units threshold (killed units): %1", _unitsThreshold]; // Get all living AI units private _allUnits = _args call DMS_fnc_GetAllUnits; private _totalUnits = count _allUnits; -//diag_log format ["DMS DEBUG :: Total living units: %1", _totalUnits]; +diag_log format ["DMS DEBUG :: Total living units: %1", _totalUnits]; // Calculate the number of killed units private _killedUnits = if (_initialUnitCount - _totalUnits > 0) then {_initialUnitCount - _totalUnits} else {0}; -//diag_log format ["DMS DEBUG :: Total killed units: %1", _killedUnits]; +diag_log format ["DMS DEBUG :: Total killed units: %1", _killedUnits]; // Check if the number of killed units is greater than or equal to the threshold if (_killedUnits >= _unitsThreshold) then { _killedpercent = true; - //diag_log "DMS DEBUG :: Kill percent condition met"; + diag_log "DMS DEBUG :: Kill percent condition met"; } else { - //diag_log "DMS DEBUG :: Kill percent condition not met"; + diag_log "DMS DEBUG :: Kill percent condition not met"; }; _killedpercent; From 3885c2420e00b401b4d92b1032c9090dc9a6817a Mon Sep 17 00:00:00 2001 From: Ravenger2709 Date: Wed, 18 Sep 2024 16:28:36 +0300 Subject: [PATCH 15/15] turn off debug messages --- .../addons/a3_dms/scripts/fn_GetAllUnits.sqf | 1 + .../a3_dms/scripts/fn_MissionSuccessState.sqf | 1 + .../a3_dms/scripts/fn_TargetsKilledPercent.sqf | 14 +++++++------- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/@ExileServer/addons/a3_dms/scripts/fn_GetAllUnits.sqf b/@ExileServer/addons/a3_dms/scripts/fn_GetAllUnits.sqf index 66bd27b..f59e770 100644 --- a/@ExileServer/addons/a3_dms/scripts/fn_GetAllUnits.sqf +++ b/@ExileServer/addons/a3_dms/scripts/fn_GetAllUnits.sqf @@ -1,6 +1,7 @@ /* DMS_fnc_GetAllUnits Created by eraser1 + Modified by Ravenger2709 Usage: [ diff --git a/@ExileServer/addons/a3_dms/scripts/fn_MissionSuccessState.sqf b/@ExileServer/addons/a3_dms/scripts/fn_MissionSuccessState.sqf index 8e5b9df..9bd9771 100644 --- a/@ExileServer/addons/a3_dms/scripts/fn_MissionSuccessState.sqf +++ b/@ExileServer/addons/a3_dms/scripts/fn_MissionSuccessState.sqf @@ -1,6 +1,7 @@ /* DMS_fnc_MissionSuccessState Created by eraser1 + Modified by Ravenger2709 Usage: [ diff --git a/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf b/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf index cbcb3d6..7e86390 100644 --- a/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf +++ b/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilledPercent.sqf @@ -23,28 +23,28 @@ private _killedpercent = false; // Get the kill percent value from config private _killPercent = DMS_AI_KillPercent; -diag_log format ["DMS DEBUG :: Kill percent value: %1", _killPercent]; -diag_log format ["DMS DEBUG :: Initial unit count: %1", _initialUnitCount]; +//diag_log format ["DMS DEBUG :: Kill percent value: %1", _killPercent]; +//diag_log format ["DMS DEBUG :: Initial unit count: %1", _initialUnitCount]; // Calculate the acceptable number of killed units based on initial unit count private _unitsThreshold = ceil(_killPercent * _initialUnitCount / 100); -diag_log format ["DMS DEBUG :: Units threshold (killed units): %1", _unitsThreshold]; +//diag_log format ["DMS DEBUG :: Units threshold (killed units): %1", _unitsThreshold]; // Get all living AI units private _allUnits = _args call DMS_fnc_GetAllUnits; private _totalUnits = count _allUnits; -diag_log format ["DMS DEBUG :: Total living units: %1", _totalUnits]; +//diag_log format ["DMS DEBUG :: Total living units: %1", _totalUnits]; // Calculate the number of killed units private _killedUnits = if (_initialUnitCount - _totalUnits > 0) then {_initialUnitCount - _totalUnits} else {0}; -diag_log format ["DMS DEBUG :: Total killed units: %1", _killedUnits]; +//diag_log format ["DMS DEBUG :: Total killed units: %1", _killedUnits]; // Check if the number of killed units is greater than or equal to the threshold if (_killedUnits >= _unitsThreshold) then { _killedpercent = true; - diag_log "DMS DEBUG :: Kill percent condition met"; + //diag_log "DMS DEBUG :: Kill percent condition met"; } else { - diag_log "DMS DEBUG :: Kill percent condition not met"; + //diag_log "DMS DEBUG :: Kill percent condition not met"; }; _killedpercent;