Jump to content
GingerAsianBond

Global Message Displayed When Civillian Is Killed

Recommended Posts

Hi there,

 

I am making a TvT mission that involves civilians in the AO. I am trying to get a global message displayed whenever a civilian is killed. It should look something like this - "Player X12 killed a civilian." 


Looking forward to hearing from you guys.

 

Thank you.

Share this post


Link to post
Share on other sites

Should be doable with an Eventhandler: https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#Killed

Depends on how the Civilians are spawned. If its through scripts or the editor that should be easy. If its through Zeus you might need a Loop in the background that checks for dead civilians. But I might be wrong with the latter.

Share this post


Link to post
Share on other sites

about the cleanest way i could think of that is also universal. if you have more civilian AI spawning later in the mission that you want the message to be displayed when they are killed, you can simply run this script again and it will add it to the new civilian units without adding a second killed event handler to the civilian AI that already have one. ONLY run this on the server, there is no point in this running on the client so put it in initServer.sqf or call it from the server only

{
	_Unit = _x;
	//if the unit has an event handler ID already assigned to them then _EHID will NOT be -1.
	_EHID = _Unit GetVariable ["KilledEHID", -1];//-1 is the default value if the variable KilledEHID is not found

	if (_EHID == -1	) then
    {//if the unit does not have the event handler
    	_EHID = _Unit AddEventHandler ["Killed",//add a killed event handler to the unit
		{
			params ["_Unit", "_Killer", "_Instigator", "_UseEffects"];
			//when the unit is killed, RemoteExec(execute a hint on all players including the server)
			[Format["Player %1 killed a civilian", Name _Killer]] RemoteExec ["Hint", 0, true];
			//output would be(with your name) Player GingerAsianBond killed a civilian
		}];
		//since the unit now has an event handler, lets set KilledEHID to equal the ID of the event handler -
		//so it does not get added twice to the same unit incase you need to run this command again in a loop -
		//or for newly spawned civilians.
		_Unit SetVariable ["KilledEHID", _EHID, false];
    };
// only loop through the units who are civilian and not players
} ForEach (AllUnits Select {Side _x == Civilian && !(IsPlayer _x)});

 

  • Like 1

Share this post


Link to post
Share on other sites

Could also add an MP eventHandler to the civilians:
 

_civ addMPEventHandler ["MPKilled",{if(side _this#1==WEST)then{systemChat format["%1 has inflicted a civilian casualty!",_this#1]};}];

 

  • Like 1

Share this post


Link to post
Share on other sites

Hi guys, thanks for the prompt reply. Appreciate the feedback. @Moon_chilD

 

@phronk I am using the Dynamic Civilian spawner from Bohemia, would there be a workaround for this that would affect all spawned units? Perhaps a trigger?

 

@gokitty1199 You're a legend, mate. Would this be placed in my init.sqf?

 

 

Share this post


Link to post
Share on other sites

I'd just put the code right after you find the command in the script using createUnit, which spawns the civilian, that way it adds the eventHandler immediately after they spawn.

Share this post


Link to post
Share on other sites
16 hours ago, GingerAsianBond said:

Hi guys, thanks for the prompt reply. Appreciate the feedback. @Moon_chilD

 

@phronk I am using the Dynamic Civilian spawner from Bohemia, would there be a workaround for this that would affect all spawned units? Perhaps a trigger?

 

@gokitty1199 You're a legend, mate. Would this be placed in my init.sqf?

 

 

it would go in your initserver so that way the script never has to touch the client so the server is doing all the work and simply telling the clients with a message when a civilian is killed (i try to keep everything off of the client unless its necessary or crucial to performance)

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

×