Skip to content

Commit

Permalink
Explosives - Local Defuse Helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
PabstMirror committed May 27, 2015
1 parent 5e6e622 commit adf29d7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 26 deletions.
53 changes: 36 additions & 17 deletions addons/explosives/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,45 @@
*/
#include "script_component.hpp"

//Event system to add the defuse object to all explosive devices (defuse is local)
GVAR(explosivesHelped) = [];
GVAR(defuseOjbects) = [];

["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
if (isServer) then {
[{
private ["_explosive", "_helpers", "_defuseHelper"];
//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)));
{
_explosive = _x;
_helpers = {
((typeOf _x) == "ACE_DefuseObject") && {(_x getVariable [QGVAR(Explosive), objNull]) == _explosive}
} count (attachedObjects _explosive);

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];
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;
Expand Down
10 changes: 2 additions & 8 deletions addons/explosives/functions/fnc_placeExplosive.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion addons/explosives/functions/fnc_place_Approve.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
Expand Down

0 comments on commit adf29d7

Please sign in to comment.