CBAfy AGM_Hearing

This commit is contained in:
Nicolás Badano 2015-01-13 01:17:52 -03:00
parent db7322e50a
commit 5d6fd9ab3e
20 changed files with 289 additions and 284 deletions

View File

@ -0,0 +1,7 @@
// Setting up old stuff for A3
class CfgAmmo {
class BulletBase;
class B_127x108_Ball: BulletBase {
audibleFire = 15;
};
};

View File

@ -0,0 +1,36 @@
class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preInit) );
};
};
class Extended_PostInit_EventHandlers {
class ADDON {
clientInit = QUOTE( call COMPILE_FILE(XEH_postInit.sqf) );
};
};
class Extended_Init_EventHandlers {
class CAManBase {
class GVAR(AddEarPlugs) {
init = QUOTE( if (local (_this select 0)) then {_this call FUNC(addEarPlugs)}; );
};
};
};
class Extended_FiredNear_EventHandlers {
class CAManBase {
class GVAR(FiredNear) {
clientFiredNear = QUOTE( if (_this select 0 == ACE_player) then {_this call FUNC(firedNear)}; );
};
};
};
class Extended_Explosion_EventHandlers {
class CAManBase {
class GVAR(ExplosionNear) {
clientExplosion = QUOTE( if (_this select 0 == #CE_player) then {_this call FUNC(explosionNear)}; );
};
};
};

View File

@ -0,0 +1,14 @@
class CfgSounds {
class ACE_EarRinging_Weak {
sound[] = {QUOTE(PATHOF(sounds\ACE_earringing_weak.wav),8,1.7};
titles[] = {};
};
class ACE_EarRinging_Medium {
sound[] = {QUOTE(PATHOF(sounds\ACE_earringing_medium.wav),8,1.7};
titles[] = {};
};
class ACE_EarRinging_Heavy {
sound[] = {QUOTE(PATHOF(sounds\ACE_earringing_heavy.wav),8,1.7};
titles[] = {};
};
};

View File

@ -0,0 +1,101 @@
#define MACRO_ADDITEM(ITEM,COUNT) class _xx_##ITEM { \
name = #ITEM; \
count = COUNT; \
};
class CfgVehicles {
class Man;
class CAManBase: Man {
class ACE_SelfActions {
class ACE_Equipment {
class ACE_PutInEarplugs {
displayName = "$STR_ACE_Hearing_Earbuds_On";
condition = QUOTE( !([_player] call FUNC(hasEarPlugsIn)) && {'ACE_EarBuds' in items _player} );
statement = QUOTE( [_player] call FUNC(putInEarPlugs) );
showDisabled = 0;
priority = 2.5;
icon = QUOTE(PATHOF(UI\ACE_earplugs_x_ca.paa));
hotkey = "E";
enableInside = 1;
};
class ACE_RemoveEarplugs {
displayName = "$STR_ACE_Hearing_Earbuds_Off";
condition = QUOTE( [_player] call FUNC(hasEarPlugsIn) );
statement = QUOTE( [_player] call FUNC(removeEarPlugs) );
showDisabled = 0;
priority = 2.5;
icon = QUOTE(PATHOF(UI\ACE_earplugs_x_ca.paa));
hotkey = "E";
enableInside = 1;
};
};
};
};
class ReammoBox_F;
class NATO_Box_Base;
class EAST_Box_Base;
class IND_Box_Base;
class FIA_Box_Base_F;
class Box_NATO_Support_F: NATO_Box_Base {
class TransportItems {
MACRO_ADDITEM(ACE_EarBuds,12)
};
};
class B_supplyCrate_F: ReammoBox_F {
class TransportItems {
MACRO_ADDITEM(ACE_EarBuds,12)
};
};
class Box_East_Support_F: EAST_Box_Base {
class TransportItems {
MACRO_ADDITEM(ACE_EarBuds,12)
};
};
class O_supplyCrate_F: B_supplyCrate_F {
class TransportItems {
MACRO_ADDITEM(ACE_EarBuds,12)
};
};
class Box_IND_Support_F: IND_Box_Base {
class TransportItems {
MACRO_ADDITEM(ACE_EarBuds,12)
};
};
class Box_FIA_Support_F: FIA_Box_Base_F {
class TransportItems {
MACRO_ADDITEM(ACE_EarBuds,12)
};
};
class I_supplyCrate_F: B_supplyCrate_F {
class TransportItems {
MACRO_ADDITEM(ACE_EarBuds,12)
};
};
class IG_supplyCrate_F: ReammoBox_F {
class TransportItems {
MACRO_ADDITEM(ACE_EarBuds,12)
};
};
class C_supplyCrate_F: ReammoBox_F {
class TransportItems {
MACRO_ADDITEM(ACE_EarBuds,12)
};
};
class ACE_Box_Misc: Box_NATO_Support_F {
class TransportItems {
MACRO_ADDITEM(ACE_EarBuds,12)
};
};
};

View File

@ -0,0 +1,15 @@
class CfgWeapons {
class ACE_ItemCore;
class InventoryItem_Base_F;
class ACE_EarBuds: ACE_ItemCore {
displayName = "$STR_ACE_Hearing_Earbuds_Name";
descriptionShort = "$STR_ACE_Hearing_Earbuds_Description";
model = QUOTE(PATHOF(ACE_earplugs.p3d);
picture = QUOTE(PATHOF(UI\ACE_earplugs_x_ca.paa);
scope = 2;
class ItemInfo: InventoryItem_Base_F {
mass = 1;
};
};
};

View File

@ -0,0 +1,55 @@
// by commy2 and CAA-Picard
#define STRENGHTODEAFNESS 3
#define MAXDEAFNESS 1.1
GVAR(currentDeafness) = 0;
GVAR(newStrength) = 0;
// Spawn volume updating process
0 spawn {
while {true} do {
_player = ACE_player;
// Check if new noises increase deafness
if (GVAR(newStrength) * STRENGHTODEAFNESS > GVAR(currentDeafness)) then {
GVAR(currentDeafness) = GVAR(newStrength) * STRENGHTODEAFNESS min MAXDEAFNESS;
};
GVAR(newStrength) = 0;
// Recover rate is slower if deafness is severe
_recoverRate = 0.01;
if (GVAR(currentDeafness) > 0.7) then {
_recoverRate = 0.005;
if (GVAR(currentDeafness) > 0.9) then {
_recoverRate = 0.002;
};
};
// Deafness recovers with time
GVAR(currentDeafness) = GVAR(currentDeafness) - _recoverRate max 0;
// needed until Bohemia fixes playSound to actually use the second argument
_volume = (1 - GVAR(currentDeafness) max 0)^2 max 0.1;
// Earplugs reduce hearing 20%
if ([_player] call FUNC(hasEarPlugsIn)) then {
_volume = _volume min 0.8;
};
// Reduce volume if player is unconscious
if (_player getVariable ["ACE_isUnconscious", false]) then {
_volume = _volume min 0.4;
};
if (!(missionNameSpace getVariable [QGVAR(disableVolumeUpdate), false])) then {
0.1 fadeSound _volume;
0.1 fadeSpeech _volume;
_player setVariable ["tf_globalVolume", _volume];
_player setVariable ["acre_sys_core_globalVolume", _volume];
};
//hintSilent format ["GVAR(currentDeafness), _Volume = %1, %2", GVAR(currentDeafness), _volume];
sleep 0.1;
};
};

View File

@ -0,0 +1,9 @@
#include "script_component.hpp"
PREP(addEarPlugs);
PREP(earRinging);
PREP(explosionNear);
PREP(firedNear);
PREP(hasEarPlugsIn);
PREP(putInEarPlugs);
PREP(removeEarPlugs);

View File

@ -1,64 +0,0 @@
// by commy2 and CAA-Picard
#define STRENGHTODEAFNESS 3
#define MAXDEAFNESS 1.1
AGM_CurrentDeafness = 0;
AGM_NewStrength = 0;
// Spawn volume updating process
0 spawn {
while {true} do {
_player = AGM_player;
// Check if new noises increase deafness
if (AGM_NewStrength * STRENGHTODEAFNESS > AGM_CurrentDeafness) then {
AGM_CurrentDeafness = AGM_NewStrength * STRENGHTODEAFNESS min MAXDEAFNESS;
// icon is CUT
/*if (AGM_CurrentDeafness > 0.4) then {
if (AGM_CurrentDeafness > 0.8) then {
[parseText "<img align='center' size='2.5' color='#FF0000' image='AGM_Hearing\UI\deafness_x_ca.paa'/>"] call AGM_Core_fnc_displayTextStructured;
} else {
[parseText "<img align='center' size='2.5' color='#FFFF00' image='AGM_Hearing\UI\deafness_x_ca.paa'/>"] call AGM_Core_fnc_displayTextStructured;
};
};*/
};
AGM_NewStrength = 0;
// Recover rate is slower if deafness is severe
_recoverRate = 0.01;
if (AGM_CurrentDeafness > 0.7) then {
_recoverRate = 0.005;
if (AGM_CurrentDeafness > 0.9) then {
_recoverRate = 0.002;
};
};
// Deafness recovers with time
AGM_CurrentDeafness = AGM_CurrentDeafness - _recoverRate max 0;
// needed until Bohemia fixes playSound to actually use the second argument
_volume = (1 - AGM_CurrentDeafness max 0)^2 max 0.1;
// Earplugs reduce hearing 20%
if ([_player] call AGM_Hearing_fnc_hasEarPlugsIn) then {
_volume = _volume min 0.8;
};
// Reduce volume if player is unconscious
if (_player getVariable ["AGM_isUnconscious", false]) then {
_volume = _volume min 0.4;
};
if (!(missionNameSpace getVariable ["AGM_Hearing_disableVolumeUpdate", false])) then {
0.1 fadeSound _volume;
0.1 fadeSpeech _volume;
_player setVariable ["tf_globalVolume", _volume];
_player setVariable ["acre_sys_core_globalVolume", _volume];
};
//hintSilent format ["AGM_CurrentDeafness, _Volume = %1, %2", AGM_CurrentDeafness, _volume];
sleep 0.1;
};
};

View File

@ -1,198 +1,23 @@
#include "script_component.hpp"
class CfgPatches { class CfgPatches {
class AGM_Hearing { class ADDON {
units[] = {}; units[] = {};
weapons[] = {"AGM_EarBuds"}; weapons[] = {"ACE_EarBuds"};
requiredVersion = 0.60; requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {AGM_Core, AGM_Interaction}; requiredAddons[] = {"ace_common"};
version = "0.95";
versionStr = "0.95";
versionAr[] = {0,95,0};
author[] = {"KoffeinFlummi", "CAA-Picard", "HopeJ", "commy2"}; author[] = {"KoffeinFlummi", "CAA-Picard", "HopeJ", "commy2"};
authorUrl = "https://github.com/KoffeinFlummi/"; authorUrl = "https://github.com/KoffeinFlummi/";
VERSION_CONFIG;
}; };
}; };
class CfgFunctions { #include "CfgEventHandlers.hpp"
class AGM_Hearing {
class AGM_Hearing {
file = "AGM_Hearing\functions";
class addEarPlugs;
class earRinging;
class explosionNear;
class firedNear;
class hasEarPlugsIn;
class putInEarPlugs;
class removeEarPlugs;
};
};
};
class Extended_PostInit_EventHandlers { #include "CfgVehicles.hpp"
class AGM_Hearing {
clientInit = "call compile preprocessFileLineNumbers '\AGM_Hearing\clientInit.sqf'";
};
};
class Extended_Init_EventHandlers { #include "CfgSounds.hpp"
class CAManBase {
class AGM_Hearing_AddEarPlugs {
init = "if (local (_this select 0)) then {_this call AGM_Hearing_fnc_addEarPlugs};";
};
};
};
class Extended_FiredNear_EventHandlers { #include "CfgWeapons.hpp"
class CAManBase {
class AGM_Hearing_FiredNear {
clientFiredNear = "if (_this select 0 == AGM_player) then {_this call AGM_Hearing_fnc_firedNear};";
};
};
};
class Extended_Explosion_EventHandlers { #include "CfgAmmo.hpp"
class CAManBase {
class AGM_Hearing_ExplosionNear {
clientExplosion = "if (_this select 0 == AGM_player) then {_this call AGM_Hearing_fnc_explosionNear};";
};
};
};
#define MACRO_ADDITEM(ITEM,COUNT) class _xx_##ITEM { \
name = #ITEM; \
count = COUNT; \
};
class CfgVehicles {
class Man;
class CAManBase: Man {
class AGM_SelfActions {
class AGM_Equipment {
class AGM_PutInEarplugs {
displayName = "$STR_AGM_Hearing_Earbuds_On";
condition = "!([_player] call AGM_Hearing_fnc_hasEarPlugsIn) && {'AGM_EarBuds' in items _player}";
statement = "[_player] call AGM_Hearing_fnc_putInEarPlugs";
showDisabled = 0;
priority = 2.5;
icon = "AGM_Hearing\UI\agm_earplugs_x_ca.paa";
hotkey = "E";
enableInside = 1;
};
class AGM_RemoveEarplugs {
displayName = "$STR_AGM_Hearing_Earbuds_Off";
condition = "[_player] call AGM_Hearing_fnc_hasEarPlugsIn";
statement = "[_player] call AGM_Hearing_fnc_removeEarPlugs";
showDisabled = 0;
priority = 2.5;
icon = "AGM_Hearing\UI\agm_earplugs_x_ca.paa";
hotkey = "E";
enableInside = 1;
};
};
};
};
class ReammoBox_F;
class NATO_Box_Base;
class EAST_Box_Base;
class IND_Box_Base;
class FIA_Box_Base_F;
class Box_NATO_Support_F: NATO_Box_Base {
class TransportItems {
MACRO_ADDITEM(AGM_EarBuds,12)
};
};
class B_supplyCrate_F: ReammoBox_F {
class TransportItems {
MACRO_ADDITEM(AGM_EarBuds,12)
};
};
class Box_East_Support_F: EAST_Box_Base {
class TransportItems {
MACRO_ADDITEM(AGM_EarBuds,12)
};
};
class O_supplyCrate_F: B_supplyCrate_F {
class TransportItems {
MACRO_ADDITEM(AGM_EarBuds,12)
};
};
class Box_IND_Support_F: IND_Box_Base {
class TransportItems {
MACRO_ADDITEM(AGM_EarBuds,12)
};
};
class Box_FIA_Support_F: FIA_Box_Base_F {
class TransportItems {
MACRO_ADDITEM(AGM_EarBuds,12)
};
};
class I_supplyCrate_F: B_supplyCrate_F {
class TransportItems {
MACRO_ADDITEM(AGM_EarBuds,12)
};
};
class IG_supplyCrate_F: ReammoBox_F {
class TransportItems {
MACRO_ADDITEM(AGM_EarBuds,12)
};
};
class C_supplyCrate_F: ReammoBox_F {
class TransportItems {
MACRO_ADDITEM(AGM_EarBuds,12)
};
};
class AGM_Box_Misc: Box_NATO_Support_F {
class TransportItems {
MACRO_ADDITEM(AGM_EarBuds,12)
};
};
};
class CfgSounds {
class AGM_EarRinging_Weak {
sound[] = {"\AGM_Hearing\sounds\agm_earringing_weak.wav",8,1.7};
titles[] = {};
};
class AGM_EarRinging_Medium {
sound[] = {"\AGM_Hearing\sounds\agm_earringing_medium.wav",8,1.7};
titles[] = {};
};
class AGM_EarRinging_Heavy {
sound[] = {"\AGM_Hearing\sounds\agm_earringing_heavy.wav",8,1.7};
titles[] = {};
};
};
class CfgWeapons {
class AGM_ItemCore;
class InventoryItem_Base_F;
class AGM_EarBuds: AGM_ItemCore {
displayName = "$STR_AGM_Hearing_Earbuds_Name";
descriptionShort = "$STR_AGM_Hearing_Earbuds_Description";
model = "\AGM_Hearing\agm_earplugs.p3d";
picture = "\AGM_Hearing\UI\agm_earplugs_x_ca.paa";
scope = 2;
class ItemInfo: InventoryItem_Base_F {
mass = 1;
};
};
};
// Setting up old stuff for A3
class CfgAmmo {
class BulletBase;
class B_127x108_Ball: BulletBase {
audibleFire = 15;
};
};

View File

@ -9,6 +9,7 @@
* Return value: * Return value:
* Nothing * Nothing
*/ */
#include "\z\ace\addons\hearing\script_component.hpp"
private ["_unit", "_launcher"]; private ["_unit", "_launcher"];
@ -18,7 +19,7 @@ _unit = _this select 0;
_launcher = secondaryWeapon _unit; _launcher = secondaryWeapon _unit;
if (_launcher != "") exitWith { if (_launcher != "") exitWith {
_unit addItem "AGM_EarBuds"; _unit addItem "ACE_EarBuds";
}; };
// otherwise add earplugs if the soldier has a big rifle // otherwise add earplugs if the soldier has a big rifle
@ -31,5 +32,5 @@ if (isNil "_magazine") exitWith {};
_ammo = getText (configFile >> "CfgMagazines" >> _magazine >> "ammo"); _ammo = getText (configFile >> "CfgMagazines" >> _magazine >> "ammo");
if (getNumber (configFile >> "CfgAmmo" >> _ammo >> "audiblefire") > 8) then { if (getNumber (configFile >> "CfgAmmo" >> _ammo >> "audiblefire") > 8) then {
_unit addItem "AGM_EarBuds"; _unit addItem "ACE_EarBuds";
}; };

View File

@ -9,41 +9,42 @@
* Return Value: * Return Value:
* none * none
*/ */
#include "\z\ace\addons\hearing\script_component.hpp"
private ["_unit", "_strength"]; private ["_unit", "_strength"];
_unit = _this select 0; _unit = _this select 0;
_strength = _this select 1; _strength = _this select 1;
if (_unit getVariable ["AGM_hasEarPlugsin", false] || {_unit getVariable ["X39_MedSys_var_hasEarplugs", false]}) then { if (_unit getVariable ["ACE_hasEarPlugsin", false]) then {
_strength = _strength / 4; _strength = _strength / 4;
}; };
AGM_NewStrength = AGM_NewStrength max _strength; GVAR(newStrength) = GVAR(newStrength) max _strength;
if (missionNamespace getVariable ["AGM_isEarRingingPlaying", false]) exitWith {}; if (missionNamespace getVariable [QGVAR(isEarRingingPlaying), false]) exitWith {};
if (_strength > 0.75) exitWith { if (_strength > 0.75) exitWith {
playSound "AGM_EarRinging_Heavy"; playSound "ACE_EarRinging_Heavy";
AGM_isEarRingingPlaying = true; GVAR(isEarRingingPlaying) = true;
0 spawn { 0 spawn {
sleep 7; sleep 7;
AGM_isEarRingingPlaying = false; GVAR(isEarRingingPlaying) = false;
}; };
}; };
if (_strength > 0.5) exitWith { if (_strength > 0.5) exitWith {
playSound "AGM_EarRinging_Medium"; playSound "ACE_EarRinging_Medium";
AGM_isEarRingingPlaying = true; GVAR(isEarRingingPlaying) = true;
0 spawn { 0 spawn {
sleep 5; sleep 5;
AGM_isEarRingingPlaying = false; GVAR(isEarRingingPlaying) = false;
}; };
}; };
if (_strength > 0.2) exitWith { if (_strength > 0.2) exitWith {
playSound "AGM_EarRinging_Weak"; playSound "ACE_EarRinging_Weak";
AGM_isEarRingingPlaying = true; GVAR(isEarRingingPlaying) = true;
0 spawn { 0 spawn {
sleep 3; sleep 3;
AGM_isEarRingingPlaying = false; GVAR(isEarRingingPlaying) = false;
}; };
}; };

View File

@ -9,6 +9,7 @@
* Return Value: * Return Value:
* none * none
*/ */
#include "\z\ace\addons\hearing\script_component.hpp"
private ["_unit", "_damage", "_strength"]; private ["_unit", "_damage", "_strength"];
@ -20,5 +21,5 @@ if (_strength < 0.01) exitWith {};
[_unit, _strength] spawn { [_unit, _strength] spawn {
sleep 0.2; sleep 0.2;
_this call AGM_Hearing_fnc_earRinging; _this call FUNC(earRinging);
}; };

View File

@ -9,6 +9,7 @@
* Return Value: * Return Value:
* none * none
*/ */
#include "\z\ace\addons\hearing\script_component.hpp"
private ["_unit", "_firer", "_distance", "_weapon", "_muzzle", "_mode", "_ammo", "_silencer", "_audibleFireCoef", "_loudness", "_strength"]; private ["_unit", "_firer", "_distance", "_weapon", "_muzzle", "_mode", "_ammo", "_silencer", "_audibleFireCoef", "_loudness", "_strength"];
@ -21,7 +22,7 @@ _mode = _this select 5;
_ammo = _this select 6; _ammo = _this select 6;
if (_weapon in ["Throw", "Put"]) exitWith {}; if (_weapon in ["Throw", "Put"]) exitWith {};
if (_unit != vehicle _unit && {!([_unit] call AGM_Core_fnc_isTurnedOut)}) exitWith {}; if (_unit != vehicle _unit && {!([_unit] call EFUNC(common,isTurnedOut))}) exitWith {};
_silencer = switch (_weapon) do { _silencer = switch (_weapon) do {
case (primaryWeapon _unit) : {primaryWeaponItems _unit select 0}; case (primaryWeapon _unit) : {primaryWeaponItems _unit select 0};
@ -47,5 +48,5 @@ if (_strength < 0.01) exitWith {};
[_unit, _strength] spawn { [_unit, _strength] spawn {
sleep 0.2; sleep 0.2;
_this call AGM_Hearing_fnc_earRinging; _this call FUNC(earRinging);
}; };

View File

@ -9,9 +9,10 @@
* Return value: * Return value:
* Boolean (Bool) * Boolean (Bool)
*/ */
#include "\z\ace\addons\hearing\script_component.hpp"
private "_unit"; private "_unit";
_unit = _this select 0; _unit = _this select 0;
_unit getVariable ["AGM_hasEarPlugsin", false] || {_unit getVariable ["X39_MedSys_var_hasEarplugs", false]} _unit getVariable ["ACE_hasEarPlugsin", false]

View File

@ -10,6 +10,7 @@
* Return Value: * Return Value:
* none * none
*/ */
#include "\z\ace\addons\hearing\script_component.hpp"
private "_player"; private "_player";
@ -20,7 +21,7 @@ _player removeItem "AGM_EarBuds";
_player setVariable ["AGM_hasEarPlugsIn", true, true]; _player setVariable ["AGM_hasEarPlugsIn", true, true];
[localize "STR_AGM_Hearing_Earbuds_Are_On"] call AGM_Core_fnc_displayTextStructured; [localize "STR_AGM_Hearing_Earbuds_Are_On"] call EFUNC(common,displayTextStructured);
/*// No Ear Buds in inventory, telling user /*// No Ear Buds in inventory, telling user
[localize "STR_AGM_Hearing_NoBuds"] call AGM_Core_fnc_displayTextStructured;*/ [localize "STR_AGM_Hearing_NoBuds"] call EFUNC(common,displayTextStructured);*/

View File

@ -10,18 +10,19 @@
* Return Value: * Return Value:
* none * none
*/ */
#include "\z\ace\addons\hearing\script_component.hpp"
private "_player"; private "_player";
_player = _this select 0; _player = _this select 0;
if !(_player canAdd "AGM_EarBuds") exitWith { // inventory full if !(_player canAdd "ACE_EarBuds") exitWith { // inventory full
[localize "STR_AGM_Hearing_Inventory_Full"] call AGM_Core_fnc_displayTextStructured; [localize "STR_ACE_Hearing_Inventory_Full"] call EFUNC(common,displayTextStructured);
}; };
// Buds already in and removing them. // Buds already in and removing them.
_player addItem "AGM_EarBuds"; _player addItem "ACE_EarBuds";
_player setVariable ["AGM_hasEarPlugsIn", false, true]; _player setVariable ["ACE_hasEarPlugsIn", false, true];
[localize "STR_AGM_Hearing_Earbuds_Are_Off"] call AGM_Core_fnc_displayTextStructured; [localize "STR_ACE_Hearing_Earbuds_Are_Off"] call EFUNC(common,displayTextStructured);