Skip to content

Commit

Permalink
add supressHide
Browse files Browse the repository at this point in the history
  • Loading branch information
Madin authored and Madin5 committed May 9, 2024
1 parent cd0f11a commit df71d41
Show file tree
Hide file tree
Showing 15 changed files with 187 additions and 0 deletions.
1 change: 1 addition & 0 deletions addons/supressHide/$PBOPREFIX$
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
z\afmf\addons\staticspawn
15 changes: 15 additions & 0 deletions addons/supressHide/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Extended_PreStart_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preStart));
};
};
class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preInit));
};
};
class Extended_PostInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_postInit));
};
};
1 change: 1 addition & 0 deletions addons/supressHide/CfgModuleCategories.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "script_component.hpp"
5 changes: 5 additions & 0 deletions addons/supressHide/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
PREP(EH);
PREP(hide);
PREP(init);
PREP(unhide);
PREP(unhideConditionLoop);
1 change: 1 addition & 0 deletions addons/supressHide/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "script_component.hpp"
4 changes: 4 additions & 0 deletions addons/supressHide/XEH_preInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "script_component.hpp"
ADDON = false;
#include "XEH_PREP.hpp"
ADDON = true;
2 changes: 2 additions & 0 deletions addons/supressHide/XEH_preStart.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include "script_component.hpp"
#include "XEH_PREP.hpp"
17 changes: 17 additions & 0 deletions addons/supressHide/config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "script_component.hpp"
class CfgPatches {
class ADDON {
name = COMPONENT;
units[] = {};
weapons[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {};
author = "Madin";
VERSION_CONFIG;
};
};


#include "CfgEventHandlers.hpp"

#include "CfgModuleCategories.hpp"
29 changes: 29 additions & 0 deletions addons/supressHide/functions/fn_EH.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
params [["_unit", objNull], ["_suppressedTime", 30]];

// hide when fired at
_unit addEventHandler ["Suppressed", {
params ["_unit", "_distance", "_shooter", "_instigator", "_ammoObject", "_ammoClassName", "_ammoConfig"];
if !(local _unit) exitWith {};
if (_unit distance _shooter < 25 + random 25) exitWith {};
_unit lookAt _shooter;
[_unit] call FUNC(Hide);

_unit setVariable ["AF_suppressedTime", time + random _suppressedTime];
}];

// hide on reload
_unit addEventHandler ["Fired", {
params ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_gunner"];
if (_unit ammo _muzzle > 0) exitWith {};
[_unit] call FUNC(Hide);
// [
// {
// _this ammo currentWeapon _this > 0
// },
// {
// _this call FUNC(Unhide);
// },
// _unit,
// 10
// ] call CBA_fnc_waitUntilAndExecute;
}];
29 changes: 29 additions & 0 deletions addons/supressHide/functions/fn_hide.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
params [["_unit", objNull]];
private _hidden = _unit getVariable ["AF_unitHidden", false];
if (_hidden) exitWith {};

private _unitPos = unitPos _unit;
if (_unitPos isEqualTo "Down") exitWith {};

if (_unitPos isEqualTo "Middle") then {
_unit playActionNow "PlayerProne";
_unit setUnitPos "Down";
_unit setVariable ["AF_unitStanceHide", _unitPos];
} else {
_unit playActionNow "PlayerCrouch";
_unit setUnitPos "Middle";
// _unit setUnitPos "Down";
_unit setVariable ["AF_unitStanceHide", "Up"];
};

_unit setVariable ["AF_unitHidden", true];

private _suppressedTime = _unit getVariable ["AF_suppressedTime", 30];

[
{
_this call FUNC(unhideConditionLoop);
},
_unit,
random _suppressedTime max 2
] call CBA_fnc_waitAndExecute;
14 changes: 14 additions & 0 deletions addons/supressHide/functions/fn_init.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
params [["_unit", objNull], ["_suppressedTime", 30]];
_unit setVariable ["AF_suppressedTime", _suppressedTime];

// disable lambs
_unit setVariable ["lambs_danger_disableAI", true];
if (isFormationLeader _unit) then {
group _unit setVariable ["lambs_danger_disableGroupAI", true];
};

if (unitPos _unit == "Auto") then {
_unit setUnitPos "Up";
};

[_unit, _suppressedTime] call FUNC(EH);
5 changes: 5 additions & 0 deletions addons/supressHide/functions/fn_unhide.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
params [["_unit", objNull]];

_unit setVariable ["AF_unitHidden", false];
private _unitPos = _unit getVariable ["AF_unitStanceHide", "Up"];
_unit setUnitPos _unitPos;
15 changes: 15 additions & 0 deletions addons/supressHide/functions/fn_unhideConditionLoop.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
params [["_unit", objNull]];

if !(alive _unit) exitWith {};

private _suppressedTime = _unit getVariable ["AF_suppressedTime", 30];
private _currentAmmo = _unit ammo currentWeapon _unit;

if (time < _suppressedTime || _currentAmmo == 0) exitWith {
[
{_this call FUNC(unhideConditionLoop)},
_this,
0
] call CBA_fnc_waitAndExecute;
};
_unit call AF_fnc_suppressUnhide;
14 changes: 14 additions & 0 deletions addons/supressHide/script_component.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#define COMPONENT staticspawn
#include "\z\afmf\addons\main\script_mod.hpp"

#define DEBUG_MODE_FULL
#define DISABLE_COMPILE_CACHE

#ifdef DEBUG_ENABLED_STATICSPAWN
#define DEBUG_MODE_FULL
#endif
#ifdef DEBUG_SETTINGS_STATICSPAWN
#define DEBUG_SETTINGS DEBUG_SETTINGS_STATICSPAWN
#endif

#include "\z\afmf\addons\main\script_macros.hpp"
35 changes: 35 additions & 0 deletions addons/supressHide/stringtable.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<Project name="MAI_2">
<Key ID="STR_MAI_sphereSize">
<Original>Distance</Original>
<Polish>Dystans</Polish>
</Key>
<Key ID="STR_MAI_sphereSizeShort">
<Original>The distance of checking the presence of players</Original>
<Polish>Dystans sprawdzania obecności graczy</Polish>
</Key>
<Key ID="STR_MAI_sphereDespawnDistance">
<Original>Despawn distance</Original>
<Polish>Dystans despawnu</Polish>
</Key>
<Key ID="STR_MAI_sphereDespawnDistanceShort">
<Original>The distance of checking the presence of players above which units will be removed. Added to spawn value.</Original>
<Polish>Dystans sprawdzania obecności graczy powyżej którego jednostki zostaną usunięte. Dodane do wartości spawnu.</Polish>
</Key>
<Key ID="STR_MAI_checkVisibility">
<Original>Visibility check</Original>
<Polish>Sprawdzanie widoczności</Polish>
</Key>
<Key ID="STR_MAI_checkVisibilityShort">
<Original>Unactive</Original>
<Polish>Nieaktywne</Polish>
</Key>
<Key ID="STR_MAI_sphereBackDistance">
<Original>Offset checking</Original>
<Polish>Przsunięcie sprawdzania</Polish>
</Key>
<Key ID="STR_MAI_sphereBackDistanceShort">
<Original>How far back will players be checked.</Original>
<Polish>Jak daleko do tyłu będzie sprawdzane obecność graczy.</Polish>
</Key>
</Project>

0 comments on commit df71d41

Please sign in to comment.