Skip to content

Commit

Permalink
Wirecutter - Replace fences with destroyed models when cut (#8106)
Browse files Browse the repository at this point in the history
* Add more fence types for wirecutter

* Replace fences with destroyed models when cut

* Move fence destruction to server side
  • Loading branch information
BaerMitUmlaut authored Feb 23, 2021
1 parent 5bc43fe commit 61e8ae3
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 7 deletions.
2 changes: 1 addition & 1 deletion addons/logistics_wirecutter/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class Extended_PreInit_EventHandlers {

class Extended_PostInit_EventHandlers {
class ADDON {
clientInit = QUOTE(call COMPILE_FILE(XEH_clientInit));
init = QUOTE(call COMPILE_FILE(XEH_postInit));
};
};
15 changes: 15 additions & 0 deletions addons/logistics_wirecutter/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,19 @@ class CfgVehicles {
class Land_BackAlley_01_l_1m_F: Wall_F {
GVAR(isFence) = 1;
};
class Land_GameProofFence_01_l_5m_F: Wall_F {
GVAR(isFence) = 1;
};
class Land_NetFence_03_m_3m_F: Wall_F {
GVAR(isFence) = 1;
};
class Land_NetFence_03_m_3m_corner_F: Wall_F {
GVAR(isFence) = 1;
};
class Land_NetFence_03_m_3m_hole_F: Wall_F {
GVAR(isFence) = 1;
};
class Land_NetFence_03_m_9m_F: Wall_F {
GVAR(isFence) = 1;
};
};
1 change: 1 addition & 0 deletions addons/logistics_wirecutter/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
PREP(cutDownFence);
PREP(destroyFence);
PREP(interactEH);
PREP(isFence);
5 changes: 0 additions & 5 deletions addons/logistics_wirecutter/XEH_clientInit.sqf

This file was deleted.

9 changes: 9 additions & 0 deletions addons/logistics_wirecutter/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "script_component.hpp"

if (hasInterface) then {
["ace_interactMenuOpened", {_this call FUNC(interactEH)}] call CBA_fnc_addEventHandler;
};

if (isServer) then {
[QGVAR(destroyFence), {_this call FUNC(destroyFence)}] call CBA_fnc_addEventHandler;
};
24 changes: 24 additions & 0 deletions addons/logistics_wirecutter/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,28 @@ PREP_RECOMPILE_START;
#include "XEH_PREP.hpp"
PREP_RECOMPILE_END;

if (isServer) then {
GVAR(replacements) = createHashMapFromArray [
["gameprooffence_01_l_5m_f.p3d", [["Land_GameProofFence_01_l_d_F", [0, 0, 0], 0]]],
["indfnc_3_f.p3d", [["Land_IndFnc_3_D_F", [0.039, -0.221, 0], 0]]],
["indfnc_3_hole_f.p3d", [["Land_IndFnc_3_D_F", [0.042, -0.252, 0], 0]]],
["indfnc_9_f.p3d", [["Land_IndFnc_3_F", [-3, -0.06, 0], 0], ["Land_IndFnc_3_D_F", [0.039, -0.281, 0], 0], ["Land_IndFnc_3_F", [3, -0.06, 0], 0]]],
["indfnc_corner_f.p3d", [["Land_IndFnc_3_D_F", [0.116, -0.223, 0], 0]]],
["mil_wiredfence_f.p3d", [["Land_Mil_WiredFenceD_F", [0, 0, 0], 0]]],
["net_fence_8m_f.p3d", [["Land_Net_FenceD_8m_F", [0, 0.1, 0], 0]]],
["netfence_01_m_4m_f.p3d", [["Land_NetFence_01_m_d_F", [0, 0, 0], 0]]],
["netfence_01_m_8m_f.p3d", [["Land_NetFence_01_m_4m_F", [-2, 0, 0], 0], ["Land_NetFence_01_m_d_F", [2, 0, 0], 0]]],
["netfence_03_m_3m_corner_f.p3d", [["Land_NetFence_03_m_3m_d_F", [0.104, -0.183, 0], 0]]],
["netfence_03_m_3m_f.p3d", [["Land_NetFence_03_m_3m_d_F", [0.042, -0.236, 0], 0]]],
["netfence_03_m_3m_hole_f.p3d", [["Land_NetFence_03_m_3m_d_F", [0.045, -0.273, 0], 0]]],
["netfence_03_m_9m_f.p3d", [["Land_NetFence_03_m_3m_F", [-3.006, -0.073, 0], 0], ["Land_NetFence_03_m_3m_d_F", [0.038, -0.309, 0], 0], ["Land_NetFence_03_m_3m_F", [2.995, -0.073, 0], 0]]],
["plasticnetfence_01_long_f.p3d", [["Land_PlasticNetFence_01_long_d_F", [0, 0, -0.1], 0]]],
["wired_fence_4m_f.p3d", [["Land_Wired_Fence_4mD_F", [0, 0, 0], 0]]],
["wired_fence_8m_f.p3d", [["Land_Wired_Fence_4m_F", [-2, 0, 0], 0], ["Land_Wired_Fence_4mD_F", [3, 0, 0], 0]]],
["wiredfence_01_16m_f.p3d", [["Land_WiredFence_01_4m_F", [-6, 0, 0], 0], ["Land_WiredFence_01_8m_d_F", [0.34, -0.1, 0], 0]]],
["wiredfence_01_4m_f.p3d", [["Land_WiredFence_01_pole_F", [-2, 0, 0], 150]]],
["wiredfence_01_8m_f.p3d", [["Land_WiredFence_01_4m_F", [-2, 0, 0], 0], ["Land_WiredFence_01_pole_F", [0, 0, 0], 0]]]
];
};

ADDON = true;
2 changes: 1 addition & 1 deletion addons/logistics_wirecutter/functions/fnc_cutDownFence.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ if !(_unit call EFUNC(common,isSwimming)) then {
TRACE_1("Fence cutting successful",_this);
(_this select 0) params ["_unit", "_fence"];

_fence setDamage 1;
[QGVAR(destroyFence), [_fence]] call CBA_fnc_serverEvent;
if !(_unit call EFUNC(common,isSwimming)) then {
[_unit, "AmovPknlMstpSrasWrflDnon", 1] call EFUNC(common,doAnimation);
};
Expand Down
42 changes: 42 additions & 0 deletions addons/logistics_wirecutter/functions/fnc_destroyFence.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "script_component.hpp"
/*
* Author: BaerMitUmlaut
* Destroys the given fence and replaces it with a destroyed fence if possible.
*
* Arguments:
* 0: Fence <OBJECT>
*
* Return Value:
* None
*
* Example:
* [fence] call ace_logistics_wirecutter_fnc_destroyFence
*
* Public: No
*/

params ["_fence"];

private _fenceModel = toLower ((getModelInfo _fence)#0);

// If fence cannot be replaced with destroyed model, just knock it over
if !(_fenceModel in GVAR(replacements)) exitWith {
_fence setDamage 1;
};

// Remove old fence
if ([_fence] call CBA_fnc_isTerrainObject) then {
_fence setDamage 1;
_fence hideObjectGlobal true;
} else {
deleteVehicle _fence;
};

// Create replacement(s)
{
_x params ["_type", "_position", "_dir"];

private _replacement = _type createVehicle [0, 0, 0];
_replacement setPosWorld (_fence modelToWorldWorld _position);
_replacement setDir (direction _fence + _dir);
} forEach (GVAR(replacements) get _fenceModel);
1 change: 1 addition & 0 deletions addons/logistics_wirecutter/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"gm_gc_g501_sm70_02.p3d",\
"gm_gc_g501_sm70_03.p3d",\
"netfence_03_m_3m_f.p3d",\
"netfence_03_m_3m_hole_f.p3d",\
"netfence_03_m_3m_corner_f.p3d",\
"netfence_03_m_9m_f.p3d",\
"vineyardfence_01_f.p3d",\
Expand Down

0 comments on commit 61e8ae3

Please sign in to comment.