Merge pull request #1417 from acemod/localDefuseObjects

Explosives - Local defuse objects
This commit is contained in:
PabstMirror 2015-05-30 15:46:07 -05:00
commit 23d300df52
7 changed files with 62 additions and 42 deletions

View File

@ -15,28 +15,10 @@
*/ */
#include "script_component.hpp" #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);
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];
};
} forEach allMines;
}, 5, []] call CBA_fnc_addPerFrameHandler;
};
if !(hasInterface) exitWith {}; if !(hasInterface) exitWith {};
["interactMenuOpened", {_this call FUNC(interactEH)}] call EFUNC(common,addEventHandler);
GVAR(PlacedCount) = 0; GVAR(PlacedCount) = 0;
GVAR(Setup) = objNull; GVAR(Setup) = objNull;
GVAR(pfeh_running) = false; GVAR(pfeh_running) = false;

View File

@ -36,6 +36,8 @@ PREP(handleScrollWheel);
PREP(hasExplosives); PREP(hasExplosives);
PREP(hasPlacedExplosives); PREP(hasPlacedExplosives);
PREP(interactEH);
PREP(getDetonators); PREP(getDetonators);
PREP(getPlacedExplosives); PREP(getPlacedExplosives);
PREP(getSpeedDialExplosive); PREP(getSpeedDialExplosive);

View File

@ -21,10 +21,4 @@ if (getNumber (ConfigFile >> "CfgAmmo" >> typeof _explosive >> "ACE_explodeOnDef
[_unit, -1, [_explosive, 1], true] call FUNC(detonateExplosive); [_unit, -1, [_explosive, 1], true] call FUNC(detonateExplosive);
}; };
{
detach _x;
deleteVehicle _x;
false
} count (attachedObjects (_explosive));
_unit action ["Deactivate", _unit, _explosive]; _unit action ["Deactivate", _unit, _explosive];

View File

@ -26,12 +26,6 @@ _result = true;
if (!_ignoreRange && {(_unit distance (_item select 0)) > _range}) exitWith {false}; if (!_ignoreRange && {(_unit distance (_item select 0)) > _range}) exitWith {false};
_helpers = attachedObjects (_item select 0);
{
detach _x;
deleteVehicle _x;
} forEach _helpers;
if (getNumber (ConfigFile >> "CfgAmmo" >> typeof (_item select 0) >> "TriggerWhenDestroyed") == 0) then { if (getNumber (ConfigFile >> "CfgAmmo" >> typeof (_item select 0) >> "TriggerWhenDestroyed") == 0) then {
private ["_exp", "_previousExp"]; private ["_exp", "_previousExp"];
_previousExp = _item select 0; _previousExp = _item select 0;

View File

@ -0,0 +1,56 @@
/*
* 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;

View File

@ -51,16 +51,8 @@ if (isText(_magazineTrigger >> "ammo")) then {
_ammo = getText (_magazineTrigger >> "ammo"); _ammo = getText (_magazineTrigger >> "ammo");
}; };
_triggerSpecificVars pushBack _triggerConfig; _triggerSpecificVars pushBack _triggerConfig;
private ["_defuseHelper"];
_defuseHelper = createVehicle ["ACE_DefuseObject", _pos, [], 0, "NONE"];
_defuseHelper setPosATL _pos;
_explosive = createVehicle [_ammo, _pos, [], 0, "NONE"]; _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 setPosATL _pos;
if (!isNull _attachedTo) then { if (!isNull _attachedTo) then {

View File

@ -37,7 +37,7 @@ if (_dir > 180) then {
} else { } else {
_dir = 180 + _dir; _dir = 180 + _dir;
}; };
_setup setVariable [QGVAR(Direction), _dir]; _setup setVariable [QGVAR(Direction), _dir, true];
_player setVariable [QGVAR(PlantingExplosive), true]; _player setVariable [QGVAR(PlantingExplosive), true];
[{_this setVariable [QGVAR(PlantingExplosive), false]}, _player, 1.5, 0.5] call EFUNC(common,waitAndExecute); [{_this setVariable [QGVAR(PlantingExplosive), false]}, _player, 1.5, 0.5] call EFUNC(common,waitAndExecute);
_setup addEventHandler ["EpeContactStart", FUNC(onLanded)]; _setup addEventHandler ["EpeContactStart", FUNC(onLanded)];