ArmA 3 Alpha: TL_killCounter, a kill counter that tracks the total number of AI kills a player has

Overview

TL_killCounter is a script that you can include in any mission to have a simple kill counter. The kill counter increments with each OPFOR kill. This script is currently only for single player missions.

This script is primarily an example of how a kill counter can be implemented. It is very basic, but feel free to expand on the code. You can leave any feature requests you’d like to see implemented, in the comments.

Update April 3, 2013: I combined the previous code into a single file so it can be included in any mission. All variables are prefixed with TL_ to avoid naming conflicts.

Player has zero kills.
Player has 1 kill.
Kill counter updates to 2.

Usage

Use the following code to setup the kill counter.

// Setup kill counter
execVM "TL_killCounter.sqf";

TL_killCounter.sqf

Download TL_killCounter.sqf to your mission folder.

/*********************************************************************
 *
 * FUNCTION: TL_killCounter
 *
 * @description		A simple kill counter
 * @author 		TechLethal
 * @website 		http://www.techlethal.com
 * @version 		1.0
 *
 *********************************************************************
 *
 * USAGE:
 * execVM "TL_killCounter.sqf";
 *
 * Note: Currently only works with single player missions
 *
 ********************************************************************/

// Set kill count to zero
TL_killCount = 0;	

/**
 * FUNCTION
 * Increment kill count and display kill count to player
 */
TL_fnc_updateKillCount = {

	// Increment the kill count
	TL_killCount = TL_killCount + 1;

	// Display the player's new kill count
	if(TL_killCount == 1) then {
		hint format["You have %1 kill", TL_killCount];	// Singular message
	}
	else {
		hint format["You have %1 kills", TL_killCount]; // Plural message
	};

};	

/**
 * FUNCTION
 * Called when enemy unit dies
 */
TL_fnc_enemyKilled = {

	_victim = _this select 0;
	_attacker = _this select 1;

	// Only increase the kill count if the kill was made by the player
	if(_attacker == player) then {
		call TL_fnc_updateKillCount;
	};

};

/*
 * Add an event to all OPFOR enemy units that calls our
 * enemyKilled function when the unit is killed.
 */
{
	if(side _x == EAST && _x isKindOf "Man") then {
		_x addEventHandler ["killed", { _this call TL_fnc_enemyKilled } ];
	};
} foreach allUnits;

// Add event handler to reset the player's kill count when they die
player addEventHandler ["killed", { TL_killCount = 0 }];