From b15ff6d7ba07a3d1bc76c1bed17ba1d1609cdd02 Mon Sep 17 00:00:00 2001 From: Steinar Thorshaug Date: Fri, 29 Apr 2016 09:45:10 +0200 Subject: [PATCH 1/4] Added modules for transfering groups to the server One module transfers a single group. The other module transfers all groups. --- .../ares_zeusExtensions/cfgFunctions.hpp | 3 +- .../functions/fn_TransferGroupsToServer.sqf | 52 +++++++++++++++++++ .../scripts/Util_TransferAllToServer.sqf | 8 +++ .../scripts/Util_TransferGroupToServer.sqf | 25 +++++++++ .../scripts/registerBuiltInCustomModules.sqf | 5 +- 5 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 src/addons/ares_zeusExtensions/functions/fn_TransferGroupsToServer.sqf create mode 100644 src/addons/ares_zeusExtensions/scripts/Util_TransferAllToServer.sqf create mode 100644 src/addons/ares_zeusExtensions/scripts/Util_TransferGroupToServer.sqf 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..3b484b6 --- /dev/null +++ b/src/addons/ares_zeusExtensions/functions/fn_TransferGroupsToServer.sqf @@ -0,0 +1,52 @@ +/* + 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) +*/ +private ["_group", "_debugOn"]; +_group = [_this, 0, objNull] call BIS_fnc_param; +_debugOn = [_this, 1, false] call BIS_fnc_param; + +// Require this function +if(isNil "Ares_changeOwnerToServerFunction") then { + Ares_changeOwnerToServerFunction = { + private ["_playerInGroup", "_debugOn", "_debugTxt", "_groups"]; + _groups = [_this, 0, objNull] call BIS_fnc_param; + _debugOn = [_this, 1, false] call BIS_fnc_param; + + 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_TransferAllToServer.sqf b/src/addons/ares_zeusExtensions/scripts/Util_TransferAllToServer.sqf new file mode 100644 index 0000000..2d58706 --- /dev/null +++ b/src/addons/ares_zeusExtensions/scripts/Util_TransferAllToServer.sqf @@ -0,0 +1,8 @@ +[ + "Util", + "Transfer all groups to server", + { + [] 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/Util_TransferGroupToServer.sqf b/src/addons/ares_zeusExtensions/scripts/Util_TransferGroupToServer.sqf new file mode 100644 index 0000000..67af712 --- /dev/null +++ b/src/addons/ares_zeusExtensions/scripts/Util_TransferGroupToServer.sqf @@ -0,0 +1,25 @@ +[ + "Util", + "Transfer group to server", + { + private ["_groupUnderCursor"]; + ["BehaviourPatrol: Getting group under cursor"] call Ares_fnc_LogMessage; + _groupUnderCursor = [_logic] call Ares_fnc_GetGroupUnderCursor; + ["BehaviourPatrol: Got group under cursor"] call Ares_fnc_LogMessage; + if (not isNull _groupUnderCursor) then { + private ["_playerInGroup"]; + _playerInGroup = false; + { + if (isPlayer _x) exitWith { _playerInGroup = true; }; + } forEach (units _groupUnderCursor); + if(not _playerInGroup) then { + [_groupUnderCursor] 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 { + ["No unit or group under cursor!!"] call Ares_fnc_LogMessage; + }; + } +] call Ares_fnc_RegisterCustomModule; diff --git a/src/addons/ares_zeusExtensions/scripts/registerBuiltInCustomModules.sqf b/src/addons/ares_zeusExtensions/scripts/registerBuiltInCustomModules.sqf index 8d2505b..1083592 100644 --- a/src/addons/ares_zeusExtensions/scripts/registerBuiltInCustomModules.sqf +++ b/src/addons/ares_zeusExtensions/scripts/registerBuiltInCustomModules.sqf @@ -18,7 +18,9 @@ _scripts = [ "Util_ExecuteCodeServer", "Util_MakeZeusInvisible", "Util_MakeZeusVisible", - "Util_RemoveAllActions" + "Util_RemoveAllActions", + "Util_TransferAllToServer", + "Util_TransferGroupToServer" ]; { call compile preprocessFileLineNumbers ("\ares_zeusExtensions\scripts\" + _x + ".sqf"); @@ -38,4 +40,3 @@ if (isNil "Ares_FireArtilleryFunction") then }; publicVariable "Ares_FireArtilleryFunction"; }; - From e5f1fe9b6e62440507f48eb807849b19dcc3fb08 Mon Sep 17 00:00:00 2001 From: Steinar Thorshaug Date: Wed, 11 May 2016 09:08:49 +0200 Subject: [PATCH 2/4] Merge both modules into a single module Drop the module on a group to transfer the specific group. Drop the module elsewhere to transfer all groups. --- .../scripts/Util_TransferAllToServer.sqf | 8 -------- .../scripts/Util_TransferGroupToServer.sqf | 17 ++++++++--------- .../scripts/registerBuiltInCustomModules.sqf | 1 - 3 files changed, 8 insertions(+), 18 deletions(-) delete mode 100644 src/addons/ares_zeusExtensions/scripts/Util_TransferAllToServer.sqf diff --git a/src/addons/ares_zeusExtensions/scripts/Util_TransferAllToServer.sqf b/src/addons/ares_zeusExtensions/scripts/Util_TransferAllToServer.sqf deleted file mode 100644 index 2d58706..0000000 --- a/src/addons/ares_zeusExtensions/scripts/Util_TransferAllToServer.sqf +++ /dev/null @@ -1,8 +0,0 @@ -[ - "Util", - "Transfer all groups to server", - { - [] 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/Util_TransferGroupToServer.sqf b/src/addons/ares_zeusExtensions/scripts/Util_TransferGroupToServer.sqf index 67af712..940568e 100644 --- a/src/addons/ares_zeusExtensions/scripts/Util_TransferGroupToServer.sqf +++ b/src/addons/ares_zeusExtensions/scripts/Util_TransferGroupToServer.sqf @@ -1,25 +1,24 @@ [ "Util", - "Transfer group to server", + "Transfer to server", { - private ["_groupUnderCursor"]; - ["BehaviourPatrol: Getting group under cursor"] call Ares_fnc_LogMessage; - _groupUnderCursor = [_logic] call Ares_fnc_GetGroupUnderCursor; - ["BehaviourPatrol: Got group under cursor"] call Ares_fnc_LogMessage; - if (not isNull _groupUnderCursor) then { + private ["_unitUnderCursor"]; + _unitUnderCursor = _this select 1; + if (not isNull _unitUnderCursor) then { private ["_playerInGroup"]; _playerInGroup = false; { if (isPlayer _x) exitWith { _playerInGroup = true; }; - } forEach (units _groupUnderCursor); + } forEach (units (group _unitUnderCursor)); if(not _playerInGroup) then { - [_groupUnderCursor] call Ares_fnc_TransferGroupsToServer; + [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 { - ["No unit or group under cursor!!"] call Ares_fnc_LogMessage; + [] 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 1083592..f5bf13a 100644 --- a/src/addons/ares_zeusExtensions/scripts/registerBuiltInCustomModules.sqf +++ b/src/addons/ares_zeusExtensions/scripts/registerBuiltInCustomModules.sqf @@ -19,7 +19,6 @@ _scripts = [ "Util_MakeZeusInvisible", "Util_MakeZeusVisible", "Util_RemoveAllActions", - "Util_TransferAllToServer", "Util_TransferGroupToServer" ]; { From 616372b3fd209bd70ed9c99beb41b38b529a519b Mon Sep 17 00:00:00 2001 From: Steinar Thorshaug Date: Wed, 11 May 2016 09:18:48 +0200 Subject: [PATCH 3/4] Fixed code-style issues --- .../functions/fn_TransferGroupsToServer.sqf | 35 ++++++++++++------- .../scripts/Util_TransferGroupToServer.sqf | 14 +++++--- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/addons/ares_zeusExtensions/functions/fn_TransferGroupsToServer.sqf b/src/addons/ares_zeusExtensions/functions/fn_TransferGroupsToServer.sqf index 3b484b6..b984695 100644 --- a/src/addons/ares_zeusExtensions/functions/fn_TransferGroupsToServer.sqf +++ b/src/addons/ares_zeusExtensions/functions/fn_TransferGroupsToServer.sqf @@ -10,43 +10,54 @@ _group = [_this, 0, objNull] call BIS_fnc_param; _debugOn = [_this, 1, false] call BIS_fnc_param; // Require this function -if(isNil "Ares_changeOwnerToServerFunction") then { - Ares_changeOwnerToServerFunction = { +if (isNil "Ares_ChangeOwnerToServerFunction") then +{ + Ares_ChangeOwnerToServerFunction = + { private ["_playerInGroup", "_debugOn", "_debugTxt", "_groups"]; _groups = [_this, 0, objNull] call BIS_fnc_param; _debugOn = [_this, 1, false] call BIS_fnc_param; - if(isNull _groups) then { + if (isNull _groups) then + { _groups = allGroups; - } else { + } + 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 { + 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 { + if (!_playerInGroup) then + { _x setGroupOwner 2; - if(_debugOn) then { + if (_debugOn) then + { _debugTxt = format ["[ARES] Changing owner to server for %1", _x]; - if(isDedicated) then { + if (isDedicated) then + { diag_log _debugTxt; - } else { + } + else + { systemChat _debugTxt; }; }; }; }; - }foreach _groups; + } foreach _groups; }; - publicVariable "Ares_changeOwnerToServerFunction"; + publicVariable "Ares_ChangeOwnerToServerFunction"; }; -[[_group, _debugOn], "Ares_changeOwnerToServerFunction", false] call BIS_fnc_MP; +[[_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 index 940568e..9fa144b 100644 --- a/src/addons/ares_zeusExtensions/scripts/Util_TransferGroupToServer.sqf +++ b/src/addons/ares_zeusExtensions/scripts/Util_TransferGroupToServer.sqf @@ -4,19 +4,25 @@ { private ["_unitUnderCursor"]; _unitUnderCursor = _this select 1; - if (not isNull _unitUnderCursor) then { + if (not isNull _unitUnderCursor) then + { private ["_playerInGroup"]; _playerInGroup = false; { if (isPlayer _x) exitWith { _playerInGroup = true; }; } forEach (units (group _unitUnderCursor)); - if(not _playerInGroup) then { + if (not _playerInGroup) then + { [group _unitUnderCursor] call Ares_fnc_TransferGroupsToServer; ["Group will be transfered to the server."] call Ares_fnc_ShowZeusMessage; - } else { + } + else + { ["Cannot transfer a group with player units."] call Ares_fnc_ShowZeusMessage; }; - } else { + } + else + { [] call Ares_fnc_TransferGroupsToServer; ["All groups will be transfered to the server"] call Ares_fnc_ShowZeusMessage; }; From 671fb0718d4e5f3d55bda8586f90bd2804764d30 Mon Sep 17 00:00:00 2001 From: Steinar Thorshaug Date: Wed, 11 May 2016 09:48:07 +0200 Subject: [PATCH 4/4] Use params instead of BIS_fnc_param --- .../functions/fn_TransferGroupsToServer.sqf | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/addons/ares_zeusExtensions/functions/fn_TransferGroupsToServer.sqf b/src/addons/ares_zeusExtensions/functions/fn_TransferGroupsToServer.sqf index b984695..ce908eb 100644 --- a/src/addons/ares_zeusExtensions/functions/fn_TransferGroupsToServer.sqf +++ b/src/addons/ares_zeusExtensions/functions/fn_TransferGroupsToServer.sqf @@ -5,18 +5,14 @@ 0: Specific group or objNull for all groups (default objNull) 1: Bool - show debug output (optional, default false) */ -private ["_group", "_debugOn"]; -_group = [_this, 0, objNull] call BIS_fnc_param; -_debugOn = [_this, 1, false] call BIS_fnc_param; +params[["_group", grpNull, [grpNull]], ["_debugOn", false, [false]]]; // Require this function if (isNil "Ares_ChangeOwnerToServerFunction") then { Ares_ChangeOwnerToServerFunction = { - private ["_playerInGroup", "_debugOn", "_debugTxt", "_groups"]; - _groups = [_this, 0, objNull] call BIS_fnc_param; - _debugOn = [_this, 1, false] call BIS_fnc_param; + params[["_groups", grpNull, [grpNull]], ["_debugOn", false, [false]]]; if (isNull _groups) then {