Jump to content
Sign in to follow this  
bismember

Activate a trigger each time when any AI unit on the map is killed

Recommended Posts

Hi, guys.

THE TASK.

I'm trying to activate a trigger when an AI is killed. Trigger should show radio message about killed unit when an AI unit is killed.

MY SEARCH.

I've read many forums, but the only suggestion I found everywhere was: "give names to all your units on the map and then check them in a trigger by name". This is absurd if you have hundreds of units. I've no idea why people were satisfied with this suggestion. I'm really surprised that no one in the world asked this question.. It's really crazy to follow the suggestion people gave.

THE QUESTION.

Trigger Condition field is empty and I have no idea how to sript it to react when I kill an AI. What should I type in Condition field to make this trigger activate when any unknown nameless AI gets killed?

Thanks.

SOLUTION 1 (By Schatten)

Add event handler into the Initialization field of each unit. It should look like this: this addeventhandler ["killed", {here you type what you want this event to do}]

SOLUTION 2 (By Schatten)

Scripting + Functions module. The solution that was needed.

Edited by bismember

Share this post


Link to post
Share on other sites
How you create units? Using script or editor?

Maybe you need to use event handler?

I add units in the editor using Units menu.

Oh, looks like I can use individual event handlers. So just add it to all AIs I spawn on the map and these events will show the message... And even if I create AIs automatically with script, I can add this event handler, which is even better. ... Man, thank you.

But I have another question about it. How do I check if the killer is the player? I mean, I need to show kill confirmation only when player kills AI, not when AI kills AI. I need to check if the killer is player. Can you suggest anything?

Edited by bismember

Share this post


Link to post
Share on other sites

Add into init.sqf (or create it if it's don't exist) in your mission folder this code:

if (isServer) then {
waitUntil {
	sleep 0.1;

	!(isNil "BIS_MPF_InitDone") and {!(isNil "BIS_fnc_init")}
};

onNpcKill = compile (preprocessFileLineNumbers "onNpcKill.sqf");
};

Create in your mission folder file onNpcKill.sqf with this code:

_npc = _this select 0;
_killer = _this select 1;

if (isPlayer _killer) then {
[
	_npc,
	nil,
	"globalChat",
	"NPC was killed by " + (name _killer)
] call RE;
};

true

How to use RE function.

Place on map Functions module.

Add into Init field of NPC this code:

if (isServer) then {this addEventHandler ["Killed", {_this call onNpcKill}]};

Edited by Schatten

Share this post


Link to post
Share on other sites
Add into init.sqf (or create it if it's don't exist) in your mission folder this code...

This is amazing. Clear and useful answer. I'll try.

...

Ok, tried. Works fine. Added a few modifications to it and it now completely satisfies me. Perfect solution.

Edited by bismember

Share this post


Link to post
Share on other sites
Add into init.sqf (or create it if it's don't exist) in your mission folder this code:

I have a question. In short, how can I check if _npc is a vehicle, armor or man? Unit type or something like that. And if it is possible, to get name of a destroyed vehicle. Because (name _npc) doesn't work for vehicles. And it works funny for AI enemies, it shows real human names like Novak Kozlovsky etc, lol.

I want my final radio message to look like: "Target (VEHICLE) eliminated by ...";

...

I've just found I can use typeof instead of name. Make a message a bit more technical yet informative.

Edited by bismember

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  

×