Jump to content

Recommended Posts

Very new to scripting and I'm figuring out how to count the amount of AI that has died at the end of a mission. If you have any answers or help it would be appreciated. 

Share this post


Link to post
Share on other sites

initServer.sqf

TAG_aiKilled = 0;
addMissionEventHandler ["EntityKilled", {
	params ["_unit"];
	if !(isPlayer _unit) then {
		TAG_aiKilled = TAG_aiKilled + 1;
	};
}];

all the commands are explained on the BIKI: https://community.bistudio.com/wiki/Main_Page

The idea is to create a global counter TAG_aiKilled (use a unique TAG, mine is e.g. TER) which should be increased when an AI is killed. How do we know that an AI is killed? We use an Eventhandler, in this case a mission wide eventhandler. In this EH we check if the unit that was killed (_unit) is not a player (!(isPlayer _unit)). In this case we increase the counter by one. If you are doing a multiplayer mission it will get a bit more complicated.

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

I've looked for a bit but I'm still unsure what you mean by TAG, is it the unit name or something else? Sorry if this is something a lot of people know I'm just getting into the editor.

Share this post


Link to post
Share on other sites

The TAG is just to make sure that your global variable is unique and will not be overwritten by another script/mod. It can literally be any combination of letters, you just have to be consistent and remember it. For example, instead of writing this:

globalVariable = "Any value";

You would do this:

TAG_globalVariable = "Any value";

This is just good practice, both codes work. Here is a list of tags already used (though I have to admit, mine was already taken before I even knew this site was a thing 😅): https://www.ofpec.com/tags/index.php?action=list

  • Like 1
  • Thanks 1
  • Haha 1

Share this post


Link to post
Share on other sites

Just in case it isn't perfectly clear, "TAG" is a stand-in for your personal tag, which is usually a 3-4 letter abbreviation/contraction of your username/handle - whatever you feel represents you best. For example, Mine is "HARZ" and I might use it as such: HARZ_myVariable.

A lot of folks seem to misunderstand this and end up using "TAG" as their tag, which is probably fine functionally, but can be confusing.

  • Like 1

Share this post


Link to post
Share on other sites

If by statistics you mean how many AI killed in a mission, TAG_aiKilled is a variable, in this case will have a value of a number, 0 at the start of the mission and 10 after killing 10 AIs. There are plenty of ways to show the value of TAG_aiKilled, easiest way but not subtle at all would be to hint it with each kill:

TAG_aiKilled = 0;
addMissionEventHandler ["EntityKilled", {
	params ["_unit"];
	if !(isPlayer _unit) then {
		TAG_aiKilled = TAG_aiKilled + 1;
      		hint format ["Number of AI killed: %1",TAG_aiKilled];
	};
}];

With this line added, at each AI death a hint will appear with how many AI killed so far, as I say this would work well for debugging but not for a mission.

Now it's down to you on how you want to display this.

  • Like 1

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

×