← Go back

Arma 3: Not another ear plugs script!


Posted on October 16, 2017 at 00:15 (GMT +00:00) by Colin



An SQF script for inserting and removing virtual earplugs!

So probably just about everyone has meddled with an ear plugs script for Arma. When I first messed around with SQF a couple of weeks ago I decided I would first make this legendary *smirk* script to hone my SQF skillz. I originally have written it to be a part of my upcoming game mode "Decay", but I decided to try make most of the functionality modular, this means it was simple enough to make it stand-alone.


/////////////////////////////////////////////////////////////////////////////////
//
// EarPlugs - part of PixeL_GaMMa library.
// Simulate having earplugs in, allowing you to hear radio over other noises
// Copyright (c) Colin J.D. Stewart. All rights reserved
// APL-ND License - https://www.bistudio.com/community/licenses/arma-public-license-nd
//
/////////////////////////////////////////////////////////////////////////////////

if (!isDedicated) then {
	PX_fnc_earPlugsInsert = {
		PX_earPlugActive = true;
		1 fadeSound 0.2;	
		player removeAction PX_earPlugAction;
		hint "Ear plugs have been inserted!";
		PX_earPlugAction = player addAction [("<t color='#FF0000'>Remove Ear Plugs</t>"), {call PX_fnc_earPlugsRemove}, [], 1, false, true];
	};

	PX_fnc_earPlugsRemove = {
		PX_earPlugActive = false;
		1 fadeSound 1;
		player removeAction PX_earPlugAction;
		hint "Ear plugs have been removed!";
		PX_earPlugAction = player addAction [("<t color='#00FF00'>Insert Ear Plugs</t>"), {call PX_fnc_earPlugsInsert}, [], 1, false, true];	
	};

	PX_earPlugActive = false;
	player addEventHandler ["Respawn", {
		if (PX_earPlugActive) then {
			PX_earPlugAction = player addAction [("<t color='#FF0000'>Remove Ear Plugs</t>"), {call PX_fnc_earPlugsRemove}, [], 1, false, true];
		} else {
			PX_earPlugAction = player addAction [("<t color='#00FF00'>Insert Ear Plugs</t>"), {call PX_fnc_earPlugsInsert}, [], 1, false, true];
		};	
	}];
	player addEventHandler ["Killed", { player removeAction PX_earPlugAction; }];
};

This script is ran client-side, and is simple to add to any of your missions. Create a sub-folder "PX" and a file inside "px_earplugs.sqf" inside your mission folder, paste the code into the file and save. Now simply execute it from your init.sqf in your mission. (note to self: Write some Arma 3 mission creation tutorials).

Your init.sqf file should contain something like this:

// execute ear plugs script
[] execVM "PX\px_earplugs.sqf";


If you find this useful or you have any issues, please drop me a comment below, now play your mission and use your player context menu for inserting and removing your ear-plugs!
/Scripting/Programming/Game Modding