Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add condition and helper function for placeMapOnVehicle #75

Merged
merged 2 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addons/map/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
PREP(addOpenMapAction);
PREP(addPickupMapAction);
PREP(addPlaceMapAction);
PREP(getPlaceMapOnVehicleParams);
PREP(hasMap);
PREP(openMap);
PREP(pickupMap);
Expand Down
13 changes: 4 additions & 9 deletions addons/map/functions/fnc_addPickupMapAction.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*
* Parameter(s):
* 0: OBJECT - Placed map
* 1: OBJECT - The vehicle which the map is placed on. (Optional, only needed if map was placed on vehicle)
*
* Returns:
* Nothing.
Expand All @@ -18,7 +17,7 @@
*
*/

params [["_map", objNull, [objNull]], ["_vehicle", objNull, [objNull]]];
params [["_map", objNull, [objNull]]];

CHECK(!hasinterface || isNull _map);

Expand All @@ -27,16 +26,12 @@ private _pickupMap = [
LLSTRING(pickupMap),
"A3\Ui_f\data\IGUI\Cfg\Actions\take_ca.paa",
{
params ["_map", "_player", "_args"];
_args params ["_vehicle"];

[_player, _map, _vehicle] call FUNC(pickupMap);
params ["_map", "_player"];
[_player, _map] call FUNC(pickupMap);
},
{
params ["_map", "_player"];
!([_player] call FUNC(hasMap)) && {[_player, _map] call ace_common_fnc_canInteractWith}
},
{},
[_vehicle]
}
] call ace_interact_menu_fnc_createAction;
[_map, 0, ["ACE_MainActions"], _pickupMap] call ace_interact_menu_fnc_addActionToObject;
31 changes: 31 additions & 0 deletions addons/map/functions/fnc_getPlaceMapOnVehicleParams.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "script_component.hpp"
/**
* Author: Timi007
*
* Description:
* Returns the parameters needed for mts_map_fnc_placeMapOnVehicle.
* How to use: Place vehicle and map how you want the map to be placed when the action is performed.
* Call this function and pass the vehicle and map objects. The returned array are the parameters.
*
* Parameter(s):
* 0: OBJECT - Vehicle the map is placed on.
* 1: OBJECT - The placeholder map object.
*
* Returns:
* ARRAY - Parameters for mts_map_fnc_placeMapOnVehicle.
*
* Example:
* [this, map1] call mts_map_fnc_getPlaceMapOnVehicleParams
*
*/

params [["_vehicle", objnull, [objNull]], ["_mapObj", objnull, [objNull]]];

CHECK(isNull _vehicle || isNull _mapObj);

private _class = typeOf _vehicle;
private _offset = _vehicle worldToModelVisual (ASLtoAGL (getPosASLVisual _mapObj));
private _vectorDir = vectorDir _mapObj;
private _vectorUp = vectorUp _mapObj;

[_class, _offset, [_vectorDir, _vectorUp]]
7 changes: 4 additions & 3 deletions addons/map/functions/fnc_pickupMap.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* Parameter(s):
* 0: OBJECT - Player which takes the map from the ground.
* 1: OBJECT - The map object to pickup.
* 2: OBJECT - The vehicle the map object is attached to. (Optional, ignore if map object is not attached to anything)
*
* Returns:
* Nothing.
Expand All @@ -18,18 +17,20 @@
*
*/

params [["_player", objNull, [objNull]], ["_map", objNull, [objNull]], ["_vehicle", objNull, [objNull]]];
params [["_player", objNull, [objNull]], ["_map", objNull, [objNull]]];

CHECK(isNull _player || isNull _map);

[_player, "pickup"] call FUNC(playMapSound);
_player playAction "PutDown";

[{((animationState (_this select 0)) select [25,7]) isEqualTo "putdown"}, {
params ["_player", "_map", "_vehicle"];
params ["_player", "_map"];

[QGVAR(removeMap), _map] call CBA_fnc_remoteEvent;

private _vehicle = attachedTo _map;

private _mapClass = _map getVariable [QGVAR(mapClass), "ItemMap"];

deleteVehicle _map;
Expand Down
26 changes: 18 additions & 8 deletions addons/map/functions/fnc_placeMapOnVehicle.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
* Parameter(s):
* 0: STRING - Classname of (typeOf) the vehicle.
* 1: ARRAY - Offset of map to the vehicle.
* 2. ARRAY - Dir and up vectors of the map.
* 2: ARRAY - Dir and up vectors of the map.
* 3: CODE - Addtional condition when to show action
* Passed arguments:
* 0: OBJECT - Vehicle.
* 1: OBJECT - Player.
* 2: ARRAY - Custom args (see param 4)).
* 4: ARRAY - Custom arguments for the condition.
*
* Returns:
* Nothing.
Expand All @@ -23,11 +29,12 @@
params [
["_vehClass", "", [""]],
["_offset", [0,0,0], [[]]],
["_vectorDirAndUp", [[0,1,0],[0,0,1]], [[]]]
["_vectorDirAndUp", [[0,1,0],[0,0,1]], [[]]],
["_condition", {true}, [{}]],
["_conditionArgs", [], [[]]]
];

CHECK(!hasinterface);
CHECK(_vehClass isEqualTo "");
CHECK(!hasinterface || _vehClass isEqualTo "");

private _placeMapOnVehAction = [
QGVAR(placeMapOnVehAction),
Expand All @@ -49,21 +56,24 @@ private _placeMapOnVehAction = [

_vehicle setVariable [QGVAR(isMapOnVehicle), true, true];

private _id = [QGVAR(addMapActions), [_map, _vehicle]] call CBA_fnc_globalEventJIP;
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"];
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 getVariable [QGVAR(isMapOnVehicle), false])} &&
{[_vehicle, _player, _conditionArgs] call _condition}
},
{},
[_offset, _vectorDirAndUp],
[_offset, _vectorDirAndUp, _condition, _conditionArgs],
_offset,
2
] call ace_interact_menu_fnc_createAction;
Expand Down