From 4125f90dd24d8c12658033d74b9cc516ffebd756 Mon Sep 17 00:00:00 2001 From: Filip Maciejewski Date: Mon, 10 Sep 2018 20:48:21 +0200 Subject: [PATCH 1/4] Simplify core module player actions adding --- .../fnc/fn_core_handleVehicleSpawn.sqf | 38 ++++++++++++++ .../fnc/fn_core_setupPlayerActions.sqf | 52 +++---------------- .../modules/01_core/functions.hpp | 5 +- 3 files changed, 49 insertions(+), 46 deletions(-) create mode 100644 Missionframework/modules/01_core/fnc/fn_core_handleVehicleSpawn.sqf diff --git a/Missionframework/modules/01_core/fnc/fn_core_handleVehicleSpawn.sqf b/Missionframework/modules/01_core/fnc/fn_core_handleVehicleSpawn.sqf new file mode 100644 index 000000000..caf34a7a8 --- /dev/null +++ b/Missionframework/modules/01_core/fnc/fn_core_handleVehicleSpawn.sqf @@ -0,0 +1,38 @@ +/* + KPLIB_fnc_core_handleVehicleSpawn + + File: fn_core_handleVehicleSpawn.sqf + Author: KP Liberation Dev Team - https://github.com/KillahPotatoes + Date: 2018-09-10 + Last Update: 2018-09-10 + License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html + + Description: + Handle vehicle spawn event + + Parameter(s): + 0: OBJECT - Vehicle which was spawned + + Returns: + NOTHING +*/ +params ["_vehicle"]; + +switch(typeOf _vehicle) do { + case KPLIB_preset_fobBox; + case KPLIB_preset_fobTruck: { + // Add FOB build action globaly and for JIP + [ + _vehicle, + [localize "STR_ACTION_FOB_DEPLOY", {[param [0], param [1], param[3]] call KPLIB_fnc_core_buildFob}, true, -800, false, true, "", "[_target, _this] call KPLIB_fnc_core_canBuildFob", 10] + ] remoteExecCall ["addAction", 0, true]; + }; + + case KPLIB_preset_potato: { + // Add redeploy action globaly and for JIP + [ + _vehicle, + [localize "STR_ACTION_REDEPLOY", {[] spawn KPLIB_fnc_core_redeploy}, nil, -801, false, true, "", "_target == _originalTarget", 10] + ] remoteExecCall ["addAction", 0, true]; + }; +}; diff --git a/Missionframework/modules/01_core/fnc/fn_core_setupPlayerActions.sqf b/Missionframework/modules/01_core/fnc/fn_core_setupPlayerActions.sqf index 2e6a6c8d3..a1a3ade3a 100644 --- a/Missionframework/modules/01_core/fnc/fn_core_setupPlayerActions.sqf +++ b/Missionframework/modules/01_core/fnc/fn_core_setupPlayerActions.sqf @@ -4,7 +4,7 @@ File: fn_common_setupPlayerActions.sqf Author: KP Liberation Dev Team - https://github.com/KillahPotatoes Date: 2018-05-28 - Last Update: 2018-08-26 + Last Update: 2018-09-10 License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html Description: @@ -19,54 +19,16 @@ // Actions avalible GLOBALLY on objects if (isServer) then { - // Actions on Vehicles - ["KPLIB_vehicle_spawned", { - params ["_vehicle"]; - - switch(typeOf _vehicle) do { - case KPLIB_preset_fobBox; - case KPLIB_preset_fobTruck: { - // Add FOB build action globaly and for JIP - [ - _vehicle, - [localize "STR_ACTION_FOB_DEPLOY", {[param [0], param [1], param[3]] call KPLIB_fnc_core_buildFob}, true, -800, false, true, "", "[_target, _this] call KPLIB_fnc_core_canBuildFob", 10] - ] remoteExecCall ["addAction", 0, true]; - }; - - case KPLIB_preset_potato: { - // Add redeploy action globaly and for JIP - [ - _vehicle, - [localize "STR_ACTION_REDEPLOY", {[] spawn KPLIB_fnc_core_redeploy}, nil, -801, false, true, "", "vehicle player == player", 10] - ] remoteExecCall ["addAction", 0, true]; - }; - }; - }] call CBA_fnc_addEventHandler; + // Add actions to supported vehicles + ["KPLIB_vehicle_spawned", KPLIB_fnc_core_handleVehicleSpawn] call CBA_fnc_addEventHandler; }; // Actions avalible LOCALLY to player if(hasInterface) then { - ["KPLIB_player_fob", { - params ["_player", "_fob"]; - - private _redeployActionId = _player getVariable ["KPLIB_actionId_redeploy", nil]; - - // Remove redeploy action if player had one avalible - if (_fob isEqualTo "") then { - if (!isNil "_redeployActionId") then { - _player removeAction _redeployActionId; - _player setVariable ["KPLIB_actionId_redeploy", nil]; - }; - } else { - // If entered fob and had no action - if (isNil "_redeployActionId") then { - // Add action to player - _redeployActionId = _player addAction [localize "STR_ACTION_REDEPLOY", {[] spawn KPLIB_fnc_core_redeploy}, nil, -801, false, true, "", "vehicle player == player", 10]; - // Save action id so it can we removed when out of FOB - _player setVariable ["KPLIB_actionId_redeploy", _redeployActionId]; - }; - }; - }] call CBA_fnc_addEventHandler + // FOB redeploy action + private _fobRedeployCondition = '_target isEqualTo _originalTarget && !(_originalTarget getVariable ["KPLIB_fob", ""] isEqualTo "")'; + private _actionArray = [localize "STR_ACTION_REDEPLOY", {[] spawn KPLIB_fnc_core_redeploy}, nil, -801, false, true, "", _fobRedeployCondition, 10]; + [_actionArray] call CBA_fnc_addPlayerAction; }; true diff --git a/Missionframework/modules/01_core/functions.hpp b/Missionframework/modules/01_core/functions.hpp index 096914462..35a0627e5 100644 --- a/Missionframework/modules/01_core/functions.hpp +++ b/Missionframework/modules/01_core/functions.hpp @@ -4,7 +4,7 @@ File: functions.hpp Author: KP Liberation Dev Team - https://github.com/KillahPotatoes Date: 2017-10-28 - Last Update: 2018-08-31 + Last Update: 2018-09-10 License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html Description: @@ -47,6 +47,9 @@ class core { // Handle an activated sector class core_handleSector {}; + // Handle vehicle spawn event + class core_handleVehicleSpawn {}; + // Module initialization class core_initModule { postInit = 1; From 5316aeaf4493e20f48f3b6e8f80c635077674e54 Mon Sep 17 00:00:00 2001 From: Filip Maciejewski Date: Mon, 10 Sep 2018 20:49:57 +0200 Subject: [PATCH 2/4] Persistent build module action --- .../modules/02_build/fnc/fn_build_setupPlayerActions.sqf | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Missionframework/modules/02_build/fnc/fn_build_setupPlayerActions.sqf b/Missionframework/modules/02_build/fnc/fn_build_setupPlayerActions.sqf index 4cae7eddd..15dbe1460 100644 --- a/Missionframework/modules/02_build/fnc/fn_build_setupPlayerActions.sqf +++ b/Missionframework/modules/02_build/fnc/fn_build_setupPlayerActions.sqf @@ -4,7 +4,7 @@ File: fn_build_setupPlayerActions.sqf Author: KP Liberation Dev Team - https://github.com/KillahPotatoes Date: 2018-07-01 - Last Update: 2018-08-26 + Last Update: 2018-09-10 License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html Description: @@ -20,13 +20,14 @@ // Actions avalible LOCALLY to player if(hasInterface) then { // Build action - private _buildCondition = 'vehicle player == player && !(player getVariable ["KPLIB_fob", ""] in ["", "KPLIB_eden_startbase_marker"])'; + private _buildCondition = '_target == _originalTarget && !(_originalTarget getVariable ["KPLIB_fob", ""] in ["", "KPLIB_eden_startbase_marker"])'; private _buildAction = { private _pos = getMarkerPos (player getVariable "KPLIB_fob"); [_pos, KPLIB_range_fob] call KPLIB_fnc_build_start; }; - _buildActionId = player addAction [localize "STR_ACTION_FOB_BUILD", _buildAction, nil, -802, false, true, "", _buildCondition, 10]; - player setVariable ["KPLIB_actionId_build", _buildActionId]; + + private _actionArray = [localize "STR_ACTION_FOB_BUILD", _buildAction, nil, -802, false, true, "", _buildCondition, 10]; + [_actionArray] call CBA_fnc_addPlayerAction; }; true From d43973102b7a2b8a5d807bd8c7cd592f5cbefdc0 Mon Sep 17 00:00:00 2001 From: Filip Maciejewski Date: Mon, 10 Sep 2018 20:58:42 +0200 Subject: [PATCH 3/4] Fix Potato01 redeploy action available while in vehicle --- .../modules/01_core/fnc/fn_core_handleVehicleSpawn.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Missionframework/modules/01_core/fnc/fn_core_handleVehicleSpawn.sqf b/Missionframework/modules/01_core/fnc/fn_core_handleVehicleSpawn.sqf index caf34a7a8..e95072d02 100644 --- a/Missionframework/modules/01_core/fnc/fn_core_handleVehicleSpawn.sqf +++ b/Missionframework/modules/01_core/fnc/fn_core_handleVehicleSpawn.sqf @@ -32,7 +32,7 @@ switch(typeOf _vehicle) do { // Add redeploy action globaly and for JIP [ _vehicle, - [localize "STR_ACTION_REDEPLOY", {[] spawn KPLIB_fnc_core_redeploy}, nil, -801, false, true, "", "_target == _originalTarget", 10] + [localize "STR_ACTION_REDEPLOY", {[] spawn KPLIB_fnc_core_redeploy}, nil, -801, false, true, "", "_this == vehicle _this", 10] ] remoteExecCall ["addAction", 0, true]; }; }; From 7dd71d00e8e9fd310858236831b673cc830fdd5e Mon Sep 17 00:00:00 2001 From: Filip Maciejewski Date: Tue, 11 Sep 2018 23:22:00 +0200 Subject: [PATCH 4/4] Make player var "KPLIB_fob" global --- Missionframework/modules/01_core/scripts/server/eventLoop.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Missionframework/modules/01_core/scripts/server/eventLoop.sqf b/Missionframework/modules/01_core/scripts/server/eventLoop.sqf index a7eabe2e4..22e0c4e77 100644 --- a/Missionframework/modules/01_core/scripts/server/eventLoop.sqf +++ b/Missionframework/modules/01_core/scripts/server/eventLoop.sqf @@ -40,7 +40,7 @@ private _initFunction = { // Set fob variable on player if it has changed if !(_currentPlayer getVariable ["KPLIB_fob", ""] isEqualTo _playerFob) then { - _currentPlayer setVariable ["KPLIB_fob", _playerFob]; + _currentPlayer setVariable ["KPLIB_fob", _playerFob, true]; // Emit event ["KPLIB_player_fob", [_currentPlayer, _playerFob]] call CBA_fnc_globalEvent; };