From 3259329fb4b9d49efd01be8c2c6d9aa8acf4bb62 Mon Sep 17 00:00:00 2001 From: AndreasBrostrom Date: Thu, 2 Nov 2023 17:05:56 +0100 Subject: [PATCH] Added function to ban ai dismount for crew --- cScripts/CfgFunctions.hpp | 3 +- cScripts/cScripts_preInit.sqf | 14 +- cScripts/functions/init/fn_init_aI.sqf | 121 ++++++++++++++++++ .../init/fn_init_skillAdjustment.sqf | 102 --------------- 4 files changed, 134 insertions(+), 106 deletions(-) create mode 100644 cScripts/functions/init/fn_init_aI.sqf delete mode 100644 cScripts/functions/init/fn_init_skillAdjustment.sqf diff --git a/cScripts/CfgFunctions.hpp b/cScripts/CfgFunctions.hpp index 31b499ef4..836b1cac2 100644 --- a/cScripts/CfgFunctions.hpp +++ b/cScripts/CfgFunctions.hpp @@ -5,7 +5,8 @@ class cScripts { class init_aceTagging {}; class init_aceItemReplace {}; - class init_skillAdjustment {}; + class init_ai {}; + class init_vehicle {}; class init_staging {}; diff --git a/cScripts/cScripts_preInit.sqf b/cScripts/cScripts_preInit.sqf index bf790f972..3517ba28e 100644 --- a/cScripts/cScripts_preInit.sqf +++ b/cScripts/cScripts_preInit.sqf @@ -47,6 +47,16 @@ private _cScriptSettings = "cScripts Mission Settings"; {}, true ] call CBA_fnc_addSetting; +[ // Ai dismount + QEGVAR(Settings,setAiBanDismountOfCrew), + "LIST", + ["Allow", "This allow or disallow ai crew to dismount vehicles."], + [_cScriptSettings, "1; Mission"], + true, + true, + {}, + true +] call CBA_fnc_addSetting; //2; Radios @@ -370,9 +380,7 @@ call EFUNC(init,chatCommands); call EFUNC(init,zenModuels); -if (EGVAR(Settings,setAiSystemDifficulty) >= 1 ) then { - call EFUNC(init,skillAdjustment); -}; +call EFUNC(init,ai); call EFUNC(init,eventHandlers); diff --git a/cScripts/functions/init/fn_init_aI.sqf b/cScripts/functions/init/fn_init_aI.sqf new file mode 100644 index 000000000..25c43a2f6 --- /dev/null +++ b/cScripts/functions/init/fn_init_aI.sqf @@ -0,0 +1,121 @@ +#include "..\script_component.hpp"; +/* + * Author: CPL.Brostrom.A + * This function changes AI behaviours + * + * Example: + * call cScripts_fnc_init_ai + * + * Public: No + */ + +INFO("init", "Applying AI Event Handler to units and vehicles..."); + +if (EGVAR(Settings,setAiBanDismountOfCrew)) then { + ["AllVehicles", "init", { + params ["_vehicle"]; + if (local _vehicle) then { + _vehicle setUnloadInCombat [true, false]; + }; + }, true, ["man"], true] call CBA_fnc_addClassEventHandler; + + ["AllVehicles", "initPost", { + params ["_vehicle"]; + if (local _vehicle) then { + _vehicle setUnloadInCombat [true, false]; + }; + }, true, ["man"], true] call CBA_fnc_addClassEventHandler; +}; + + +if (!isServer) exitWith {}; + +if (EGVAR(Settings,setAiSystemDifficulty) >= 1 ) then { + ["CAManBase", "init", { + params ["_unit"]; + + if !(isPlayer _unit) then { + if (EGVAR(Settings,setAiSystemDifficulty) == 1) then { + _unit setSkill ["aimingspeed", 0.420]; + _unit setSkill ["aimingaccuracy", 1.000]; + _unit setSkill ["aimingshake", 0.360]; + _unit setSkill ["spottime", 1.000]; + _unit setSkill ["spotdistance", 1.000]; + _unit setSkill ["commanding", 1.0]; + _unit setSkill ["general", 1.0]; + }; + if (EGVAR(Settings,setAiSystemDifficulty) == 2) then { + if (getLighting select 1 <= 5) then { + if (hmd _unit != "") then { + _unit setSkill ["spottime", 0.015]; + _unit setSkill ["spotdistance", 0.015]; + } else { + _unit setSkill ["spottime", 0.520]; + _unit setSkill ["spotdistance", 0.520]; + }; + } else { + _unit setSkill ["spottime", 1.000]; + _unit setSkill ["spotdistance", 1.000]; + }; + + switch (faction _unit) do { + case "rhs_faction_msv"; + case "rhs_faction_rva"; + case "rhs_faction_tv"; + case "rhs_faction_vdv_45"; + case "rhs_faction_vdv"; + case "rhs_faction_vmf"; + case "rhs_faction_vpvo"; + case "rhs_faction_vv"; + case "rhs_faction_vvs_c"; + case "rhs_faction_vvs": { + _unit setSkill ["general", 1.000]; + _unit setSkill ["commanding", 0.950]; + _unit setSkill ["courage", 1.000]; + _unit setSkill ["aimingspeed", 0.720]; + _unit setSkill ["aimingaccuracy", 0.920]; + _unit setSkill ["aimingshake", 0.260]; + _unit setSkill ["reloadSpeed", 1.000]; + }; + default { + _unit setSkill ["general", 0.900]; // Bad <=> Good + _unit setSkill ["commanding", 0.750]; // Bad <=> Good + _unit setSkill ["courage", 0.750]; // Bad <=> Good + _unit setSkill ["aimingspeed", 0.620]; // Bad <=> Good + _unit setSkill ["aimingaccuracy", 0.830]; // Bad <=> Good + _unit setSkill ["aimingshake", 0.360]; // Good <=> Bad + _unit setSkill ["reloadSpeed", 0.750]; // Bad <=> Good + }; + }; + + // Role adjusted + if (getText (configfile >> "CfgVehicles" >> typeOf _unit >> "textSingular") == "machinegunner") then { + _unit setSkill ["aimingspeed", 0.820]; + _unit setSkill ["aimingaccuracy", 0.820]; + _unit setSkill ["aimingshake", 0.350]; + _unit setSkill ["reloadSpeed", 0.800]; + }; + if (getText (configfile >> "CfgVehicles" >> typeOf _unit >> "textSingular") == "sniper") then { + _unit setSkill ["aimingspeed", 0.600]; + _unit setSkill ["aimingaccuracy", 0.950]; + _unit setSkill ["aimingshake", 0.100]; + _unit setSkill ["reloadSpeed", 0.800]; + }; + + // For logging + private _skillArray = [ + ["general", _unit skill "general"], + ["commanding", _unit skill "commanding"], + ["courage", _unit skill "courage"], + ["aimingspeed", _unit skill "aimingspeed"], + ["aimingaccuracy", _unit skill "aimingaccuracy"], + ["aimingshake", _unit skill "aimingshake"], + ["reloadSpeed", _unit skill "reloadSpeed"], + ["spottime", _unit skill "spottime"], + ["spotdistance", _unit skill "spotdistance"] + ]; + INFO_3("init","AI unit %1 (%2) have skill levels %3.", _unit, typeOf _unit, _skillArray); + }; + }; + }, true, [], true] call CBA_fnc_addClassEventHandler; +}; diff --git a/cScripts/functions/init/fn_init_skillAdjustment.sqf b/cScripts/functions/init/fn_init_skillAdjustment.sqf deleted file mode 100644 index 5cbe02ecd..000000000 --- a/cScripts/functions/init/fn_init_skillAdjustment.sqf +++ /dev/null @@ -1,102 +0,0 @@ -#include "..\script_component.hpp"; -/* - * Author: CPL.Brostrom.A - * This function changes AI skill values - * - * Example: - * call cScripts_fnc_init_skillAdjustment - * - * Public: No - */ - -INFO("init", "Applying AI Event Handler to units..."); - -if (!isServer) exitWith {}; - -["CAManBase", "init", { - params ["_unit"]; - - if !(isPlayer _unit) then { - if (EGVAR(Settings,setAiSystemDifficulty) == 1) then { - _unit setSkill ["aimingspeed", 0.420]; - _unit setSkill ["aimingaccuracy", 1.000]; - _unit setSkill ["aimingshake", 0.360]; - _unit setSkill ["spottime", 1.000]; - _unit setSkill ["spotdistance", 1.000]; - _unit setSkill ["commanding", 1.0]; - _unit setSkill ["general", 1.0]; - }; - if (EGVAR(Settings,setAiSystemDifficulty) == 2) then { - if (getLighting select 1 <= 5) then { - if (hmd _unit != "") then { - _unit setSkill ["spottime", 0.015]; - _unit setSkill ["spotdistance", 0.015]; - } else { - _unit setSkill ["spottime", 0.520]; - _unit setSkill ["spotdistance", 0.520]; - }; - } else { - _unit setSkill ["spottime", 1.000]; - _unit setSkill ["spotdistance", 1.000]; - }; - - switch (faction _unit) do { - case "rhs_faction_msv"; - case "rhs_faction_rva"; - case "rhs_faction_tv"; - case "rhs_faction_vdv_45"; - case "rhs_faction_vdv"; - case "rhs_faction_vmf"; - case "rhs_faction_vpvo"; - case "rhs_faction_vv"; - case "rhs_faction_vvs_c"; - case "rhs_faction_vvs": { - _unit setSkill ["general", 1.000]; - _unit setSkill ["commanding", 0.950]; - _unit setSkill ["courage", 1.000]; - _unit setSkill ["aimingspeed", 0.720]; - _unit setSkill ["aimingaccuracy", 0.920]; - _unit setSkill ["aimingshake", 0.260]; - _unit setSkill ["reloadSpeed", 1.000]; - }; - default { - _unit setSkill ["general", 0.900]; // Bad <=> Good - _unit setSkill ["commanding", 0.750]; // Bad <=> Good - _unit setSkill ["courage", 0.750]; // Bad <=> Good - _unit setSkill ["aimingspeed", 0.620]; // Bad <=> Good - _unit setSkill ["aimingaccuracy", 0.830]; // Bad <=> Good - _unit setSkill ["aimingshake", 0.360]; // Good <=> Bad - _unit setSkill ["reloadSpeed", 0.750]; // Bad <=> Good - }; - }; - - // Role adjusted - if (getText (configfile >> "CfgVehicles" >> typeOf _unit >> "textSingular") == "machinegunner") then { - _unit setSkill ["aimingspeed", 0.820]; - _unit setSkill ["aimingaccuracy", 0.820]; - _unit setSkill ["aimingshake", 0.350]; - _unit setSkill ["reloadSpeed", 0.800]; - }; - if (getText (configfile >> "CfgVehicles" >> typeOf _unit >> "textSingular") == "sniper") then { - _unit setSkill ["aimingspeed", 0.600]; - _unit setSkill ["aimingaccuracy", 0.950]; - _unit setSkill ["aimingshake", 0.100]; - _unit setSkill ["reloadSpeed", 0.800]; - }; - - // For logging - private _skillArray = [ - ["general", _unit skill "general"], - ["commanding", _unit skill "commanding"], - ["courage", _unit skill "courage"], - ["aimingspeed", _unit skill "aimingspeed"], - ["aimingaccuracy", _unit skill "aimingaccuracy"], - ["aimingshake", _unit skill "aimingshake"], - ["reloadSpeed", _unit skill "reloadSpeed"], - ["spottime", _unit skill "spottime"], - ["spotdistance", _unit skill "spotdistance"] - ]; - INFO_3("init","AI unit %1 (%2) have skill levels %3.", _unit, typeOf _unit, _skillArray); - }; - }; -}, true, [], true] call CBA_fnc_addClassEventHandler;