Wirecutter handles interact event

adds helper objects to all fences that have actions
This commit is contained in:
PabstMirror 2015-03-10 16:01:46 -05:00
parent 49cef030d5
commit 794a1f9922
12 changed files with 163 additions and 85 deletions

View File

@ -4,3 +4,8 @@ class Extended_PreInit_EventHandlers {
init = QUOTE(call COMPILE_FILE(XEH_preInit));
};
};
class Extended_PostInit_EventHandlers {
class ADDON {
clientInit = QUOTE( call COMPILE_FILE(XEH_clientInit) );
};
};

View File

@ -1,19 +0,0 @@
class CfgVehicles {
class Man;
class CAManBase: Man {
class ACE_SelfActions {
class ACE_Equipment {
class GVAR(CutFence) {
displayName = "$STR_ACE_logistics_wirecutter_CutFence";
condition = QUOTE([_player] call FUNC(canCutFence));
statement = QUOTE([_player] call FUNC(cutDownFence));
exceptions[] = {};
showDisabled = 1;
priority = 0;
icon = PATHTOF(UI\wirecutter_ca.paa);
hotkey = "C";
};
};
};
};
};

View File

@ -0,0 +1,5 @@
#include "script_component.hpp"
if (!hasInterface) exitWith {};
["interact_keyDown", {_this call FUNC(interactEH)}] call EFUNC(common,addEventHandler);

View File

@ -2,11 +2,11 @@
ADDON = false;
PREP(canCutFence);
PREP(cutDownFence);
PREP(cutDownFenceAbort);
PREP(cutDownFenceCallback);
PREP(getNearestFence);
PREP(interactEH);
PREP(isFence);
ADDON = true;

View File

@ -5,7 +5,7 @@ class CfgPatches {
units[] = {};
weapons[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {"ace_common", "ace_interaction"};
requiredAddons[] = {"ace_interact_menu"};
author[] = {"gpgpgpgp", "PabstMirror"};
authorUrl = "";
VERSION_CONFIG;
@ -13,6 +13,5 @@ class CfgPatches {
};
#include "CfgEventHandlers.hpp"
#include "CfgVehicles.hpp"
#include "CfgSounds.hpp"
#include "CfgWeapons.hpp"

View File

@ -1,18 +0,0 @@
/* fnc_canCutFence.sqf
*
* Author: PabstMirror
*
* Condition check if player is able to cut a fence.
* Checks for "ACE_wirecutter" item and if there is a nearby fence.
*
* Argument:
* 0: OBJECT - Unit to check condition for (player)
*
* Return value:
* BOOL
*/
#include "script_component.hpp"
PARAMS_1(_unit);
("ACE_wirecutter" in (items _unit)) && {!(isNull ([_unit] call FUNC(getNearestFence)))}

View File

@ -1,20 +1,31 @@
// by gpgpgpgp, edited by commy2
/*
* Author: gpgpgpgp, edited by commy2, PabstMirror
* Starts cutting down a fence
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Fence <OBJECT>
*
* Return Value:
* Nothing
*
* Example:
* [player, berlinWall] call ace_logistics_wirecutter_fnc_cutDownFence
*
* Public: No
*/
#include "script_component.hpp"
PARAMS_1(_unit);
private ["_timeToCut"];
PARAMS_2(_unit,_fenceObject);
if (_unit != ACE_player) exitWith {};
_fenceObject = [ACE_player] call FUNC(getNearestFence);
if (isNull _fenceObject) exitWith {};
_timeToCut = 5;
if !([ACE_player] call EFUNC(common,isEngineer)) then {
_timeToCut = _timeToCut + 5;
};
_timeToCut = if ([ACE_player] call EFUNC(common,isEngineer)) then {5} else {10};
[ACE_player, "AinvPknlMstpSnonWnonDr_medic5", 0] call EFUNC(common,doAnimation);
if (_timeToCut > 4.5) then {
if (_timeToCut > 5) then {
playSound "ACE_wirecutter_sound_long";
} else {
playSound "ACE_wirecutter_sound";

View File

@ -1,4 +1,18 @@
// by commy2
/*
* Author: commy2
* Stops cutting down fence (reset animation)
*
* Arguments:
* Nothing
*
* Return Value:
* Nothing
*
* Example:
* [] call ace_logistics_wirecutter_fnc_cutDownFenceAbort
*
* Public: No
*/
#include "script_component.hpp"
[ACE_player, "AmovPknlMstpSrasWrflDnon", 1] call EFUNC(common,doAnimation);

View File

@ -1,7 +1,22 @@
/*
* Author: PabstMirror
* Once progressbar is done: Fence is cutdown
*
* Arguments:
* 0: Fence Object <OBJECT>
*
* Return Value:
* Nothing
*
* Example:
* [aFence] call ace_logistics_wirecutter_fnc_cutDownFenceCallback
*
* Public: No
*/
#include "script_component.hpp"
PARAMS_1(_fenceObject);
_fenceObject setdamage 1;
[localize "STR_ACE_logistics_wirecutter_FenceCut"] call EFUNC(common,displayTextStructured);
// [localize "STR_ACE_logistics_wirecutter_FenceCut"] call EFUNC(common,displayTextStructured);
[ACE_player, "AmovPknlMstpSrasWrflDnon", 1] call EFUNC(common,doAnimation);

View File

@ -1,15 +1,18 @@
/* fnc_getNearestFence.sqf
*
* Author: PabstMirror
*
* Gets nearest fence within 5 meters to the unit.
*
* Argument:
* 0: OBJECT - Unit to search for fence objects arround
*
* Return value:
* OBJECT - Nearest object that is a fence, objNull if none found.
*/
/*
* Author: PabstMirror
* Gets nearest fence object (not actully used, left for utility)
*
* Arguments:
* 0: Unit <OBJECT>
*
* Return Value:
* The return value <OBJECT>
*
* Example:
* [player] call ace_logistics_wirecutter_fnc_getNearestFence
*
* Public: Yes
*/
#include "script_component.hpp"
private "_nearestFence";
@ -20,6 +23,6 @@ _nearestFence = objNull;
if ((isNull _nearestFence) && {[_x] call FUNC(isFence)}) then {
_nearestFence = _x;
};
} forEach nearestObjects [_unit, [], 5];
} forEach nearestObjects [_unit, [], 15];
_nearestFence

View File

@ -0,0 +1,60 @@
/*
* Author: PabstMirror
* When interact_menu starts rendering (from "interact_keyDown" event)
*
* Arguments:
* Nothing
*
* Return Value:
* Nothing
*
* Example:
* [] call ace_logistics_wirecutter_fnc_interactEH
*
* Public: Yes
*/
#include "script_component.hpp"
//for performance only do stuff it they have a wirecutter item
//(if they somehow get one durring keydown they'll just have to reopen)
if (!("ACE_wirecutter" in (items ace_player))) exitWith {};
[{
PARAMS_2(_args,_pfID);
EXPLODE_3_PVT(_args,_setPosition,_addedHelpers,_fencesHelped);
if (!EGVAR(interact_menu,keyDown)) then {
{deleteVehicle _x;} forEach _addedHelpers;
[_pfID] call CBA_fnc_removePerFrameHandler;
} else {
//If play moved >5 meters from last pos, then rescan
if (((getPosASL ace_player) distance _setPosition) > 5) then {
_fncStatement = {
_attachedFence = _target getVariable [QGVAR(attachedFence), objNull];
[ace_player, _attachedFence] call FUNC(cutDownFence);
};
_fncCondition = {
_attachedFence = _target getVariable [QGVAR(attachedFence), objNull];
((!isNull _attachedFence) && {(damage _attachedFence) < 1} && {("ACE_wirecutter" in (items ace_player))})
};
{
if (!(_x in _fencesHelped)) then {
if ([_x] call FUNC(isFence)) then {
_fencesHelped pushBack _x;
_helper = "Sign_Sphere25cm_F" createVehicleLocal (getpos _x);
[_helper, 0, [""], (localize "STR_ACE_logistics_wirecutter_CutFence"), QUOTE(PATHTOF(ui\wirecutter_ca.paa)), [0,0,0], _fncStatement, _fncCondition, 5] call EFUNC(interact_menu,addAction);
_helper setPosASL ((getPosASL _x) vectorAdd [0,0,1.25]);
_helper hideObject true;
_helper setVariable [QGVAR(attachedFence), _x];
_addedHelpers pushBack _helper;
};
};
} forEach nearestObjects [ace_player, [], 15];
_args set [0, (getPosASL ace_player)];
};
};
}, 0.1, [((getPosASL ace_player) vectorAdd [-100,0,0]), [], []]] call CBA_fnc_addPerFrameHandler;

View File

@ -1,16 +1,19 @@
/* fnc_isFence.sqf
*
* Author: PabstMirror
*
* Checks if object is a fence. Should work on any fence type, even (typeof == "").
* Call is fairly expensive because of all of the string checking.
*
* Argument:
* 0: OBJECT - Ojbect to test
*
* Return value:
* BOOL
*/
/*
* Author: PabstMirror
* Checks if object is a fence. Should work on any fence type, even (typeof == "").
* Call is fairly expensive because of all of the string checking.
*
* Arguments:
* 0: An Object To Test <OBJECT>
*
* Return Value:
* Is it a fence <BOOL>
*
* Example:
* [aFence] call ace_logistics_wirecutter_fnc_isFence
*
* Public: No
*/
#include "script_component.hpp"
//find is case sensitive, so keep everything lowercase
@ -27,14 +30,14 @@ _typeOf = toLower (typeOf _object);
_returnValue = false;
if (_typeOf != "") then {
_returnValue = _typeOf in (FENCE_A3_TYPENAMES + FENCE_AIA_TYPENAMES);
_returnValue = _typeOf in (FENCE_A3_TYPENAMES + FENCE_AIA_TYPENAMES);
} else {
_typeOf = toLower (str _object); //something like "123201: wall_indfnc_9.p3d"
{
if ((_typeOf find _x) != -1) then {
_returnValue = true;
};
} forEach (FENCE_A3_P3DS + FENCE_AIA_P3DS);
_typeOf = toLower (str _object); //something like "123201: wall_indfnc_9.p3d"
{
if ((_typeOf find _x) != -1) then {
_returnValue = true;
};
} forEach (FENCE_A3_P3DS + FENCE_AIA_P3DS);
};
_returnValue