Jump to content

Recommended Posts

Hey guys.

I am pretty new to mission editing in Arma, and i was wondering how you can make a "enemy counter", so you know how enemies there are left.

Really hope someone can help me?

Share this post


Link to post
Share on other sites

I'm not sure if this works in A3, but it did in A2. EDIT: I put the unnecessary stuff inside the spoiler

Put this code somewhere during mission init:

enemyCount = 0;

Then

create a script with a code like this:

enemyCount = 0; forEachUnit side "OPFOR" {enemyCount=enemyCount+1}; hint format["Enemy count: %1", enemyCount];

To make the script repeat, you can use something like this:

while true do {[i]the script you want to repeat[/i]};

Now I'm not completely sure whether the syntax is correct since I've had quite a long break from scripting, but I'm sure you can pick up the general idea and if this code doesn't work, find out the correct syntax and commands. :)

Edited by Janat

Share this post


Link to post
Share on other sites

Just a hint. If you use the while loop, consider using a sleep during the loop. Otherwise it will run on every frame. Which is baaaaad ;)

  • Like 1

Share this post


Link to post
Share on other sites

I would do:

create a trigger covering all the map, activation OPFOR (or what side your enemy is), make it repeating, in the condition field write counter.

on activation: hint format ["Enemies left: %1",count thislist]; counter=false;

on deactivation: counter=true;

then make another trigger, set the condition field to true, and in on activation write counter=true;

should do the trick!

Edited by Tuliq
  • Like 1

Share this post


Link to post
Share on other sites

Yeah, sleep 1 inside the while loop would repeat the script fast enough while being quite easy on the cpu. That trigger would work, too, but it's not as pretty (and somehow I have a feeling it would take a bit more processing power, which is hardly a problem if you're not running loads of scripts). Edited the counting script to actually do what the OP asked it to do.

Edited by Janat

Share this post


Link to post
Share on other sites

A simple way is just use a radio trigger.

place a trigger down anywhere.

Size of the trigger 0

Type none

Activation radio alpha ect

Activation present

Repeatable

Trigger exp

Condition player ==P1 (P1 is your player's name) if you want more then one guy to check how many enemies are left then player ==P1 || Player ==P2

On activation hint str ({side _x == east && {player distance _x < 6000} count allunits}; if your AO is bigger then make it 10000 

Share this post


Link to post
Share on other sites

The rest of the people here have provided some simple solutions that (must) work quite well. Personally I would prefer something like

// Assume that the opposing side is East/OPFOR
private _numOfEnemies = east countSide allUnits;

This of course would require some kind of timer to check in some kind of interval. Solutions like

// 1st alternative
// Run "forever"
while {true} do {
	// Get the number of OPFOR units
	private _numOfEnemies = east countSide allUnits;

	// "Sleep" for 5 seconds
	uiSleep 5;
}

// 2nd alternative
// Get the number of OPFOR units
private _numOfEnemies = east countSide allUnits;

// Run until all enemies are dead
while {_numOfEnemies == 0} do {
	// Get the number of OPFOR units
	_numOfEnemies = east countSide allUnits;

	// "Sleep" for a while
	uiSleep 5;
}

Now, you may want the variable to be global, or public or something like that depending on when and where you intend to use it. Additionally, you may wish to make a function out of it if you intend to use it quite often (although this is just one line of code and I am not sure how much you would save by making a function out of it... If you intend to use it quite often in various places it may be worth it).

 

One more tweak could be to get your player's faction/side and count all units that do not belong to the same faction as enemies. One approach to that (most probably there are more) could be

// Use a single variable to save some memory (although it may be not worth it, feel free to follow your style)
private _numOfEnemies = (side player) countSide allUnits; // Get all the units on the same side with the player
_numOfEnemies = allUnits - _numOfEnemies; // Exclude the units on the same side with the player from "all the units"

Finally, you could count the enemies (based on your player's faction and game's setup, the opposing factions may vary). This could possibly be done like

// Count the units that are considered enemies for the player
private _numOfEnemies = player countEnemy allUnits;

Please keep in mind that countEnemy counts also the "renegades" (friendly units that have done some friendly kills, etc.) and all units that are considered enemies. For the sides' relationships please refer to this page. You can also check the same page for ways to change hostility between sides (one- or two-way hostilities included). You can get information about side hostilities in the scripts with the helper functions: BIS_fnc_sideIsFriendly and BIS_fnc_sideIsEnemy.

  • Like 1

Share this post


Link to post
Share on other sites
On 3/6/2013 at 6:50 PM, Tuliq said:

I would do:

create a trigger covering all the map, activation OPFOR (or what side your enemy is), make it repeating, in the condition field write counter.

on activation: hint format ["Enemies left: %1",count thislist]; counter=false;

on deactivation: counter=true;

then make another trigger, set the condition field to true, and in on activation write counter=true;

should do the trick!

 

is there any way to do this without sounding the message? with hintsilent for example?

  • 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

×