ACE3/addons/explosives/functions/fnc_interactEH.sqf
2015-05-27 14:09:06 -05:00

57 lines
1.9 KiB
Plaintext

/*
* Author: PabstMirror
* When interact_menu starts rendering (from "interact_keyDown" event)
* Add defuse helpers to all nearby mines
*
* Arguments:
* Interact Menu Type (0 - world, 1 - self) <NUMBER>
*
* Return Value:
* Nothing
*
* Example:
* [0] call ace_explosives_fnc_interactEH
*
* Public: Yes
*/
#include "script_component.hpp"
PARAMS_1(_interactionType);
//Ignore self-interaction menu
if (_interactionType != 0) exitWith {};
//Ignore while mounted:
if ((vehicle ACE_player) != ACE_player) exitWith {};
//Ignore if we don't have defuse kit
if (!("ACE_DefusalKit" in (items ACE_player))) exitWith {};
[{
PARAMS_2(_args,_pfID);
EXPLODE_3_PVT(_args,_setPosition,_addedDefuseHelpers,_minesHelped);
if (!EGVAR(interact_menu,keyDown)) then {
TRACE_1("Cleaning Defuse Helpers",(count _addedDefuseHelpers));
{deleteVehicle _x;} forEach _addedDefuseHelpers;
[_pfID] call CBA_fnc_removePerFrameHandler;
} else {
private ["_defuseHelper"];
// Prevent Rare Error when ending mission with interact key down:
if (isNull ace_player) exitWith {};
//If player moved >5 meters from last pos, then rescan
if (((getPosASL ace_player) distance _setPosition) > 5) then {
{
if (((_x distance ACE_player) < 15) && {!(_x in _minesHelped)}) then {
TRACE_2("Making Defuse Helper",(_x),(typeOf _x));
_defuseHelper = "ACE_DefuseObject" createVehicleLocal (getPos _x);
_defuseHelper attachTo [_x, [0,0,0]];
_defuseHelper setVariable [QGVAR(Explosive),_x];
_addedDefuseHelpers pushBack _defuseHelper;
_minesHelped pushBack _x;
};
} forEach allMines;
_args set [0, (getPosASL ace_player)];
};
};
}, 0.5, [((getPosASL ace_player) vectorAdd [-100,0,0]), [], []]] call CBA_fnc_addPerFrameHandler;