Jump to content

Very simple earplugs script


js2k6

Recommended Posts

Hi everyone,

Made a very basic script for earplugs for A2 Epoch

This method requires that you have dayz_spaceInterrupt.sqf in your mission.pbo

 

I use snap pro in my server, so my space interrupt file is located at custom\snap_pro\dayz_spaceinterrupt.sqf

 

look for the line that says

// Disable ESC after death
if (_dikCode == 0x01 && r_player_dead) then {
	_handled = true;
};

then add this below

if (_dikCode == 0x16) then
    {
        if (soundVolume == 1) then {
            1 fadeSound 0.25;
            hintSilent "Earplugs Inserted";
        }
            else
        {
            1 fadeSound 1;
            hintSilent "Earplugs Removed";
        };
    };

0x16 is the letter U,

 

you can find a list of all other available keys at

https://community.bistudio.com/wiki/DIK_KeyCodes

 

You can let your players know about this feature in your servers welcome credits or by adding a system chat message in init.sqf

 

Oh well, enjoy.

Link to comment
Share on other sites

this just makes everything more quiet at a key press. engine, gunshots, etc
it cuts the overall volume to 25%

 

https://community.bistudio.com/wiki/fadeSound

 

for instance 5 fadesound 0; would cut sound to 0 over the course of 5 seconds.

or as i do in the space interrupt file. i cut the sound to 25% in 1 second.

 

i find it to be mostly useful in choppers, its nice not going deaf.

we use something very similar in our weekly co-op tactical missions. decided we needed it in arma 2 dayz epoch aswell

Link to comment
Share on other sites

  • 1 month later...

private ["_dikCode","_handled","_primaryWeapon","_secondaryWeapon","_nearbyObjects","_nill","_shift","_ctrl","_alt","_dropPrimary","_dropSecondary","_iItem","_removed","_iPos","_radius","_item"];

_dikCode = _this select 1;
 
_handled = false;
 
if (_dikCode in[0x02,0x03,0x04,0x58,0x57,0x44,0x43,0x42,0x41,0x40,0x3F,0x3E,0x3D,0x3C,0x3B,0x0B,0x0A,0x09,0x08,0x07,0x06,0x05]) then {
_handled = true;
};
 
if ((_dikCode == 0x3E or _dikCode == 0x0F or _dikCode == 0xD3)) then {
if(diag_tickTime - dayz_lastCheckBit > 10) then {
dayz_lastCheckBit = diag_tickTime;
call dayz_forceSave;
};
call dayz_EjectPlayer;
};
 
// esc
if (_dikCode == 0x01) then {
DZE_cancelBuilding = true;
call dayz_EjectPlayer;
};
// Disable ESC after death
if (_dikCode == 0x01 && r_player_dead) then {
_handled = true;
};
 
// surrender 
if (_dikCode in actionKeys "Surrender") then {
 
_vehicle = vehicle player;
_inVehicle = (_vehicle != player);
_onLadder = (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "onLadder")) == 1;
_canDo = (!r_drag_sqf and !r_player_unconscious and !_onLadder and !_inVehicle);
 
if (_canDo and !DZE_Surrender and !(player isKindOf  "PZombie_VB")) then {
DZE_Surrender = true;
_dropPrimary = false;
_dropSecondary = false;
 
_primaryWeapon = primaryWeapon player;
if (_primaryWeapon != "") then {_dropPrimary = true;};
_secondaryWeapon = "";
{
if ((getNumber (configFile >> "CfgWeapons" >> _x >> "Type")) == 2) exitWith {
_secondaryWeapon = _x;
};
} forEach (weapons player);
if (_secondaryWeapon != "") then {_dropSecondary = true;};
 
if (_dropPrimary or _dropSecondary) then {
player playActionNow "PutDown";
_iPos = getPosATL player;
_radius = 1;
_item = createVehicle ["WeaponHolder", _iPos, [], _radius, "CAN_COLLIDE"];
_item setposATL _iPos;
if (_dropPrimary) then {
_iItem = _primaryWeapon;
_removed = ([player,_iItem,1] call BIS_fnc_invRemove);
if (_removed == 1) then {
_item addWeaponCargoGlobal [_iItem,1];
};
};
if (_dropSecondary) then {
_iItem = _secondaryWeapon;
_removed = ([player,_iItem,1] call BIS_fnc_invRemove);
if (_removed == 1) then {
_item addWeaponCargoGlobal [_iItem,1];
};
};
player reveal _item;
};
 
// set publicvariable that allows other player to access gear
player setVariable ["DZE_Surrendered", true, true];
// surrender animation
player playMove "AmovPercMstpSsurWnonDnon";
};
_handled = true;
};
 
if (_dikCode in actionKeys "MoveForward") exitWith {r_interrupt = true; if (DZE_Surrender) then {call dze_surrender_off};};
if (_dikCode in actionKeys "MoveLeft") exitWith {r_interrupt = true; if (DZE_Surrender) then {call dze_surrender_off};};
if (_dikCode in actionKeys "MoveRight") exitWith {r_interrupt = true; if (DZE_Surrender) then {call dze_surrender_off};};
if (_dikCode in actionKeys "MoveBack") exitWith {r_interrupt = true; if (DZE_Surrender) then {call dze_surrender_off};};
 
//Prevent exploit of drag body
if ((_dikCode in actionKeys "Prone") and r_drag_sqf) exitWith { force_dropBody = true; };
if ((_dikCode in actionKeys "Crouch") and r_drag_sqf) exitWith { force_dropBody = true; };
 
_shift = _this select 2;
_ctrl = _this select 3;
_alt = _this select 4;
 
//diag_log format["Keypress: %1", _this];
if ((_dikCode in actionKeys "Gear") and (vehicle player != player) and !_shift and !_ctrl and !_alt && !dialog) then {
createGearDialog [player, "RscDisplayGear"];
_handled = true;
};
 
if (_dikCode in (actionKeys "GetOver")) then {
 
if (player isKindOf  "PZombie_VB") then {
_handled = true;
DZE_PZATTACK = true;
} else {
_nearbyObjects = nearestObjects[getPosATL player, dayz_disallowedVault, 8];
if (count _nearbyObjects > 0) then {
if((diag_tickTime - dayz_lastCheckBit > 4)) then {
[objNull, player, rSwitchMove,"GetOver"] call RE;
player playActionNow "GetOver";
dayz_lastCheckBit = diag_tickTime;
} else {
_handled = true;
};
};
};
};
//if (_dikCode == 57) then {_handled = true}; // space
//if (_dikCode in actionKeys 'MoveForward' or _dikCode in actionKeys 'MoveBack') then {r_interrupt = true};
if (_dikCode == 210) then {
_nill = execvm "\z\addons\dayz_code\actions\playerstats.sqf";
};
 
if (_dikCode in actionKeys "ForceCommandingMode") then {_handled = true};
if (_dikCode in actionKeys "PushToTalk" and (diag_tickTime - dayz_lastCheckBit > 10)) then {
dayz_lastCheckBit = diag_tickTime;
[player,50,true,(getPosATL player)] spawn player_alertZombies;
};
if (_dikCode in actionKeys "VoiceOverNet" and (diag_tickTime - dayz_lastCheckBit > 10)) then {
dayz_lastCheckBit = diag_tickTime;
[player,50,true,(getPosATL player)] spawn player_alertZombies;
};
if (_dikCode in actionKeys "PushToTalkDirect" and (diag_tickTime - dayz_lastCheckBit > 10)) then {
dayz_lastCheckBit = diag_tickTime;
[player,15,false,(getPosATL player)] spawn player_alertZombies;
};
if (_dikCode in actionKeys "Chat" and (diag_tickTime - dayz_lastCheckBit > 10)) then {
dayz_lastCheckBit = diag_tickTime;
[player,15,false,(getPosATL player)] spawn player_alertZombies;
};
if (_dikCode in actionKeys "User20" and (diag_tickTime - dayz_lastCheckBit > 5)) then {
dayz_lastCheckBit = diag_tickTime;
_nill = execvm "\z\addons\dayz_code\actions\playerstats.sqf";
};
 
// numpad 8 0x48 now pgup 0xC9 1
if ((_dikCode == 0xC9 and (!_alt or !_ctrl)) or (_dikCode in actionKeys "User15")) then {
DZE_Q = true;
};
// numpad 2 0x50 now pgdn 0xD1
if ((_dikCode == 0xD1 and (!_alt or !_ctrl)) or (_dikCode in actionKeys "User16")) then {
DZE_Z = true;
};
 
 
// numpad 8 0x48 now pgup 0xC9 0.1
if ((_dikCode == 0xC9 and (_alt and !_ctrl)) or (_dikCode in actionKeys "User13")) then {
DZE_Q_alt = true;
};
// numpad 2 0x50 now pgdn 0xD1
if ((_dikCode == 0xD1 and (_alt and !_ctrl)) or (_dikCode in actionKeys "User14")) then {
DZE_Z_alt = true;
};
 
 
// numpad 8 0x48 now pgup 0xC9 0.01
if ((_dikCode == 0xC9 and (!_alt and _ctrl)) or (_dikCode in actionKeys "User7")) then {
DZE_Q_ctrl = true;
};
// numpad 2 0x50 now pgdn 0xD1
if ((_dikCode == 0xD1 and (!_alt and _ctrl)) or (_dikCode in actionKeys "User8")) then {
DZE_Z_ctrl = true;
};
 
 
 
 
// numpad 4 0x4B now Q 0x10
if (_dikCode == 0x10 or (_dikCode in actionKeys "User17")) then {
DZE_4 = true;
};
// numpad 6 0x4D now E 0x12
if (_dikCode == 0x12 or (_dikCode in actionKeys "User18")) then {
DZE_6 = true;
};
// numpad 5 0x4C now space 0x39
if (_dikCode == 0x39 or (_dikCode in actionKeys "User19")) then {
DZE_5 = true;
};
 
// F key
if ((_dikCode == 0x21 and (!_alt and !_ctrl)) or (_dikCode in actionKeys "User6")) then {
DZE_F = true;
};
 
_handled

 
Thats before adding anything
Link to comment
Share on other sites

Added it to my test server and it works fine here 

private ["_dikCode","_handled","_primaryWeapon","_secondaryWeapon","_nearbyObjects","_nill","_shift","_ctrl","_alt","_dropPrimary","_dropSecondary","_iItem","_removed","_iPos","_radius","_item"];
_dikCode = _this select 1;
 
_handled = false;
 
if (_dikCode in[0x02,0x03,0x04,0x58,0x57,0x44,0x43,0x42,0x41,0x40,0x3F,0x3E,0x3D,0x3C,0x3B,0x0B,0x0A,0x09,0x08,0x07,0x06,0x05]) then {
_handled = true;
};
 
if ((_dikCode == 0x3E or _dikCode == 0x0F or _dikCode == 0xD3)) then {
if(diag_tickTime - dayz_lastCheckBit > 10) then {
dayz_lastCheckBit = diag_tickTime;
call dayz_forceSave;
};
call dayz_EjectPlayer;
};
 
// esc
if (_dikCode == 0x01) then {
DZE_cancelBuilding = true;
call dayz_EjectPlayer;
};
// Disable ESC after death
if (_dikCode == 0x01 && r_player_dead) then {
_handled = true;
};
 
if (_dikCode == 0x16) then
    {
        if (soundVolume == 1) then {
            1 fadeSound 0.25;
            hintSilent "Earplugs Inserted";
        }
            else
        {
            1 fadeSound 1;
            hintSilent "Earplugs Removed";
        };
    };
 
// surrender 
if (_dikCode in actionKeys "Surrender") then {
 
_vehicle = vehicle player;
_inVehicle = (_vehicle != player);
_onLadder = (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "onLadder")) == 1;
_canDo = (!r_drag_sqf and !r_player_unconscious and !_onLadder and !_inVehicle);
 
if (_canDo and !DZE_Surrender and !(player isKindOf  "PZombie_VB")) then {
DZE_Surrender = true;
_dropPrimary = false;
_dropSecondary = false;
 
_primaryWeapon = primaryWeapon player;
if (_primaryWeapon != "") then {_dropPrimary = true;};
_secondaryWeapon = "";
{
if ((getNumber (configFile >> "CfgWeapons" >> _x >> "Type")) == 2) exitWith {
_secondaryWeapon = _x;
};
} forEach (weapons player);
if (_secondaryWeapon != "") then {_dropSecondary = true;};
 
if (_dropPrimary or _dropSecondary) then {
player playActionNow "PutDown";
_iPos = getPosATL player;
_radius = 1;
_item = createVehicle ["WeaponHolder", _iPos, [], _radius, "CAN_COLLIDE"];
_item setposATL _iPos;
if (_dropPrimary) then {
_iItem = _primaryWeapon;
_removed = ([player,_iItem,1] call BIS_fnc_invRemove);
if (_removed == 1) then {
_item addWeaponCargoGlobal [_iItem,1];
};
};
if (_dropSecondary) then {
_iItem = _secondaryWeapon;
_removed = ([player,_iItem,1] call BIS_fnc_invRemove);
if (_removed == 1) then {
_item addWeaponCargoGlobal [_iItem,1];
};
};
player reveal _item;
};
 
// set publicvariable that allows other player to access gear
player setVariable ["DZE_Surrendered", true, true];
// surrender animation
player playMove "AmovPercMstpSsurWnonDnon";
};
_handled = true;
};
 
if (_dikCode in actionKeys "MoveForward") exitWith {r_interrupt = true; if (DZE_Surrender) then {call dze_surrender_off};};
if (_dikCode in actionKeys "MoveLeft") exitWith {r_interrupt = true; if (DZE_Surrender) then {call dze_surrender_off};};
if (_dikCode in actionKeys "MoveRight") exitWith {r_interrupt = true; if (DZE_Surrender) then {call dze_surrender_off};};
if (_dikCode in actionKeys "MoveBack") exitWith {r_interrupt = true; if (DZE_Surrender) then {call dze_surrender_off};};
 
//Prevent exploit of drag body
if ((_dikCode in actionKeys "Prone") and r_drag_sqf) exitWith { force_dropBody = true; };
if ((_dikCode in actionKeys "Crouch") and r_drag_sqf) exitWith { force_dropBody = true; };
 
_shift = _this select 2;
_ctrl = _this select 3;
_alt = _this select 4;
 
//diag_log format["Keypress: %1", _this];
if ((_dikCode in actionKeys "Gear") and (vehicle player != player) and !_shift and !_ctrl and !_alt && !dialog) then {
createGearDialog [player, "RscDisplayGear"];
_handled = true;
};
 
if (_dikCode in (actionKeys "GetOver")) then {
 
if (player isKindOf  "PZombie_VB") then {
_handled = true;
DZE_PZATTACK = true;
} else {
_nearbyObjects = nearestObjects[getPosATL player, dayz_disallowedVault, 8];
if (count _nearbyObjects > 0) then {
if((diag_tickTime - dayz_lastCheckBit > 4)) then {
[objNull, player, rSwitchMove,"GetOver"] call RE;
player playActionNow "GetOver";
dayz_lastCheckBit = diag_tickTime;
} else {
_handled = true;
};
};
};
};
//if (_dikCode == 57) then {_handled = true}; // space
//if (_dikCode in actionKeys 'MoveForward' or _dikCode in actionKeys 'MoveBack') then {r_interrupt = true};
if (_dikCode == 210) then {
_nill = execvm "\z\addons\dayz_code\actions\playerstats.sqf";
};
 
if (_dikCode in actionKeys "ForceCommandingMode") then {_handled = true};
if (_dikCode in actionKeys "PushToTalk" and (diag_tickTime - dayz_lastCheckBit > 10)) then {
dayz_lastCheckBit = diag_tickTime;
[player,50,true,(getPosATL player)] spawn player_alertZombies;
};
if (_dikCode in actionKeys "VoiceOverNet" and (diag_tickTime - dayz_lastCheckBit > 10)) then {
dayz_lastCheckBit = diag_tickTime;
[player,50,true,(getPosATL player)] spawn player_alertZombies;
};
if (_dikCode in actionKeys "PushToTalkDirect" and (diag_tickTime - dayz_lastCheckBit > 10)) then {
dayz_lastCheckBit = diag_tickTime;
[player,15,false,(getPosATL player)] spawn player_alertZombies;
};
if (_dikCode in actionKeys "Chat" and (diag_tickTime - dayz_lastCheckBit > 10)) then {
dayz_lastCheckBit = diag_tickTime;
[player,15,false,(getPosATL player)] spawn player_alertZombies;
};
if (_dikCode in actionKeys "User20" and (diag_tickTime - dayz_lastCheckBit > 5)) then {
dayz_lastCheckBit = diag_tickTime;
_nill = execvm "\z\addons\dayz_code\actions\playerstats.sqf";
};
 
// numpad 8 0x48 now pgup 0xC9 1
if ((_dikCode == 0xC9 and (!_alt or !_ctrl)) or (_dikCode in actionKeys "User15")) then {
DZE_Q = true;
};
// numpad 2 0x50 now pgdn 0xD1
if ((_dikCode == 0xD1 and (!_alt or !_ctrl)) or (_dikCode in actionKeys "User16")) then {
DZE_Z = true;
};
 
 
// numpad 8 0x48 now pgup 0xC9 0.1
if ((_dikCode == 0xC9 and (_alt and !_ctrl)) or (_dikCode in actionKeys "User13")) then {
DZE_Q_alt = true;
};
// numpad 2 0x50 now pgdn 0xD1
if ((_dikCode == 0xD1 and (_alt and !_ctrl)) or (_dikCode in actionKeys "User14")) then {
DZE_Z_alt = true;
};
 
 
// numpad 8 0x48 now pgup 0xC9 0.01
if ((_dikCode == 0xC9 and (!_alt and _ctrl)) or (_dikCode in actionKeys "User7")) then {
DZE_Q_ctrl = true;
};
// numpad 2 0x50 now pgdn 0xD1
if ((_dikCode == 0xD1 and (!_alt and _ctrl)) or (_dikCode in actionKeys "User8")) then {
DZE_Z_ctrl = true;
};
 
 
 
 
// numpad 4 0x4B now Q 0x10
if (_dikCode == 0x10 or (_dikCode in actionKeys "User17")) then {
DZE_4 = true;
};
// numpad 6 0x4D now E 0x12
if (_dikCode == 0x12 or (_dikCode in actionKeys "User18")) then {
DZE_6 = true;
};
// numpad 5 0x4C now space 0x39
if (_dikCode == 0x39 or (_dikCode in actionKeys "User19")) then {
DZE_5 = true;
};
 
// F key
if ((_dikCode == 0x21 and (!_alt and !_ctrl)) or (_dikCode in actionKeys "User6")) then {
DZE_F = true;
};
 
_handled

Link to comment
Share on other sites

  • 4 weeks later...

Does this auto insert? Cause when I hit U or any key I change it to nothing happens

 

 

No it doesn't, this script works perfectly fine for me and many others, have a play around with the code or where you have placed the code,

its obviously an error on your end

Link to comment
Share on other sites

Can I have two Space Interrupt files? I installed snap building after I added earplugs and not only did the snap pro make the earplugs stop working but it also made my group system not work

 

No, you can't. The second one to be called will override any custom stuff in the first one. Just add the earplug code lines to the Snap Building file? 

Link to comment
Share on other sites

  • 1 month later...

I would also recommend: (I don't recommend anymore haha)

if (_dikCode == 0x16) then
    {
///Having it activate if the sound is above .25 not if its 1 because some people might usually play on .5 and want to use earplugs.. :) (hope i didn't misunderstand the function, should be right though
        if (soundVolume > 0.25) then {
            1 fadeSound 0.25;
            hintSilent "Earplugs Inserted";
        }
            else
        {
            1 fadeSound 1;
            hintSilent "Earplugs Removed";
        };
    };
Edited by GoldEagle
Link to comment
Share on other sites

  • 2 weeks later...

I would also recommend: 

if (_dikCode == 0x16) then...

The fadeSound function doesn't affect the game volume as set by the player in the options menu. Even if your game volume is turned off in the options menu soundVolume could be a greater than zero value.

Longer version:
To calculate the volume of a given sound the engine takes into account; the specified volume of that sound as defined in a config or internally, the distance from the player to that sound source, soundVolume and the volume set by the player in the options menu. Once it has all those it can then calculate the final output volume for a given sound. This explains the reason why soundVolume and the user set volume do not correlate, they are recognised internally to be two separate values not one.
I may be simplifying the process taken to calculate final volumes but nevertheless it allows you to understand better about the fadeSound and soundVolume functions.
 

Link to comment
Share on other sites

The fadeSound function doesn't affect the game volume as set by the player in the options menu. Even if your game volume is turned off in the options menu soundVolume could be a greater than zero value.

Longer version:
To calculate the volume of a given sound the engine takes into account; the specified volume of that sound as defined in a config or internally, the distance from the player to that sound source, soundVolume and the volume set by the player in the options menu. Once it has all those it can then calculate the final output volume for a given sound. This explains the reason why soundVolume and the user set volume do not correlate, they are recognised internally to be two separate values not one.
I may be simplifying the process taken to calculate final volumes but nevertheless it allows you to understand better about the fadeSound and soundVolume functions.
 

 

 

 

Ok, thanks for the answer, you always learn something each day!  :D

Link to comment
Share on other sites

  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...