From adf29d75e3d536d21c3ab3f636a0149083d9130a Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Tue, 26 May 2015 23:15:50 -0500 Subject: [PATCH] Explosives - Local Defuse Helpers --- addons/explosives/XEH_postInit.sqf | 55 +++++++++++++------ .../functions/fnc_placeExplosive.sqf | 10 +--- .../functions/fnc_place_Approve.sqf | 2 +- 3 files changed, 40 insertions(+), 27 deletions(-) diff --git a/addons/explosives/XEH_postInit.sqf b/addons/explosives/XEH_postInit.sqf index 88a7bbba95..5bff254613 100644 --- a/addons/explosives/XEH_postInit.sqf +++ b/addons/explosives/XEH_postInit.sqf @@ -15,26 +15,45 @@ */ #include "script_component.hpp" -//Start up a PFEH that scans all mines/explosives without defuseObjects attached and adds them -//Handles Editor Placed / Zeus / Scripted -if (isServer) then { - [{ - private ["_explosive", "_helpers", "_defuseHelper"]; - { - _explosive = _x; - _helpers = { - ((typeOf _x) == "ACE_DefuseObject") && {(_x getVariable [QGVAR(Explosive), objNull]) == _explosive} - } count (attachedObjects _explosive); +//Event system to add the defuse object to all explosive devices (defuse is local) +GVAR(explosivesHelped) = []; +GVAR(defuseOjbects) = []; - if (_helpers == 0) then { - TRACE_3("Explosive without helper",_explosive,(getPosAsl _explosive),(typeOf _explosive)); - _defuseHelper = createVehicle ["ACE_DefuseObject", (getPos _explosive), [], 0, "NONE"]; - _defuseHelper attachTo [_explosive, [0,0,0], ""]; - _defuseHelper setVariable [QGVAR(Explosive),_explosive,true]; +["explosive_placed", { + PARAMS_1(_explosive); + if (_explosive in GVAR(explosivesHelped)) exitWith {}; + private ["_defuseHelper"]; + _defuseHelper = "ACE_DefuseObject" createVehicleLocal (getPos _explosive); + _defuseHelper attachTo [_explosive, [0,0,0]]; + _defuseHelper setVariable [QGVAR(Explosive),_explosive]; + TRACE_3("Added local defuse to helper",_explosive,(typeOf _explosive),_defuseHelper); + GVAR(explosivesHelped) pushBack _explosive; + GVAR(defuseOjbects) pushBack _defuseHelper; +}] call EFUNC(common,addEventHandler); + +//Start up a PFEH that scans all mines/explosives without defuseObjects attached and adds them +//Handles Editor Placed / Zeus / Scripted / JIP +[{ + private ["_modeAdd"]; + _modeAdd = (_this select 0) select 0; + if (_modeAdd) then { + TRACE_2("Adding Helpers",(count allMines),(count GVAR(explosivesHelped))); + { + TRACE_2("Explosive without helper",_explosive,(typeOf _explosive)); + ["explosive_placed", [_x]] call EFUNC(common,localEvent); + } forEach (allMines - GVAR(explosivesHelped)); + } else { + TRACE_2("Cleaning Helpers",(count allMines),(count GVAR(explosivesHelped))); + { + if (isNull _x) then { + deleteVehicle (GVAR(defuseObjects) select _forEachIndex); }; - } forEach allMines; - }, 5, []] call CBA_fnc_addPerFrameHandler; -}; + } forEach GVAR(explosivesHelped); + GVAR(explosivesHelped) = GVAR(explosivesHelped) - [objNull]; + GVAR(defuseOjbects) = GVAR(defuseOjbects) - [objNull]; + }; + (_this select 0) set [0, !_modeAdd]; +}, 5, [true]] call CBA_fnc_addPerFrameHandler; if !(hasInterface) exitWith {}; GVAR(PlacedCount) = 0; diff --git a/addons/explosives/functions/fnc_placeExplosive.sqf b/addons/explosives/functions/fnc_placeExplosive.sqf index 2e6a0ad2c5..f4fcacb7b1 100644 --- a/addons/explosives/functions/fnc_placeExplosive.sqf +++ b/addons/explosives/functions/fnc_placeExplosive.sqf @@ -51,18 +51,12 @@ if (isText(_magazineTrigger >> "ammo")) then { _ammo = getText (_magazineTrigger >> "ammo"); }; _triggerSpecificVars pushBack _triggerConfig; -private ["_defuseHelper"]; -_defuseHelper = createVehicle ["ACE_DefuseObject", _pos, [], 0, "NONE"]; -_defuseHelper setPosATL _pos; _explosive = createVehicle [_ammo, _pos, [], 0, "NONE"]; -_defuseHelper attachTo [_explosive, [0,0,0], ""]; -_defuseHelper setVariable [QGVAR(Explosive),_explosive,true]; - -_expPos = getPosATL _explosive; -_defuseHelper setPosATL (((getPosATL _defuseHelper) vectorAdd (_pos vectorDiff _expPos))); _explosive setPosATL _pos; +["explosive_placed", [_explosive]] call EFUNC(common,globalEvent); + if (!isNull _attachedTo) then { TRACE_1("Attaching Live Explosive",_attachedTo); _explosive attachTo [_attachedTo]; diff --git a/addons/explosives/functions/fnc_place_Approve.sqf b/addons/explosives/functions/fnc_place_Approve.sqf index 323e8bd634..0604045f65 100644 --- a/addons/explosives/functions/fnc_place_Approve.sqf +++ b/addons/explosives/functions/fnc_place_Approve.sqf @@ -37,7 +37,7 @@ if (_dir > 180) then { } else { _dir = 180 + _dir; }; -_setup setVariable [QGVAR(Direction), _dir]; +_setup setVariable [QGVAR(Direction), _dir, true]; _player setVariable [QGVAR(PlantingExplosive), true]; [{_this setVariable [QGVAR(PlantingExplosive), false]}, _player, 1.5, 0.5] call EFUNC(common,waitAndExecute); _setup addEventHandler ["EpeContactStart", FUNC(onLanded)];