diff --git a/addons/map/XEH_PREP.hpp b/addons/map/XEH_PREP.hpp index 9fb1b33..99638b3 100644 --- a/addons/map/XEH_PREP.hpp +++ b/addons/map/XEH_PREP.hpp @@ -1,6 +1,7 @@ PREP(addOpenMapAction); PREP(addPickupMapAction); PREP(addPlaceMapAction); +PREP(getPlaceMapOnVehicleAction); PREP(getPlaceMapOnVehicleParams); PREP(hasMap); PREP(openMap); diff --git a/addons/map/functions/fnc_getPlaceMapOnVehicleAction.sqf b/addons/map/functions/fnc_getPlaceMapOnVehicleAction.sqf new file mode 100644 index 0000000..9f48eaa --- /dev/null +++ b/addons/map/functions/fnc_getPlaceMapOnVehicleAction.sqf @@ -0,0 +1,76 @@ +#include "script_component.hpp" +/** + * Author: Timi007 + * + * Description: + * Returns an ACE action to place a unit's map on the vehicle. + * The map will be attached to the vehicle with the given offset and orientation. + * This function has a local effect. + * + * Parameter(s): + * 0: ARRAY - Offset of map to the vehicle. + * 1: ARRAY - Dir and up vectors of the map. + * 2: CODE - Additional condition when to show action + * Passed arguments: + * 0: OBJECT - Vehicle. + * 1: OBJECT - Player. + * 2: ARRAY - Custom args (see param 4)). + * 3: ARRAY - Custom arguments for the condition. + * + * Returns: + * ARRAY - ACE action + * + * Example: + * _action = [[-0.205078,1.49292,-0.3325], [[-1,0,0],[0,0.1,1]]] call mts_map_fnc_getPlaceMapOnVehicleAction; + * [_vehicle, 0, [], _action] call ace_interact_menu_fnc_addActionToObject; + * + */ + +params [ + ["_offset", [0,0,0], [[]]], + ["_vectorDirAndUp", [[0,1,0],[0,0,1]], [[]]], + ["_condition", {true}, [{}]], + ["_conditionArgs", [], [[]]] +]; + +[ + QGVAR(placeMapOnVehAction), + LLSTRING(placeMap), + "\A3\Ui_f\data\GUI\Rsc\RscDisplayArsenal\map_ca.paa", + { + params ["_vehicle", "_player", "_args"]; + _args params ["_offset", "_vectorDirAndUp"]; + + _player playAction "putdown"; + [_player, "unfold"] call FUNC(playMapSound); + + [{((animationState (_this select 1)) select [25,7]) isEqualTo "putdown"}, { + params ["_vehicle", "_player", "_offset", "_vectorDirAndUp"]; + + private _map = GVAR(itemMapClassname) createVehicle [0,0,0]; + _map attachTo [_vehicle, _offset]; + _map setVectorDirAndUp _vectorDirAndUp; + + _vehicle setVariable [QGVAR(isMapOnVehicle), true, true]; + + private _id = [QGVAR(addMapActions), [_map]] call CBA_fnc_globalEventJIP; + [_id, _map] call CBA_fnc_removeGlobalEventJIP; // Remove JIP when map is deleted + + private _mapClass = [_player] call FUNC(removeMap); + _map setVariable [QGVAR(mapClass), _mapClass, true]; + }, [_vehicle, _player, _offset, _vectorDirAndUp]] call CBA_fnc_waitUntilAndExecute; + }, + { + params ["_vehicle", "_player", "_args"]; + _args params ["", "", "_condition", "_conditionArgs"]; + + ([_player] call FUNC(hasMap)) && + {[_player, _vehicle, ["isNotInside"]] call ace_common_fnc_canInteractWith} && + {!(_vehicle getVariable [QGVAR(isMapOnVehicle), false])} && + {[_vehicle, _player, _conditionArgs] call _condition} + }, + {}, + [_offset, _vectorDirAndUp, _condition, _conditionArgs], + _offset, + 2 +] call ace_interact_menu_fnc_createAction; diff --git a/addons/map/functions/fnc_placeMapOnVehicle.sqf b/addons/map/functions/fnc_placeMapOnVehicle.sqf index bd1aad3..70e62cc 100644 --- a/addons/map/functions/fnc_placeMapOnVehicle.sqf +++ b/addons/map/functions/fnc_placeMapOnVehicle.sqf @@ -11,7 +11,7 @@ * 0: STRING - Classname of (typeOf) the vehicle. * 1: ARRAY - Offset of map to the vehicle. * 2: ARRAY - Dir and up vectors of the map. - * 3: CODE - Addtional condition when to show action + * 3: CODE - Additional condition when to show action * Passed arguments: * 0: OBJECT - Vehicle. * 1: OBJECT - Player. @@ -36,45 +36,5 @@ params [ CHECK(!hasInterface || _vehClass isEqualTo ""); -private _placeMapOnVehAction = [ - QGVAR(placeMapOnVehAction), - LLSTRING(placeMap), - "\A3\Ui_f\data\GUI\Rsc\RscDisplayArsenal\map_ca.paa", - { - params ["_vehicle", "_player", "_args"]; - _args params ["_offset", "_vectorDirAndUp"]; - - _player playAction "putdown"; - [_player, "unfold"] call FUNC(playMapSound); - - [{((animationState (_this select 1)) select [25,7]) isEqualTo "putdown"}, { - params ["_vehicle", "_player", "_offset", "_vectorDirAndUp"]; - - private _map = GVAR(itemMapClassname) createVehicle [0,0,0]; - _map attachTo [_vehicle, _offset]; - _map setVectorDirAndUp _vectorDirAndUp; - - _vehicle setVariable [QGVAR(isMapOnVehicle), true, true]; - - private _id = [QGVAR(addMapActions), [_map]] call CBA_fnc_globalEventJIP; - [_id, _map] call CBA_fnc_removeGlobalEventJIP; // Remove JIP when map is deleted - - private _mapClass = [_player] call FUNC(removeMap); - _map setVariable [QGVAR(mapClass), _mapClass, true]; - }, [_vehicle, _player, _offset, _vectorDirAndUp]] call CBA_fnc_waitUntilAndExecute; - }, - { - params ["_vehicle", "_player", "_args"]; - _args params ["", "", "_condition", "_conditionArgs"]; - - ([_player] call FUNC(hasMap)) && - {[_player, _vehicle, ["isNotInside"]] call ace_common_fnc_canInteractWith} && - {!(_vehicle getVariable [QGVAR(isMapOnVehicle), false])} && - {[_vehicle, _player, _conditionArgs] call _condition} - }, - {}, - [_offset, _vectorDirAndUp, _condition, _conditionArgs], - _offset, - 2 -] call ace_interact_menu_fnc_createAction; +private _placeMapOnVehAction = [_offset, _vectorDirAndUp, _condition, _conditionArgs] call FUNC(getPlaceMapOnVehicleAction); [_vehClass, 0, [], _placeMapOnVehAction] call ace_interact_menu_fnc_addActionToClass;