Explosives - Local Defuse Helpers

This commit is contained in:
PabstMirror 2015-05-26 23:15:50 -05:00
parent 5e6e62280e
commit adf29d75e3
3 changed files with 40 additions and 27 deletions

View File

@ -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;

View File

@ -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];

View File

@ -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)];