Skip to content

hitSound

Back To Armed Assault Scripts

Play selected random sound when the player is hit.

You need to have your sounds defined in Description.ext under CfgSounds.

For the Armed Assault 3 solution, you don’t need any triggers. If you have init.sqf in the root folder of your mission/scenario, it adds the MPHit event handler to the player.


Armed Assault

Trigger Axis A & B: 99999

Activation: Player side / Once / Present

On Activation:

{_x addEventHandler ["HIT", "(_this select 1) exec ""hitSound.sqs"""]} forEach thisList

hitSound.sqs

; ***************************
; Random Hit Sound Script
; Created by Semedar (Villa, Victor D.)
; ***************************

?!local _this: exit

_random = random 5
_a = _random - (_random mod 1) 

~(random 3)

?(_a == 1) : goto "1"
?(_a == 2) : goto "2"
?(_a == 3) : goto "3"
?(_a == 4) : goto "4"
?(_a == 5) : goto "5"

#1
playSound "Sound1"
exit

#2
playSound "Sound2"
exit 

#3
playSound "Sound3"
exit

#4
playSound "Sound4"
exit

#5
playSound "Sound5"
exit

Armed Assault 2

Trigger Axis A & B: 99999

Activation: Player side / Once / Present

On Activation:

{_x addEventHandler ["HIT", "(_this) execVM ""hitSound.sqf"""]} forEach thisList;

hitSound.sqf

/*
Hit Sound Script
Semedar (Villa, Victor D.)
*/

waitUntil {!(isNil "bis_fnc_init")};
_sound = ["Sound1","Sound2","Sound3","Sound4","Sound5","Sound6"] call bis_fnc_selectRandom;
playSound _sound;

Armed Assault 3

init.sqf

player addMPEventHandler ["MPHit", {
	params ["_unit","_causedBy","_damage","_instigator"];
	_hitSoundArray = [
		"Sound1",
		"Sound2",
		"Sound3",
		"Sound4",
		"Sound5"
	];
	_hitSoundVar = selectRandom _hitSoundArray;
	playSound _hitSoundVar;
}];

Opus@Monotonía | © Victor D. Villa, All rights reserved.