Jump to content
Sign in to follow this  
Janat

Alarm script for stealth missions

Recommended Posts

So, I've been developing an alarm script for my mission Sabotage: Shapur. Now I have a working script and thought I'd share it here.

You can set 6 parameters:

- List of AI who receive your location info when the alarm will sound

- Name of the first marker

- Total amount of markers

- Knowsabout value before alarm will be set off

- Delay from detection to the alarm sounding (if you can kill the units who spotted you within this delay, the alarm will not sound)

- Debug messages (0 = OFF, no value = off, any other value = ON)

Note: place a game logic with

alarm1 = 0

in init field, otherwise the script will not fire.

Example:

alarmOn = [list aiArea, "ringalert", 3, 0.08, 5, 1]
[i](AI list, marker name, marker count, knowsabout value, delay, debug)[/i]

You can set up to ten alarm sound locations by creating markers. The first marker can be given any name. All other marker names should follow this structure:

markername_n

, where n is the ordinal number of the marker. So you can just copy and paste the first marker all around the map. You can set up to 10 sound sources each time you execute the script.

Example:

ringalert, ringalert_1, ringalert_2, ringalert_3, ringalert_4, ringalert_5, ringalert_6, ringalert_7, ringalert_8, ringalert_9
[i]You have set the marker name parameter to be "ringalert" (with quotes).[/i]

Take a look at the sample mission to better see how it should be set up.

Feel free to use this script in any mission. Please tell me if you have ideas to make this script even better.

The script doesn't work perfectly if an enemy group with more than one unit sees you. If a group that consists of more than one enemy unit spots you, no matter what the alarm will be set off. The alarm will be deactivated soon after that (if no other group has spotted you).

Here's the script (new tested version):

private ["_snd", "_snd1", "_snd2", "_snd3", "_snd4", "_snd5", "_snd6", "_snd7", "_snd8", "_snd9", "_aiList", "_markerName", "_detSens", "_detDelay", "_debug", "_markerCount"];

_aiList = _this select 0;
_markerName = _this select 1;
_markerCount =  floor (_this select 2);
_detSens = _this select 3;
_detDelay = _this select 4;
_debug = _this select 5;

// Checks if parameters have been given in correct form
if ((_markerCount < 0) or (_markerCount > 10)) then {
_markerCount = 0
} else {
};

if ((_detSens < 0) or (_detSens >= 1)) then {
_detSens = 0.07
} else {
};

if (_detDelay < 0) then {
_detDelay = 5
} else {
};

if (_debug == 0) then {
} else {
_debug = 1
};
// End of checks

// Checks if alarm is already on
if (alarm1 == 0) then {

{if ((_x knowsAbout player) > _detSens) then {

if (_debug == 1) then {
	hint format["noticed by enemy\nMarker Name Is %1_2", _markerName];
} else {
};

sleep _detDelay;


if (_x knowsAbout player > _detSens) then {

	alarm1 = 1;

	if (_debug == 1) then {
		hint "alarm activated"
	} else {
	};

	sleep 1;

	switch (_markerCount) do {

		case 0: {
	        if (_debug == 1) then {
	            hint "creating 0 sound sources"
	        } else {
	        };

			_x reveal player;
			_x setBehaviour "COMBAT";
			_x setCombatMode "YELLOW";
			_x setSpeedMode "NORMAL";

			while {(_x knowsAbout player) > 0} do {sleep 30};

			if (_debug == 1) then {
				hint "alarm off"
			} else {
			};

			alarm1 = 0;
		};

	    case 1: {
	        if (_debug == 1) then {
	            hint "creating 1 sound sources"
	        } else {
	        };
			// Starts creating alarm sounds to selected marker positions
				_snd = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1", _markerName]), [], 0];
			// End of alarm sound creating

			_x reveal player;
			_x setBehaviour "COMBAT";
			_x setCombatMode "YELLOW";
			_x setSpeedMode "NORMAL";

			while {(_x knowsAbout player) > 0} do {sleep 30};

			if (_debug == 1) then {
				hint "alarm off"
			} else {
			};

			// Starts alarm sound deletion
				deleteVehicle _snd;
			// End of alarm sound deletion

			alarm1 = 0;
		};

		case 2: {
			if (_debug == 1) then {
				hint "creating 2 sound sources"
			} else {
			};
			// Starts creating alarm sounds to selected marker positions
				_snd = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1", _markerName]), [], 0];
				_snd1 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_1", _markerName]), [], 0];
			// End of alarm sound creating

			_x reveal player;
			_x setBehaviour "COMBAT";
			_x setCombatMode "YELLOW";
			_x setSpeedMode "NORMAL";

			while {(_x knowsAbout player) > 0} do {sleep 30};

			if (_debug == 1) then {
				hint "alarm off"
			} else {
			};

			// Starts alarm sound deletion
				deleteVehicle _snd;
				deleteVehicle _snd1;
			// End of alarm sound deletion

			alarm1 = 0;
		};

		case 3: {
			if (_debug == 1) then {
				hint "creating 3 sound sources"
			} else {
			};
			// Starts creating alarm sounds to selected marker positions
				_snd = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1", _markerName]), [], 0];
				_snd1 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_1", _markerName]), [], 0];
				_snd2 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_2", _markerName]), [], 0];
			// End of alarm sound creating

			_x reveal player;
			_x setBehaviour "COMBAT";
			_x setCombatMode "YELLOW";
			_x setSpeedMode "NORMAL";

			while {(_x knowsAbout player) > 0} do {sleep 30};

			if (_debug == 1) then {
				hint "alarm off"
			} else {
			};

			// Starts alarm sound deletion
				deleteVehicle _snd;
				deleteVehicle _snd1;
				deleteVehicle _snd2;
			// End of alarm sound deletion

			alarm1 = 0;
		};

		case 4: {
			if (_debug == 1) then {
				hint "creating 4 sound sources"
			} else {
			};
			// Starts creating alarm sounds to selected marker positions
				_snd = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1", _markerName]), [], 0];
				_snd1 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_1", _markerName]), [], 0];
				_snd2 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_2", _markerName]), [], 0];
				_snd3 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_3", _markerName]), [], 0];
			// End of alarm sound creating

			_x reveal player;
			_x setBehaviour "COMBAT";
			_x setCombatMode "YELLOW";
			_x setSpeedMode "NORMAL";

			while {(_x knowsAbout player) > 0} do {sleep 30};

			if (_debug == 1) then {
				hint "alarm off"
			} else {
			};

			// Starts alarm sound deletion
				deleteVehicle _snd;
				deleteVehicle _snd1;
				deleteVehicle _snd2;
				deleteVehicle _snd3;
			// End of alarm sound deletion

			alarm1 = 0;
		};

		case 5: {
			if (_debug == 1) then {
				hint "creating 5 sound sources"
			} else {
			};
			// Starts creating alarm sounds to selected marker positions
				_snd = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1", _markerName]), [], 0];
				_snd1 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_1", _markerName]), [], 0];
				_snd2 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_2", _markerName]), [], 0];
				_snd3 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_3", _markerName]), [], 0];
				_snd4 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_4", _markerName]), [], 0];
			// End of alarm sound creating

			_x reveal player;
			_x setBehaviour "COMBAT";
			_x setCombatMode "YELLOW";
			_x setSpeedMode "NORMAL";

			while {(_x knowsAbout player) > 0} do {sleep 30};

			if (_debug == 1) then {
				hint "alarm off"
			} else {
			};

			// Starts alarm sound deletion
				deleteVehicle _snd;
				deleteVehicle _snd1;
				deleteVehicle _snd2;
				deleteVehicle _snd3;
				deleteVehicle _snd4;
			// End of alarm sound deletion

			alarm1 = 0;
		};

		case 6: {
			if (_debug == 1) then {
				hint "creating 6 sound sources"
			} else {
			};
			// Starts creating alarm sounds to selected marker positions
				_snd = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1", _markerName]), [], 0];
				_snd1 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_1", _markerName]), [], 0];
				_snd2 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_2", _markerName]), [], 0];
				_snd3 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_3", _markerName]), [], 0];
				_snd4 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_4", _markerName]), [], 0];
				_snd5 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_5", _markerName]), [], 0];
			// End of alarm sound creating

			_x reveal player;
			_x setBehaviour "COMBAT";
			_x setCombatMode "YELLOW";
			_x setSpeedMode "NORMAL";

			while {(_x knowsAbout player) > 0} do {sleep 30};

			if (_debug == 1) then {
				hint "alarm off"
			} else {
			};

			// Starts alarm sound deletion
				deleteVehicle _snd;
				deleteVehicle _snd1;
				deleteVehicle _snd2;
				deleteVehicle _snd3;
				deleteVehicle _snd4;
				deleteVehicle _snd5;
			// End of alarm sound deletion

			alarm1 = 0;
		};

		case 7: {
			if (_debug == 1) then {
				hint "creating 7 sound sources"
			} else {
			};
			// Starts creating alarm sounds to selected marker positions
				_snd = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1", _markerName]), [], 0];
				_snd1 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_1", _markerName]), [], 0];
				_snd2 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_2", _markerName]), [], 0];
				_snd3 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_3", _markerName]), [], 0];
				_snd4 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_4", _markerName]), [], 0];
				_snd5 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_5", _markerName]), [], 0];
				_snd6 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_6", _markerName]), [], 0];
			// End of alarm sound creating

			_x reveal player;
			_x setBehaviour "COMBAT";
			_x setCombatMode "YELLOW";
			_x setSpeedMode "NORMAL";

			while {(_x knowsAbout player) > 0} do {sleep 30};

			if (_debug == 1) then {
				hint "alarm off"
			} else {
			};

			// Starts alarm sound deletion
				deleteVehicle _snd;
				deleteVehicle _snd1;
				deleteVehicle _snd2;
				deleteVehicle _snd3;
				deleteVehicle _snd4;
				deleteVehicle _snd5;
				deleteVehicle _snd6;
			// End of alarm sound deletion

			alarm1 = 0;
		};

		case 8: {
			if (_debug == 1) then {
				hint "creating 8 sound sources"
			} else {
			};
			// Starts creating alarm sounds to selected marker positions
				_snd = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1", _markerName]), [], 0];
				_snd1 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_1", _markerName]), [], 0];
				_snd2 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_2", _markerName]), [], 0];
				_snd3 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_3", _markerName]), [], 0];
				_snd4 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_4", _markerName]), [], 0];
				_snd5 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_5", _markerName]), [], 0];
				_snd6 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_6", _markerName]), [], 0];
				_snd7 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_7", _markerName]), [], 0];
			// End of alarm sound creating

			_x reveal player;
			_x setBehaviour "COMBAT";
			_x setCombatMode "YELLOW";
			_x setSpeedMode "NORMAL";

			while {(_x knowsAbout player) > 0} do {sleep 30};

			if (_debug == 1) then {
				hint "alarm off"
			} else {
			};

			// Starts alarm sound deletion
				deleteVehicle _snd;
				deleteVehicle _snd1;
				deleteVehicle _snd2;
				deleteVehicle _snd3;
				deleteVehicle _snd4;
				deleteVehicle _snd5;
				deleteVehicle _snd6;
				deleteVehicle _snd7;
			// End of alarm sound deletion

			alarm1 = 0;
		};

		case 9: {
			if (_debug == 1) then {
				hint "creating 9 sound sources"
			} else {
			};
			// Starts creating alarm sounds to selected marker positions
				_snd = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1", _markerName]), [], 0];
				_snd1 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_1", _markerName]), [], 0];
				_snd2 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_2", _markerName]), [], 0];
				_snd3 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_3", _markerName]), [], 0];
				_snd4 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_4", _markerName]), [], 0];
				_snd5 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_5", _markerName]), [], 0];
				_snd6 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_6", _markerName]), [], 0];
				_snd7 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_7", _markerName]), [], 0];
				_snd8 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_8", _markerName]), [], 0];
			// End of alarm sound creating

			_x reveal player;
			_x setBehaviour "COMBAT";
			_x setCombatMode "YELLOW";
			_x setSpeedMode "NORMAL";

			while {(_x knowsAbout player) > 0} do {sleep 30};

			if (_debug == 1) then {
				hint "alarm off"
			} else {
			};

			// Starts alarm sound deletion
				deleteVehicle _snd;
				deleteVehicle _snd1;
				deleteVehicle _snd2;
				deleteVehicle _snd3;
				deleteVehicle _snd4;
				deleteVehicle _snd5;
				deleteVehicle _snd6;
				deleteVehicle _snd7;
				deleteVehicle _snd8;
			// End of alarm sound deletion

			alarm1 = 0;
		};

		case 10: {

			if (_debug == 1) then {
				hint "creating 10 sound sources"
			} else {
			};

			// Starts creating alarm sounds to selected marker positions
				_snd = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1", _markerName]), [], 0];
				_snd1 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_1", _markerName]), [], 0];
				_snd2 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_2", _markerName]), [], 0];
				_snd3 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_3", _markerName]), [], 0];
				_snd4 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_4", _markerName]), [], 0];
				_snd5 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_5", _markerName]), [], 0];
				_snd6 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_6", _markerName]), [], 0];
				_snd7 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_7", _markerName]), [], 0];
				_snd8 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_8", _markerName]), [], 0];
				_snd9 = createSoundSource ["Sound_Alarm2", (getMarkerPos format["%1_9", _markerName]), [], 0];
			// End of alarm sound creating

			_x reveal player;
			_x setBehaviour "COMBAT";
			_x setCombatMode "YELLOW";
			_x setSpeedMode "NORMAL";

			while {(_x knowsAbout player) > 0} do {sleep 30};

			if (_debug == 1) then {
				hint "alarm off"
			} else {
			};

			// Starts alarm sound deletion
				deleteVehicle _snd;
				deleteVehicle _snd1;
				deleteVehicle _snd2;
				deleteVehicle _snd3;
				deleteVehicle _snd4;
				deleteVehicle _snd5;
				deleteVehicle _snd6;
				deleteVehicle _snd7;
				deleteVehicle _snd8;
				deleteVehicle _snd9;
			// End of alarm sound deletion

			alarm1 = 0;
		};

	};

	_x reveal player;
	_x setBehaviour "COMBAT";
	_x setCombatMode "YELLOW";
	_x setSpeedMode "NORMAL";

	while {(_x knowsAbout player) > 0} do {sleep 30};

	if (_debug == 1) then {
		hint "alarm off"
	} else {
	};

	// Starts alarm sound deletion
		deleteVehicle _snd;
		deleteVehicle _snd1;
		deleteVehicle _snd2;
		deleteVehicle _snd3;
		deleteVehicle _snd4;
		deleteVehicle _snd5;
		deleteVehicle _snd6;
		deleteVehicle _snd7;
		deleteVehicle _snd8;
		deleteVehicle _snd9;
	// End of alarm sound deletion

} else {
	if (_debug == 1) then {
		hint "enemy dead within set time"
	} else {
	};
};
} else {
};} forEach _aiList;

} else {

if (_debug == 1) then {
	hint "alarm already active"
} else {
};
};

And here's a sample mission on Desert with outdated version of the script: http://www.mediafire.com/?m68623olvsj3r98

Edited by Janat
Script updated

Share this post


Link to post
Share on other sites

So, does anyone know how to make my script MP compatible?

Share this post


Link to post
Share on other sites

I've updated the script to be more versatile. There's been one problem with all versions of the script though. The script doesn't work perfectly if an enemy group with more than one unit sees you. If a group that consists of more than one enemy unit spots you, no matter what the alarm will be set off. The alarm will be deactivated soon after that (if no other group has spotted you). How can I get the alarm not get activated in this scenario?

Share this post


Link to post
Share on other sites

Are you using CBA you can use event handler or global execute. If not you can always make it MP proof with a tirgger because that runs on all computer when fired from mission sqm.

or use golbal variable. CBA is the best way for MP.

Share this post


Link to post
Share on other sites

No I don't use CBA. But as it'll be executed via a trigger, it should work in MP?

Script updated with more parameter checks and a new parameter which is used to set the amount of sound sources. Possible values are from 0 to 10.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×