From 5fb9a8b6637456e349b2fa1d3c79c105b923702e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ozan=20E=C4=9Fitmen?= Date: Sat, 16 Sep 2017 20:58:43 +0300 Subject: [PATCH 1/9] Add load in child actions to medical & captive TODO: captive seems to rely on it's own functions and standards for loading people. Make it more like medical & use common's functions --- addons/captives/CfgVehicles.hpp | 1 + addons/captives/XEH_PREP.hpp | 2 +- .../functions/fnc_addLoadCaptiveActions.sqf | 42 +++++++++++++++++++ .../captives/functions/fnc_canLoadCaptive.sqf | 30 ++++++------- .../captives/functions/fnc_doLoadCaptive.sqf | 27 +++++------- .../fnc_findEmptyNonFFVCargoSeat.sqf | 6 +-- .../functions/fnc_addCargoVehiclesActions.sqf | 5 +-- addons/common/XEH_PREP.hpp | 1 + addons/common/functions/fnc_loadPerson.sqf | 21 ++++------ .../functions/fnc_nearestVehiclesFreeSeat.sqf | 21 ++++++++++ addons/medical/CfgVehicles.hpp | 5 ++- addons/medical/XEH_PREP.hpp | 1 + .../medical/functions/fnc_actionLoadUnit.sqf | 7 ++-- .../functions/fnc_addLoadPatientActions.sqf | 42 +++++++++++++++++++ 14 files changed, 152 insertions(+), 59 deletions(-) create mode 100644 addons/captives/functions/fnc_addLoadCaptiveActions.sqf create mode 100644 addons/common/functions/fnc_nearestVehiclesFreeSeat.sqf create mode 100644 addons/medical/functions/fnc_addLoadPatientActions.sqf diff --git a/addons/captives/CfgVehicles.hpp b/addons/captives/CfgVehicles.hpp index 5f33739e494..08a7f837ba8 100644 --- a/addons/captives/CfgVehicles.hpp +++ b/addons/captives/CfgVehicles.hpp @@ -51,6 +51,7 @@ class CfgVehicles { showDisabled = 0; icon = QPATHTOF(UI\captive_ca.paa); priority = 2.2; + insertChildren = QUOTE([ARR_2(_player, _target)] call DFUNC(addLoadCaptiveActions)); }; class GVAR(UnloadCaptive) { displayName = CSTRING(UnloadCaptive); diff --git a/addons/captives/XEH_PREP.hpp b/addons/captives/XEH_PREP.hpp index bfb1ade5e08..c2be69c89cb 100644 --- a/addons/captives/XEH_PREP.hpp +++ b/addons/captives/XEH_PREP.hpp @@ -1,4 +1,4 @@ - +PREP(addLoadCaptiveActions); PREP(canApplyHandcuffs); PREP(canEscortCaptive); PREP(canFriskPerson); diff --git a/addons/captives/functions/fnc_addLoadCaptiveActions.sqf b/addons/captives/functions/fnc_addLoadCaptiveActions.sqf new file mode 100644 index 00000000000..315dbc80509 --- /dev/null +++ b/addons/captives/functions/fnc_addLoadCaptiveActions.sqf @@ -0,0 +1,42 @@ +/* + * Author: 654wak654 + * Adds child actions to the "load captive" action for near vehicles + * + * Arguments: + * 0: The player + * 1: The captive + * + * Return Value: + * The child actions + * + * Example: + * [bob, kevin] call ace_medical_fnc_addLoadCaptiveActions + * + * Public: No + */ +#include "script_component.hpp" + +params ["_caller", "_target"]; + +private _statement = { + params ["_target", "_player", "_vehicle"]; + [_player, _target, _vehicle] call FUNC(doLoadCaptive); +}; + +private _actions = []; + +{ + private _config = configFile >> "CfgVehicles" >> typeOf _x; + + private _name = getText (_config >> "displayName"); + private _ownerName = [_x, true] call EFUNC(common,getName); + if (_ownerName != "") then { + _name = format ["%1 (%2)", _name, _ownerName]; + }; + private _icon = (getText (_config >> "icon")) call BIS_fnc_textureVehicleIcon; + + private _action = [format ["%1", _x], _name, _icon, _statement, {true}, {}, _x] call EFUNC(interact_menu,createAction); + _actions pushBack _action; +} forEach (_target call EFUNC(common,nearestVehiclesFreeSeat)); + +_actions diff --git a/addons/captives/functions/fnc_canLoadCaptive.sqf b/addons/captives/functions/fnc_canLoadCaptive.sqf index a59c2e3be65..21686cb3163 100644 --- a/addons/captives/functions/fnc_canLoadCaptive.sqf +++ b/addons/captives/functions/fnc_canLoadCaptive.sqf @@ -4,43 +4,39 @@ * * Arguments: * 0: Unit that wants to load a captive - * 1: A captive. ObjNull for the first escorted captive (may be null) - * 2: Vehicle to load the captive into. ObjNull for the nearest vehicle (may be null) + * 1: A captive. objNull for the first escorted captive + * 2: Vehicle to load the captive into. objNull for the nearest vehicle * * Return Value: - * The return value + * Can load captive * * Example: - * [player, bob, car] call ACE_captives_fnc_canLoadCaptive + * [bob, tom, car] call ace_captives_fnc_canLoadCaptive * * Public: No */ #include "script_component.hpp" -params ["_unit", "_target","_vehicle"]; +params ["_unit", "_target", "_vehicle"]; -if ((isNull _target) && {_unit getVariable [QGVAR(isEscorting), false]}) then { - //Looking at a vehicle while escorting, get target from attached objects: +if (isNull _target && {_unit getVariable [QGVAR(isEscorting), false]}) then { + // Looking at a vehicle while escorting, get target from attached objects: { if (_x getVariable [QGVAR(isHandcuffed), false]) exitWith { _target = _x; }; } forEach (attachedObjects _unit); }; -if ((isNull _target) || {(vehicle _target) != _target} || {!(_target getVariable [QGVAR(isHandcuffed), false])}) exitWith {false}; +if (isNull _target || {(vehicle _target) != _target} || {!(_target getVariable [QGVAR(isHandcuffed), false])}) exitWith {false}; if (isNull _vehicle) then { - //Looking at a captive unit, search for nearby vehicles with valid seats: - { - if ((_x emptyPositions "cargo") > 0) exitWith { - _vehicle = _x; - }; - } forEach (nearestObjects [_unit, ["Car", "Tank", "Helicopter", "Plane", "Ship"], 10]); + // Looking at a captive unit, get nearest vehicle with valid seat: + _vehicle = (_target call EFUNC(common,nearestVehiclesFreeSeat)) param [0, objNull]; } else { - //We have a vehicle picked, make sure it has empty seats: - if ((_vehicle emptyPositions "cargo") == 0) then { + // We have a vehicle picked, make sure it has empty seats: + if (_vehicle emptyPositions "cargo" == 0 && {_vehicle emptyPositions "gunner" == 0}) then { _vehicle = objNull; }; }; -(!isNull _vehicle) +!isNull _vehicle diff --git a/addons/captives/functions/fnc_doLoadCaptive.sqf b/addons/captives/functions/fnc_doLoadCaptive.sqf index 82e446b460c..c47cc389d4a 100644 --- a/addons/captives/functions/fnc_doLoadCaptive.sqf +++ b/addons/captives/functions/fnc_doLoadCaptive.sqf @@ -4,42 +4,37 @@ * * Arguments: * 0: Unit that wants to load a captive - * 1: A captive. ObjNull for the first escorted captive - * 2: Vehicle to load the captive into. ObjNull for the nearest vehicle + * 1: A captive. objNull for the first escorted captive + * 2: Vehicle to load the captive into. objNull for the nearest vehicle * * Return Value: * None * * Example: - * [bob, tom, car] call ACE_captives_fnc_doLoadCaptive + * [bob, tom, car] call ace_captives_fnc_doLoadCaptive * * Public: No */ #include "script_component.hpp" -params ["_unit", "_target","_vehicle"]; +params ["_unit", "_target", "_vehicle"]; -if ((isNull _target) && {_unit getVariable [QGVAR(isEscorting), false]}) then { - //Looking at a vehicle while escorting, get target from attached objects: +if (isNull _target && {_unit getVariable [QGVAR(isEscorting), false]}) then { + // Looking at a vehicle while escorting, get target from attached objects: { if (_x getVariable [QGVAR(isHandcuffed), false]) exitWith { _target = _x; }; } forEach (attachedObjects _unit); }; -if ((isNull _target) || {(vehicle _target) != _target} || {!(_target getVariable [QGVAR(isHandcuffed), false])}) exitWith {WARNING("");}; +if (isNull _target || {(vehicle _target) != _target} || {!(_target getVariable [QGVAR(isHandcuffed), false])}) exitWith {WARNING("");}; if (isNull _vehicle) then { - //Looking at a captive unit, search for nearby vehicles with valid seats: - { - // if (([_x] call FUNC(findEmptyNonFFVCargoSeat)) != -1) exitWith { - if ((_x emptyPositions "cargo") > 0) exitWith { - _vehicle = _x; - }; - } forEach (nearestObjects [_unit, ["Car", "Tank", "Helicopter", "Plane", "Ship"], 10]); + // Looking at a captive unit, get nearest vehicle with valid seat: + _vehicle = (_target call EFUNC(common,nearestVehiclesFreeSeat)) param [0, objNull]; } else { - // if (([_vehicle] call FUNC(findEmptyNonFFVCargoSeat)) == -1) then { - if ((_vehicle emptyPositions "cargo") == 0) then { + // We have a vehicle picked, make sure it has empty seats: + if (_vehicle emptyPositions "cargo" == 0 && {_vehicle emptyPositions "gunner" == 0}) then { _vehicle = objNull; }; }; diff --git a/addons/captives/functions/fnc_findEmptyNonFFVCargoSeat.sqf b/addons/captives/functions/fnc_findEmptyNonFFVCargoSeat.sqf index 63792a7c552..91bb800c052 100644 --- a/addons/captives/functions/fnc_findEmptyNonFFVCargoSeat.sqf +++ b/addons/captives/functions/fnc_findEmptyNonFFVCargoSeat.sqf @@ -18,20 +18,18 @@ params ["_vehicle"]; TRACE_1("params", _vehicle); -private _vehicleConfig = configFile >> "CfgVehicles" >> (typeOf _vehicle); - scopeName "main"; { _x params ["_unit", "_role", "_cargoIndex", "_turretPath", "_isPersonTurret"]; - if ((isNull _unit) && {_role == "cargo"} && {_cargoIndex > -1} && {!_isPersonTurret}) then { + if (isNull _unit && {_role == "cargo"} && {_cargoIndex > -1} && {!_isPersonTurret}) then { [_cargoIndex, false] breakOut "main"; }; } forEach (fullCrew [_vehicle, "", true]); { _x params ["_unit", "_role", "_cargoIndex", "_turretPath", "_isPersonTurret"]; - if ((isNull _unit) && {_cargoIndex > -1}) then { + if (isNull _unit && {_cargoIndex > -1}) then { [_cargoIndex, true] breakOut "main"; }; } forEach (fullCrew [_vehicle, "", true]); diff --git a/addons/cargo/functions/fnc_addCargoVehiclesActions.sqf b/addons/cargo/functions/fnc_addCargoVehiclesActions.sqf index 176b2f31b6f..7734acb0712 100644 --- a/addons/cargo/functions/fnc_addCargoVehiclesActions.sqf +++ b/addons/cargo/functions/fnc_addCargoVehiclesActions.sqf @@ -19,8 +19,7 @@ params ["_target", "_player"]; private _statement = { - params ["_target", "_player", "_params"]; - _params params ["_vehicle"]; + params ["_target", "_player", "_vehicle"]; [_player, _target, _vehicle] call FUNC(startLoadIn); }; @@ -37,7 +36,7 @@ private _actions = []; _name = format ["%1 (%2)", _name, _ownerName]; }; private _icon = (getText (_config >> "icon")) call BIS_fnc_textureVehicleIcon; - private _action = [format ["%1", _x], _name, _icon, _statement, {true}, {}, [_x]] call EFUNC(interact_menu,createAction); + private _action = [format ["%1", _x], _name, _icon, _statement, {true}, {}, _x] call EFUNC(interact_menu,createAction); _actions pushBack [_action, [], _target]; }; } forEach (nearestObjects [_player, GVAR(cargoHolderTypes), MAX_LOAD_DISTANCE]); diff --git a/addons/common/XEH_PREP.hpp b/addons/common/XEH_PREP.hpp index 384a548fde2..ebdaabdf4a4 100644 --- a/addons/common/XEH_PREP.hpp +++ b/addons/common/XEH_PREP.hpp @@ -115,6 +115,7 @@ PREP(moduleLSDVehicles); PREP(muteUnit); PREP(muteUnitHandleInitPost); PREP(muteUnitHandleRespawn); +PREP(nearestVehiclesFreeSeat); PREP(numberToDigits); PREP(numberToDigitsString); PREP(numberToString); diff --git a/addons/common/functions/fnc_loadPerson.sqf b/addons/common/functions/fnc_loadPerson.sqf index ae762b82be3..cc2d1564b1d 100644 --- a/addons/common/functions/fnc_loadPerson.sqf +++ b/addons/common/functions/fnc_loadPerson.sqf @@ -1,13 +1,14 @@ /* * Author: Glowbal - * Loads a specified unit into any nearby vehicle + * Loads a specified unit into any nearby vehicle, or _vehicle parameter. * * Arguments: * 0: Unit that will load * 1: Unit to be loaded + * 2: Vehicle that the unit will be loaded in (default: objNull) * * Return Value: - * the vehicle that the unitToBeloaded has been loaded in. Returns ObjNull if function failed + * The vehicle that the unitToBeloaded has been loaded in. Returns objNull if function failed * * Example: * [bob, kevin] call ace_common_fnc_loadPerson @@ -18,20 +19,14 @@ #define GROUP_SWITCH_ID QFUNC(loadPerson) -params ["_caller", "_unit"]; - -private _vehicle = objNull; +params ["_caller", "_unit", ["_vehicle", objNull]]; if (!([_caller, _unit, ["isNotDragging", "isNotCarrying"]] call FUNC(canInteractWith)) || {_caller == _unit}) exitWith {_vehicle}; -private _nearVehicles = nearestObjects [_unit, ["Car", "Air", "Tank", "Ship_F","Pod_Heli_Transport_04_crewed_base_F"], 10]; - -{ - TRACE_1("",_x); - if ((_x emptyPositions "cargo" > 0) || {_x emptyPositions "gunner" > 0}) exitWith { - _vehicle = _x; - }; -} forEach _nearVehicles; +// Try to use nearest vehicle if a vehicle hasn't been supplied +if (isNull _vehicle) then { + _vehicle = ([_unit] call FUNC(nearestVehiclesFreeSeat)) param [0, objNull]; +}; if (!isNull _vehicle) then { [_unit, true, GROUP_SWITCH_ID, side group _caller] call FUNC(switchToGroupSide); diff --git a/addons/common/functions/fnc_nearestVehiclesFreeSeat.sqf b/addons/common/functions/fnc_nearestVehiclesFreeSeat.sqf new file mode 100644 index 00000000000..ef1255db81d --- /dev/null +++ b/addons/common/functions/fnc_nearestVehiclesFreeSeat.sqf @@ -0,0 +1,21 @@ +/* + * Author: 654wak654 + * Returns a list of vehicles near given unit that the unit can be a passenger in. + * + * Arguments: + * 0: The unit + * + * Return Value: + * Nearest vehicles with a free seat + * + * Example: + * [bob] call ace_common_fnc_nearestVehiclesFreeSeat + * + * Public: No + */ +#include "script_component.hpp" + +params ["_unit"]; + +private _nearVehicles = nearestObjects [_unit, ["Car", "Air", "Tank", "Ship_F", "Pod_Heli_Transport_04_crewed_base_F"], 10]; +_nearVehicles select {(_x emptyPositions "cargo" > 0) || {_x emptyPositions "gunner" > 0}} diff --git a/addons/medical/CfgVehicles.hpp b/addons/medical/CfgVehicles.hpp index 3d868e74ae0..57b397810f5 100644 --- a/addons/medical/CfgVehicles.hpp +++ b/addons/medical/CfgVehicles.hpp @@ -545,17 +545,18 @@ class CfgVehicles { class GVAR(loadPatient) { displayName = CSTRING(LoadPatient); distance = 5; - condition = QUOTE(_target getVariable[ARR_2(QUOTE(QUOTE(ACE_isUnconscious)),false)] && vehicle _target == _target); + condition = QUOTE(_target getVariable [ARR_2(QUOTE(QUOTE(ACE_isUnconscious)),false)] && vehicle _target == _target); statement = QUOTE([ARR_2(_player, _target)] call DFUNC(actionLoadUnit)); showDisabled = 0; priority = 2; icon = QPATHTOF(UI\icons\medical_cross.paa); exceptions[] = {"isNotDragging", "isNotCarrying", "isNotSwimming"}; + insertChildren = QUOTE([ARR_2(_player, _target)] call DFUNC(addLoadPatientActions)); }; class GVAR(UnLoadPatient) { displayName = CSTRING(UnloadPatient); distance = 5; - condition = QUOTE(_target getVariable[ARR_2(QUOTE(QUOTE(ACE_isUnconscious)),false)] && vehicle _target != _target); + condition = QUOTE(_target getVariable [ARR_2(QUOTE(QUOTE(ACE_isUnconscious)),false)] && vehicle _target != _target); statement = QUOTE([ARR_2(_player, _target)] call DFUNC(actionUnloadUnit)); showDisabled = 0; priority = 2; diff --git a/addons/medical/XEH_PREP.hpp b/addons/medical/XEH_PREP.hpp index b754f00f5de..a343de8d734 100644 --- a/addons/medical/XEH_PREP.hpp +++ b/addons/medical/XEH_PREP.hpp @@ -11,6 +11,7 @@ PREP(actionLoadUnit); PREP(actionUnloadUnit); PREP(addDamageToUnit); PREP(addHeartRateAdjustment); +PREP(addLoadPatientActions); PREP(addToInjuredCollection); PREP(addToLog); PREP(addToTriageCard); diff --git a/addons/medical/functions/fnc_actionLoadUnit.sqf b/addons/medical/functions/fnc_actionLoadUnit.sqf index 11a875bf2f2..264fb72a4b5 100644 --- a/addons/medical/functions/fnc_actionLoadUnit.sqf +++ b/addons/medical/functions/fnc_actionLoadUnit.sqf @@ -1,10 +1,11 @@ /* * Author: Glowbal - * Action for loading an unconscious or dead unit in the nearest vechile + * Action for loading an unconscious or dead unit in the nearest vehicle, or _vehicle if given. * * Arguments: * 0: The medic * 1: The patient + * 2: The vehicle (default: objNull) * * Return Value: * None @@ -17,7 +18,7 @@ #include "script_component.hpp" -params ["_caller", "_target"]; +params ["_caller", "_target", ["_vehicle", objNull]]; if ([_target] call EFUNC(common,isAwake)) exitWith { [QEGVAR(common,displayTextStructured), [[LSTRING(CanNotLoaded), [_target] call EFUNC(common,getName)], 1.5, _caller], [_caller]] call CBA_fnc_targetEvent; @@ -29,4 +30,4 @@ if ([_target] call FUNC(isBeingDragged)) then { [_caller, _target] call EFUNC(dragging,dropObject); }; -private _vehicle = [_caller, _target] call EFUNC(common,loadPerson); +[_caller, _target, _vehicle] call EFUNC(common,loadPerson); diff --git a/addons/medical/functions/fnc_addLoadPatientActions.sqf b/addons/medical/functions/fnc_addLoadPatientActions.sqf new file mode 100644 index 00000000000..8b71eece34e --- /dev/null +++ b/addons/medical/functions/fnc_addLoadPatientActions.sqf @@ -0,0 +1,42 @@ +/* + * Author: 654wak654 + * Adds child actions to the "load patient" action for near vehicles + * + * Arguments: + * 0: The medic + * 1: The patient + * + * Return Value: + * The child actions + * + * Example: + * [bob, kevin] call ace_medical_fnc_addLoadPatientActions + * + * Public: No + */ +#include "script_component.hpp" + +params ["_caller", "_target"]; + +private _statement = { + params ["_target", "_player", "_vehicle"]; + [_player, _target, _vehicle] call FUNC(actionLoadUnit); +}; + +private _actions = []; + +{ + private _config = configFile >> "CfgVehicles" >> typeOf _x; + + private _name = getText (_config >> "displayName"); + private _ownerName = [_x, true] call EFUNC(common,getName); + if (_ownerName != "") then { + _name = format ["%1 (%2)", _name, _ownerName]; + }; + private _icon = (getText (_config >> "icon")) call BIS_fnc_textureVehicleIcon; + + private _action = [format ["%1", _x], _name, _icon, _statement, {true}, {}, _x] call EFUNC(interact_menu,createAction); + _actions pushBack _action; +} forEach (_target call EFUNC(common,nearestVehiclesFreeSeat)); + +_actions From bcca259068cd73a0203d689b382ee155f87a6c9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ozan=20E=C4=9Fitmen?= Date: Sat, 16 Sep 2017 21:29:03 +0300 Subject: [PATCH 2/9] Add actions with proper structure --- addons/captives/functions/fnc_addLoadCaptiveActions.sqf | 2 +- addons/medical/functions/fnc_addLoadPatientActions.sqf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/captives/functions/fnc_addLoadCaptiveActions.sqf b/addons/captives/functions/fnc_addLoadCaptiveActions.sqf index 315dbc80509..a9d165c7d70 100644 --- a/addons/captives/functions/fnc_addLoadCaptiveActions.sqf +++ b/addons/captives/functions/fnc_addLoadCaptiveActions.sqf @@ -36,7 +36,7 @@ private _actions = []; private _icon = (getText (_config >> "icon")) call BIS_fnc_textureVehicleIcon; private _action = [format ["%1", _x], _name, _icon, _statement, {true}, {}, _x] call EFUNC(interact_menu,createAction); - _actions pushBack _action; + _actions pushBack [_action, [], _target]; } forEach (_target call EFUNC(common,nearestVehiclesFreeSeat)); _actions diff --git a/addons/medical/functions/fnc_addLoadPatientActions.sqf b/addons/medical/functions/fnc_addLoadPatientActions.sqf index 8b71eece34e..3f6db378ff4 100644 --- a/addons/medical/functions/fnc_addLoadPatientActions.sqf +++ b/addons/medical/functions/fnc_addLoadPatientActions.sqf @@ -36,7 +36,7 @@ private _actions = []; private _icon = (getText (_config >> "icon")) call BIS_fnc_textureVehicleIcon; private _action = [format ["%1", _x], _name, _icon, _statement, {true}, {}, _x] call EFUNC(interact_menu,createAction); - _actions pushBack _action; + _actions pushBack [_action, [], _target]; } forEach (_target call EFUNC(common,nearestVehiclesFreeSeat)); _actions From b5b549092c91f93f6c8e8c250ccb6e9e49a84d97 Mon Sep 17 00:00:00 2001 From: Dystopian Date: Sun, 17 Sep 2017 04:53:41 +0300 Subject: [PATCH 3/9] Move vehicles actions code to common function --- .../functions/fnc_addLoadCaptiveActions.sqf | 18 +--------- .../functions/fnc_addCargoVehiclesActions.sqf | 24 ++++---------- addons/interact_menu/XEH_PREP.hpp | 1 + .../functions/fnc_createVehiclesActions.sqf | 33 +++++++++++++++++++ .../functions/fnc_addLoadPatientActions.sqf | 18 +--------- 5 files changed, 42 insertions(+), 52 deletions(-) create mode 100644 addons/interact_menu/functions/fnc_createVehiclesActions.sqf diff --git a/addons/captives/functions/fnc_addLoadCaptiveActions.sqf b/addons/captives/functions/fnc_addLoadCaptiveActions.sqf index a9d165c7d70..4d9639f9948 100644 --- a/addons/captives/functions/fnc_addLoadCaptiveActions.sqf +++ b/addons/captives/functions/fnc_addLoadCaptiveActions.sqf @@ -23,20 +23,4 @@ private _statement = { [_player, _target, _vehicle] call FUNC(doLoadCaptive); }; -private _actions = []; - -{ - private _config = configFile >> "CfgVehicles" >> typeOf _x; - - private _name = getText (_config >> "displayName"); - private _ownerName = [_x, true] call EFUNC(common,getName); - if (_ownerName != "") then { - _name = format ["%1 (%2)", _name, _ownerName]; - }; - private _icon = (getText (_config >> "icon")) call BIS_fnc_textureVehicleIcon; - - private _action = [format ["%1", _x], _name, _icon, _statement, {true}, {}, _x] call EFUNC(interact_menu,createAction); - _actions pushBack [_action, [], _target]; -} forEach (_target call EFUNC(common,nearestVehiclesFreeSeat)); - -_actions +[_target call EFUNC(common,nearestVehiclesFreeSeat), _statement, _target] call EFUNC(interact_menu,createVehiclesActions) diff --git a/addons/cargo/functions/fnc_addCargoVehiclesActions.sqf b/addons/cargo/functions/fnc_addCargoVehiclesActions.sqf index 7734acb0712..9b395ec4519 100644 --- a/addons/cargo/functions/fnc_addCargoVehiclesActions.sqf +++ b/addons/cargo/functions/fnc_addCargoVehiclesActions.sqf @@ -10,7 +10,7 @@ * Children actions * * Example: - * [target, player] call ace_cargo_fnc_addCargoVehiclesActions + * [cursorObject, player] call ace_cargo_fnc_addCargoVehiclesActions * * Public: No */ @@ -23,22 +23,10 @@ private _statement = { [_player, _target, _vehicle] call FUNC(startLoadIn); }; -private _actions = []; - -{ - private _config = configFile >> "CfgVehicles" >> typeOf _x; +private _vehicles = (nearestObjects [_player, GVAR(cargoHolderTypes), MAX_LOAD_DISTANCE]) select { + private _hasCargoConfig = 1 == getNumber (configFile >> "CfgVehicles" >> typeOf _x >> QGVAR(hasCargo)); private _hasCargoPublic = _x getVariable [QGVAR(hasCargo), false]; - private _hasCargoConfig = getNumber (_config >> QGVAR(hasCargo)) == 1; - if ((_hasCargoPublic || _hasCargoConfig) && {_x != _target}) then { - private _name = getText (_config >> "displayName"); - private _ownerName = [_x, true] call EFUNC(common,getName); - if ("" != _ownerName) then { - _name = format ["%1 (%2)", _name, _ownerName]; - }; - private _icon = (getText (_config >> "icon")) call BIS_fnc_textureVehicleIcon; - private _action = [format ["%1", _x], _name, _icon, _statement, {true}, {}, _x] call EFUNC(interact_menu,createAction); - _actions pushBack [_action, [], _target]; - }; -} forEach (nearestObjects [_player, GVAR(cargoHolderTypes), MAX_LOAD_DISTANCE]); + (_hasCargoConfig || {_hasCargoPublic}) && {_x != _target} +}; -_actions +[_vehicles, _statement, _target] call EFUNC(interact_menu,createVehiclesActions) diff --git a/addons/interact_menu/XEH_PREP.hpp b/addons/interact_menu/XEH_PREP.hpp index 55c35d54df1..7ee668a583f 100644 --- a/addons/interact_menu/XEH_PREP.hpp +++ b/addons/interact_menu/XEH_PREP.hpp @@ -7,6 +7,7 @@ PREP(compileMenuSelfAction); PREP(compileMenuZeus); PREP(collectActiveActionTree); PREP(createAction); +PREP(createVehiclesActions); PREP(ctrlSetParsedTextCached); PREP(findActionNode); PREP(handleEscapeMenu); diff --git a/addons/interact_menu/functions/fnc_createVehiclesActions.sqf b/addons/interact_menu/functions/fnc_createVehiclesActions.sqf new file mode 100644 index 00000000000..6bdc941118d --- /dev/null +++ b/addons/interact_menu/functions/fnc_createVehiclesActions.sqf @@ -0,0 +1,33 @@ +/* + * Author: Dystopian + * Creates child actions for vehicle list. + * Statement gets vehicle as action parameter. + * + * Arguments: + * 0: Vehicle list + * 1: Statement + * 2: Target + * + * Return Value: + * Array of actions + * + * Example: + * [nearestObjects [player, ["AllVehicles"], 10], {}, cursorObject] call ace_interact_menu_fnc_createVehiclesActions + * + * Public: No + */ +#include "script_component.hpp" + +params ["_vehicles", "_statement", "_target"]; + +_vehicles apply { + private _config = configFile >> "CfgVehicles" >> typeOf _x; + private _name = getText (_config >> "displayName"); + private _ownerName = [_x, true] call EFUNC(common,getName); + if ("" != _ownerName) then { + _name = format ["%1 (%2)", _name, _ownerName]; + }; + private _icon = (getText (_config >> "icon")) call BIS_fnc_textureVehicleIcon; + private _action = [format ["%1", _x], _name, _icon, _statement, {true}, {}, _x] call EFUNC(interact_menu,createAction); + [_action, [], _target] +} diff --git a/addons/medical/functions/fnc_addLoadPatientActions.sqf b/addons/medical/functions/fnc_addLoadPatientActions.sqf index 3f6db378ff4..b956d8634df 100644 --- a/addons/medical/functions/fnc_addLoadPatientActions.sqf +++ b/addons/medical/functions/fnc_addLoadPatientActions.sqf @@ -23,20 +23,4 @@ private _statement = { [_player, _target, _vehicle] call FUNC(actionLoadUnit); }; -private _actions = []; - -{ - private _config = configFile >> "CfgVehicles" >> typeOf _x; - - private _name = getText (_config >> "displayName"); - private _ownerName = [_x, true] call EFUNC(common,getName); - if (_ownerName != "") then { - _name = format ["%1 (%2)", _name, _ownerName]; - }; - private _icon = (getText (_config >> "icon")) call BIS_fnc_textureVehicleIcon; - - private _action = [format ["%1", _x], _name, _icon, _statement, {true}, {}, _x] call EFUNC(interact_menu,createAction); - _actions pushBack [_action, [], _target]; -} forEach (_target call EFUNC(common,nearestVehiclesFreeSeat)); - -_actions +[_target call EFUNC(common,nearestVehiclesFreeSeat), _statement, _target] call EFUNC(interact_menu,createVehiclesActions) From 3203b3e1378ac420b4117a2f2ae58e07e9a5f98b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ozan=20E=C4=9Fitmen?= Date: Sun, 17 Sep 2017 10:48:03 +0300 Subject: [PATCH 4/9] Simplify code in config, Fix docs --- addons/captives/CfgVehicles.hpp | 2 +- addons/captives/functions/fnc_addLoadCaptiveActions.sqf | 6 +++--- addons/medical/CfgVehicles.hpp | 2 +- addons/medical/functions/fnc_addLoadPatientActions.sqf | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/addons/captives/CfgVehicles.hpp b/addons/captives/CfgVehicles.hpp index 08a7f837ba8..893197f220f 100644 --- a/addons/captives/CfgVehicles.hpp +++ b/addons/captives/CfgVehicles.hpp @@ -51,7 +51,7 @@ class CfgVehicles { showDisabled = 0; icon = QPATHTOF(UI\captive_ca.paa); priority = 2.2; - insertChildren = QUOTE([ARR_2(_player, _target)] call DFUNC(addLoadCaptiveActions)); + insertChildren = QUOTE(call DFUNC(addLoadCaptiveActions)); }; class GVAR(UnloadCaptive) { displayName = CSTRING(UnloadCaptive); diff --git a/addons/captives/functions/fnc_addLoadCaptiveActions.sqf b/addons/captives/functions/fnc_addLoadCaptiveActions.sqf index 4d9639f9948..cc4186c9a07 100644 --- a/addons/captives/functions/fnc_addLoadCaptiveActions.sqf +++ b/addons/captives/functions/fnc_addLoadCaptiveActions.sqf @@ -1,13 +1,13 @@ /* * Author: 654wak654 - * Adds child actions to the "load captive" action for near vehicles + * Adds child actions to the "load captive" action for near vehicles. * * Arguments: * 0: The player * 1: The captive * * Return Value: - * The child actions + * The child actions * * Example: * [bob, kevin] call ace_medical_fnc_addLoadCaptiveActions @@ -16,7 +16,7 @@ */ #include "script_component.hpp" -params ["_caller", "_target"]; +params ["_target", "_caller"]; private _statement = { params ["_target", "_player", "_vehicle"]; diff --git a/addons/medical/CfgVehicles.hpp b/addons/medical/CfgVehicles.hpp index 57b397810f5..43c4d102d9c 100644 --- a/addons/medical/CfgVehicles.hpp +++ b/addons/medical/CfgVehicles.hpp @@ -551,7 +551,7 @@ class CfgVehicles { priority = 2; icon = QPATHTOF(UI\icons\medical_cross.paa); exceptions[] = {"isNotDragging", "isNotCarrying", "isNotSwimming"}; - insertChildren = QUOTE([ARR_2(_player, _target)] call DFUNC(addLoadPatientActions)); + insertChildren = QUOTE(call DFUNC(addLoadPatientActions)); }; class GVAR(UnLoadPatient) { displayName = CSTRING(UnloadPatient); diff --git a/addons/medical/functions/fnc_addLoadPatientActions.sqf b/addons/medical/functions/fnc_addLoadPatientActions.sqf index b956d8634df..3b1e5ad976a 100644 --- a/addons/medical/functions/fnc_addLoadPatientActions.sqf +++ b/addons/medical/functions/fnc_addLoadPatientActions.sqf @@ -1,13 +1,13 @@ /* * Author: 654wak654 - * Adds child actions to the "load patient" action for near vehicles + * Adds child actions to the "load patient" action for near vehicles. * * Arguments: * 0: The medic * 1: The patient * * Return Value: - * The child actions + * The child actions * * Example: * [bob, kevin] call ace_medical_fnc_addLoadPatientActions @@ -16,7 +16,7 @@ */ #include "script_component.hpp" -params ["_caller", "_target"]; +params ["_target", "_caller"]; private _statement = { params ["_target", "_player", "_vehicle"]; From eeaf00cd452cb00ab4a3118e3f6804bef023ef23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ozan=20E=C4=9Fitmen?= Date: Sun, 17 Sep 2017 11:54:28 +0300 Subject: [PATCH 5/9] Remove unused vars --- addons/captives/functions/fnc_addLoadCaptiveActions.sqf | 7 +++---- addons/cargo/functions/fnc_addCargoVehiclesActions.sqf | 5 ++--- addons/medical/functions/fnc_addLoadPatientActions.sqf | 7 +++---- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/addons/captives/functions/fnc_addLoadCaptiveActions.sqf b/addons/captives/functions/fnc_addLoadCaptiveActions.sqf index cc4186c9a07..b68499942cb 100644 --- a/addons/captives/functions/fnc_addLoadCaptiveActions.sqf +++ b/addons/captives/functions/fnc_addLoadCaptiveActions.sqf @@ -3,20 +3,19 @@ * Adds child actions to the "load captive" action for near vehicles. * * Arguments: - * 0: The player - * 1: The captive + * 0: The captive * * Return Value: * The child actions * * Example: - * [bob, kevin] call ace_medical_fnc_addLoadCaptiveActions + * [kevin] call ace_medical_fnc_addLoadCaptiveActions * * Public: No */ #include "script_component.hpp" -params ["_target", "_caller"]; +params ["_target"]; private _statement = { params ["_target", "_player", "_vehicle"]; diff --git a/addons/cargo/functions/fnc_addCargoVehiclesActions.sqf b/addons/cargo/functions/fnc_addCargoVehiclesActions.sqf index 9b395ec4519..d4e48da6592 100644 --- a/addons/cargo/functions/fnc_addCargoVehiclesActions.sqf +++ b/addons/cargo/functions/fnc_addCargoVehiclesActions.sqf @@ -4,7 +4,6 @@ * * Arguments: * 0: Target - * 1: Player * * Return Value: * Children actions @@ -16,14 +15,14 @@ */ #include "script_component.hpp" -params ["_target", "_player"]; +params ["_target"]; private _statement = { params ["_target", "_player", "_vehicle"]; [_player, _target, _vehicle] call FUNC(startLoadIn); }; -private _vehicles = (nearestObjects [_player, GVAR(cargoHolderTypes), MAX_LOAD_DISTANCE]) select { +private _vehicles = (nearestObjects [_target, GVAR(cargoHolderTypes), MAX_LOAD_DISTANCE]) select { private _hasCargoConfig = 1 == getNumber (configFile >> "CfgVehicles" >> typeOf _x >> QGVAR(hasCargo)); private _hasCargoPublic = _x getVariable [QGVAR(hasCargo), false]; (_hasCargoConfig || {_hasCargoPublic}) && {_x != _target} diff --git a/addons/medical/functions/fnc_addLoadPatientActions.sqf b/addons/medical/functions/fnc_addLoadPatientActions.sqf index 3b1e5ad976a..96d06ed4322 100644 --- a/addons/medical/functions/fnc_addLoadPatientActions.sqf +++ b/addons/medical/functions/fnc_addLoadPatientActions.sqf @@ -3,20 +3,19 @@ * Adds child actions to the "load patient" action for near vehicles. * * Arguments: - * 0: The medic - * 1: The patient + * 0: The patient * * Return Value: * The child actions * * Example: - * [bob, kevin] call ace_medical_fnc_addLoadPatientActions + * [kevin] call ace_medical_fnc_addLoadPatientActions * * Public: No */ #include "script_component.hpp" -params ["_target", "_caller"]; +params ["_target"]; private _statement = { params ["_target", "_player", "_vehicle"]; From 72f3bd17add53771b34af2e76d6606b5c40eb3ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ozan=20E=C4=9Fitmen?= Date: Sun, 17 Sep 2017 11:59:52 +0300 Subject: [PATCH 6/9] Fix header example --- addons/cargo/functions/fnc_addCargoVehiclesActions.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/cargo/functions/fnc_addCargoVehiclesActions.sqf b/addons/cargo/functions/fnc_addCargoVehiclesActions.sqf index d4e48da6592..0c9f7d2c118 100644 --- a/addons/cargo/functions/fnc_addCargoVehiclesActions.sqf +++ b/addons/cargo/functions/fnc_addCargoVehiclesActions.sqf @@ -9,7 +9,7 @@ * Children actions * * Example: - * [cursorObject, player] call ace_cargo_fnc_addCargoVehiclesActions + * [cursorObject] call ace_cargo_fnc_addCargoVehiclesActions * * Public: No */ From 2aadf06676d20a415fbbfdaf234a1d5ce377bec4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ozan=20E=C4=9Fitmen?= Date: Mon, 18 Sep 2017 10:59:25 +0300 Subject: [PATCH 7/9] Add _distance param to fnc_nearestVehiclesFreeSeat --- addons/common/functions/fnc_nearestVehiclesFreeSeat.sqf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/common/functions/fnc_nearestVehiclesFreeSeat.sqf b/addons/common/functions/fnc_nearestVehiclesFreeSeat.sqf index ef1255db81d..2f8ce384e86 100644 --- a/addons/common/functions/fnc_nearestVehiclesFreeSeat.sqf +++ b/addons/common/functions/fnc_nearestVehiclesFreeSeat.sqf @@ -15,7 +15,7 @@ */ #include "script_component.hpp" -params ["_unit"]; +params ["_unit", ["_distance", 10]]; -private _nearVehicles = nearestObjects [_unit, ["Car", "Air", "Tank", "Ship_F", "Pod_Heli_Transport_04_crewed_base_F"], 10]; +private _nearVehicles = nearestObjects [_unit, ["Car", "Air", "Tank", "Ship_F", "Pod_Heli_Transport_04_crewed_base_F"], _distance]; _nearVehicles select {(_x emptyPositions "cargo" > 0) || {_x emptyPositions "gunner" > 0}} From 7b28281e2230c17b46df8d03541217be9fc84a3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ozan=20E=C4=9Fitmen?= Date: Mon, 18 Sep 2017 11:04:06 +0300 Subject: [PATCH 8/9] Change docs --- addons/captives/functions/fnc_addLoadCaptiveActions.sqf | 4 ++-- addons/cargo/functions/fnc_addCargoVehiclesActions.sqf | 2 +- addons/common/functions/fnc_loadPerson.sqf | 2 +- addons/common/functions/fnc_nearestVehiclesFreeSeat.sqf | 5 +++-- addons/medical/functions/fnc_addLoadPatientActions.sqf | 4 ++-- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/addons/captives/functions/fnc_addLoadCaptiveActions.sqf b/addons/captives/functions/fnc_addLoadCaptiveActions.sqf index b68499942cb..0c7adbda7a4 100644 --- a/addons/captives/functions/fnc_addLoadCaptiveActions.sqf +++ b/addons/captives/functions/fnc_addLoadCaptiveActions.sqf @@ -3,10 +3,10 @@ * Adds child actions to the "load captive" action for near vehicles. * * Arguments: - * 0: The captive + * 0: Captive * * Return Value: - * The child actions + * Child actions * * Example: * [kevin] call ace_medical_fnc_addLoadCaptiveActions diff --git a/addons/cargo/functions/fnc_addCargoVehiclesActions.sqf b/addons/cargo/functions/fnc_addCargoVehiclesActions.sqf index 0c9f7d2c118..111407e3fe1 100644 --- a/addons/cargo/functions/fnc_addCargoVehiclesActions.sqf +++ b/addons/cargo/functions/fnc_addCargoVehiclesActions.sqf @@ -6,7 +6,7 @@ * 0: Target * * Return Value: - * Children actions + * Child actions * * Example: * [cursorObject] call ace_cargo_fnc_addCargoVehiclesActions diff --git a/addons/common/functions/fnc_loadPerson.sqf b/addons/common/functions/fnc_loadPerson.sqf index cc2d1564b1d..897ff1f9a8e 100644 --- a/addons/common/functions/fnc_loadPerson.sqf +++ b/addons/common/functions/fnc_loadPerson.sqf @@ -8,7 +8,7 @@ * 2: Vehicle that the unit will be loaded in (default: objNull) * * Return Value: - * The vehicle that the unitToBeloaded has been loaded in. Returns objNull if function failed + * Vehicle that the unitToBeloaded has been loaded in. Returns objNull if function failed * * Example: * [bob, kevin] call ace_common_fnc_loadPerson diff --git a/addons/common/functions/fnc_nearestVehiclesFreeSeat.sqf b/addons/common/functions/fnc_nearestVehiclesFreeSeat.sqf index 2f8ce384e86..080499d9cf6 100644 --- a/addons/common/functions/fnc_nearestVehiclesFreeSeat.sqf +++ b/addons/common/functions/fnc_nearestVehiclesFreeSeat.sqf @@ -3,7 +3,8 @@ * Returns a list of vehicles near given unit that the unit can be a passenger in. * * Arguments: - * 0: The unit + * 0: Unit + * 1: Distance * * Return Value: * Nearest vehicles with a free seat @@ -11,7 +12,7 @@ * Example: * [bob] call ace_common_fnc_nearestVehiclesFreeSeat * - * Public: No + * Public: Yes */ #include "script_component.hpp" diff --git a/addons/medical/functions/fnc_addLoadPatientActions.sqf b/addons/medical/functions/fnc_addLoadPatientActions.sqf index 96d06ed4322..b00ff724729 100644 --- a/addons/medical/functions/fnc_addLoadPatientActions.sqf +++ b/addons/medical/functions/fnc_addLoadPatientActions.sqf @@ -3,10 +3,10 @@ * Adds child actions to the "load patient" action for near vehicles. * * Arguments: - * 0: The patient + * 0: Patient * * Return Value: - * The child actions + * Child actions * * Example: * [kevin] call ace_medical_fnc_addLoadPatientActions From f645f21af7f45ed48dbe61fb33e461935e9b039d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ozan=20E=C4=9Fitmen?= Date: Fri, 29 Sep 2017 22:26:18 +0300 Subject: [PATCH 9/9] Fix spacing --- addons/medical/CfgVehicles.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/medical/CfgVehicles.hpp b/addons/medical/CfgVehicles.hpp index 6f748bf40b4..4217fb37456 100644 --- a/addons/medical/CfgVehicles.hpp +++ b/addons/medical/CfgVehicles.hpp @@ -545,7 +545,7 @@ class CfgVehicles { class GVAR(loadPatient) { displayName = CSTRING(LoadPatient); distance = 5; - condition = QUOTE(_target getVariable [ARR_2(QUOTE(QUOTE(ACE_isUnconscious)),false)] && {alive _target} && {vehicle _target == _target}); + condition = QUOTE(_target getVariable [ARR_2(QUOTE(QUOTE(ACE_isUnconscious)), false)] && {alive _target} && {vehicle _target == _target}); statement = QUOTE([ARR_2(_player, _target)] call DFUNC(actionLoadUnit)); showDisabled = 0; priority = 2;