Jump to content
zzguy

Event handlers for certain unit classes?

Recommended Posts

Hello, I think of myself as decent when it comes to Arma scripting, but I can't seem to figure out event handlers for this case. I'm basically trying to create two event handlers that will play sounds when a unit dies or is damaged.

 

One event handler will play a randomized death sound

The other will play a randomized on hit sound effect

I have already defined sounds in my mission description file. However, how would I apply these event handlers too all units in the mission that match certain unit classes (i don't want to have to place something in every unit's init).

 

Is this possible? It's worth noting that this is for a MP environment (not dedicated) and I plan to use say3d on a dummy object for the death sounds.

Share this post


Link to post
Share on other sites

Easiest way would be to use CBA since it supports class eventhandlers: https://github.com/CBATeam/CBA_A3/wiki/Extended-Event-Handlers-(new). This way it will also include newly spawned units.

 

Other option without mods woul be to run a loop like this:

allUnits apply {
	if (_x is kindOf "Class") then {
		// code
	};
};

Depending on your mission you'd have to run this resource intensive code in a loop to make sure that every unit has the EH.

Share this post


Link to post
Share on other sites
On 2/26/2020 at 8:19 AM, 7erra said:

Easiest way would be to use CBA since it supports class eventhandlers: https://github.com/CBATeam/CBA_A3/wiki/Extended-Event-Handlers-(new). This way it will also include newly spawned units.

 

Other option without mods woul be to run a loop like this:


allUnits apply {
	if (_x is kindOf "Class") then {
		// code
	};
};

Depending on your mission you'd have to run this resource intensive code in a loop to make sure that every unit has the EH.

 

I managed to achieve my goal without CBA requirements, for future reference this is the code I used

I only needed to run it on units spawned at mission start though. It could easily be turned into a loop as you said, with a delay at the end to lower resource usage.

 

 

{if (typeOf(_x) == "classname_1" OR typeOf(_x) == "classname_2") then 
	
	{
		_x addEventHandler ["Killed", 
		{
			
				params ["_corpse"];
		
				private _dummy = "#particlesource" createVehicleLocal [0,0,0];
				_dummy setPosWorld getPosWorld _corpse;
				_dummy say3D (selectRandom ["deathsound_1","deathsound_2"]);
		}];
	}
} forEach allUnits;

 

 

 

 

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

×