diff --git a/src/addons/ares_zeusExtensions/cfgFunctions.hpp b/src/addons/ares_zeusExtensions/cfgFunctions.hpp index dfa9b5c..3f4cb91 100644 --- a/src/addons/ares_zeusExtensions/cfgFunctions.hpp +++ b/src/addons/ares_zeusExtensions/cfgFunctions.hpp @@ -48,6 +48,7 @@ class Ares // This bit will be prefixed when actually calling the function (e.g. class ShowZeusMessage; class StringContains; class TeleportPlayers; + class TransferGroupsToServer; class WaitForZeus; class ZenOccupyHouse; }; @@ -58,7 +59,7 @@ class Ares // This bit will be prefixed when actually calling the function (e.g. file = "\ares_zeusExtensions\modules"; class Empty; }; - + #include "cfgFunctionsBehaviour.hpp" #include "cfgFunctionsEquipment.hpp" #include "cfgFunctionsReinforcements.hpp" diff --git a/src/addons/ares_zeusExtensions/functions/fn_TransferGroupsToServer.sqf b/src/addons/ares_zeusExtensions/functions/fn_TransferGroupsToServer.sqf new file mode 100644 index 0000000..ce908eb --- /dev/null +++ b/src/addons/ares_zeusExtensions/functions/fn_TransferGroupsToServer.sqf @@ -0,0 +1,59 @@ +/* + Transfers ownership for all groups to the server + + Parameters: + 0: Specific group or objNull for all groups (default objNull) + 1: Bool - show debug output (optional, default false) +*/ +params[["_group", grpNull, [grpNull]], ["_debugOn", false, [false]]]; + +// Require this function +if (isNil "Ares_ChangeOwnerToServerFunction") then +{ + Ares_ChangeOwnerToServerFunction = + { + params[["_groups", grpNull, [grpNull]], ["_debugOn", false, [false]]]; + + if (isNull _groups) then + { + _groups = allGroups; + } + else + { + _groups = [_groups]; // Make an array of this one + }; + + // Loop all groups + { + // Check if group is owned by the server or not + if ((groupOwner _x) != 2) then + { + _playerInGroup = false; + { + if (isPlayer _x) exitWith { _playerInGroup = true; }; + } forEach (units _x); + + // Transfer group if no players are part of the group + if (!_playerInGroup) then + { + _x setGroupOwner 2; + if (_debugOn) then + { + _debugTxt = format ["[ARES] Changing owner to server for %1", _x]; + if (isDedicated) then + { + diag_log _debugTxt; + } + else + { + systemChat _debugTxt; + }; + }; + }; + }; + } foreach _groups; + }; + publicVariable "Ares_ChangeOwnerToServerFunction"; +}; + +[[_group, _debugOn], "Ares_ChangeOwnerToServerFunction", false] call BIS_fnc_MP; diff --git a/src/addons/ares_zeusExtensions/scripts/Util_TransferGroupToServer.sqf b/src/addons/ares_zeusExtensions/scripts/Util_TransferGroupToServer.sqf new file mode 100644 index 0000000..9fa144b --- /dev/null +++ b/src/addons/ares_zeusExtensions/scripts/Util_TransferGroupToServer.sqf @@ -0,0 +1,30 @@ +[ + "Util", + "Transfer to server", + { + private ["_unitUnderCursor"]; + _unitUnderCursor = _this select 1; + if (not isNull _unitUnderCursor) then + { + private ["_playerInGroup"]; + _playerInGroup = false; + { + if (isPlayer _x) exitWith { _playerInGroup = true; }; + } forEach (units (group _unitUnderCursor)); + if (not _playerInGroup) then + { + [group _unitUnderCursor] call Ares_fnc_TransferGroupsToServer; + ["Group will be transfered to the server."] call Ares_fnc_ShowZeusMessage; + } + else + { + ["Cannot transfer a group with player units."] call Ares_fnc_ShowZeusMessage; + }; + } + else + { + [] call Ares_fnc_TransferGroupsToServer; + ["All groups will be transfered to the server"] call Ares_fnc_ShowZeusMessage; + }; + } +] call Ares_fnc_RegisterCustomModule; diff --git a/src/addons/ares_zeusExtensions/scripts/registerBuiltInCustomModules.sqf b/src/addons/ares_zeusExtensions/scripts/registerBuiltInCustomModules.sqf index 8d2505b..f5bf13a 100644 --- a/src/addons/ares_zeusExtensions/scripts/registerBuiltInCustomModules.sqf +++ b/src/addons/ares_zeusExtensions/scripts/registerBuiltInCustomModules.sqf @@ -18,7 +18,8 @@ _scripts = [ "Util_ExecuteCodeServer", "Util_MakeZeusInvisible", "Util_MakeZeusVisible", - "Util_RemoveAllActions" + "Util_RemoveAllActions", + "Util_TransferGroupToServer" ]; { call compile preprocessFileLineNumbers ("\ares_zeusExtensions\scripts\" + _x + ".sqf"); @@ -38,4 +39,3 @@ if (isNil "Ares_FireArtilleryFunction") then }; publicVariable "Ares_FireArtilleryFunction"; }; -