Skip to content
This repository was archived by the owner on May 24, 2022. It is now read-only.
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
15 changes: 8 additions & 7 deletions addons/fortify/functions/fnc_addDeployHandler.sqf
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
/*
* Author: Cuel
* Register a custom deployment validator
* Provided code is passed [unit, object, cost]
* Code needs to return BOOL: true(allowed) / false(blocked)
* Author: Cuel, mharis001
* Adds a custom deploy handler.
* Code needs to return BOOL: true (allowed) / false (blocked).
*
* Arguments:
* 0: Code <CODE>
* - Passed [Unit <OBJECT>, Object being placed <OBJECT>, Cost <NUMBER>]
*
* Return Value:
* None
*
* Example:
* [{alive param [0]}] call acex_fortify_fnc_addDeployHandler;
* [{(_this select 0) getVariable ["isBobTheBuilder", false]}] call acex_fortify_fnc_addDeployHandler
*
* Public: Yes
*/

#include "script_component.hpp"
params [["_code", {true}, [{}]]];

params [["_code", {}, [{}]]];

if (_code isEqualTo {} || {_code isEqualTo {true}}) exitWith {};
GVAR(deployHandlers) pushBack _code;
19 changes: 7 additions & 12 deletions addons/fortify/functions/fnc_deployObject.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if (_budget > -1) then {_lmb = _lmb + format [" -$%1", _cost];};
private _rmb = localize ACELSTRING(Common,Cancel);
private _wheel = localize LSTRING(rotate);
private _xAxis = localize "str_disp_conf_xaxis";
private _icons = [["alt", localize "str_3den_display3den_entitymenu_movesurface_text"], ["shift", localize "str_disp_conf_xaxis" + " " +_wheel], ["control", localize "str_disp_conf_yaxis" + " " + _wheel]];
private _icons = [["alt", localize "str_3den_display3den_entitymenu_movesurface_text"], ["shift", localize "str_disp_conf_xaxis" + " " + _wheel], ["control", localize "str_disp_conf_yaxis" + " " + _wheel]];
[_lmb, _rmb, _wheel, _icons] call ACEFUNC(interaction,showMouseHint);

private _mouseClickID = [_player, "DefaultAction", {GVAR(isPlacing) == PLACE_WAITING}, {GVAR(isPlacing) = PLACE_APPROVE}] call ACEFUNC(common,addActionEventHandler);
Expand All @@ -50,17 +50,13 @@ private _mouseClickID = [_player, "DefaultAction", {GVAR(isPlacing) == PLACE_WAI
params ["_args", "_pfID"];
_args params ["_unit", "_object", "_cost", "_mouseClickID"];

if ((_unit != ACE_player) || {isNull _object} || {!([_unit, _object, []] call ACEFUNC(common,canInteractWith))} || {!([_unit, _cost] call FUNC(canFortify))}) then {
if (_unit != ACE_player || {isNull _object} || {!([_unit, _object, []] call ACEFUNC(common,canInteractWith))} || {!([_unit, _cost] call FUNC(canFortify))}) then {
GVAR(isPlacing) = PLACE_CANCEL;
};

if (GVAR(isPlacing) == PLACE_APPROVE) then {
// Run custom deploy handlers
private _someReturnFalse = {if ([_unit, _object, _cost] call _x isEqualTo false) exitWith {1}} count GVAR(deployHandlers);
if (_someReturnFalse isEqualTo 1) then {
// do not allow placement
GVAR(isPlacing) = PLACE_WAITING;
};
// If place approved, verify deploy handlers
if (GVAR(isPlacing) == PLACE_APPROVE && {(GVAR(deployHandlers) findIf {([_unit, _object, _cost] call _x) isEqualTo false}) > -1}) then {
GVAR(isPlacing) = PLACE_WAITING;
};

if (GVAR(isPlacing) != PLACE_WAITING) exitWith {
Expand All @@ -84,8 +80,8 @@ private _mouseClickID = [_player, "DefaultAction", {GVAR(isPlacing) == PLACE_WAI

private _start = eyePos _unit;
private _camViewDir = getCameraViewDirection _unit;
private _basePos = (_start vectorAdd (_camViewDir vectorMultiply _distance));
_basePos set [2, ((_basePos select 2) - (_height / 2)) max ((getTerrainHeightASL _basePos) - 0.05)];
private _basePos = _start vectorAdd (_camViewDir vectorMultiply _distance);
_basePos set [2, ((_basePos select 2) - (_height / 2)) max (getTerrainHeightASL _basePos - 0.05)];

_object setPosASL _basePos;

Expand All @@ -101,4 +97,3 @@ private _mouseClickID = [_player, "DefaultAction", {GVAR(isPlacing) == PLACE_WAI
hintSilent format ["Rotation:\nX: %1\nY: %2\nZ: %3", GVAR(objectRotationX), GVAR(objectRotationY), GVAR(objectRotationZ)];
#endif
}, 0, [_player, _object, _cost, _mouseClickID]] call CBA_fnc_addPerFrameHandler;