Jump to content
Sign in to follow this  
DeadCommunist

Counting kills, remaining enemies

Recommended Posts

I have recently made some simple scenarios using the editor of Arma2:OA, and want to get these things to work:

  • counting the kills of the player character (and using the number, stored to a variable, in scripting)
  • counting the remaining living soldiers in a given array (also would like to know how to count all alive of a side) periodically, emitting a "hint" at each full 10 ("50 remaining", "40 remaining", etc.)

As far as the first point is concerned: I don't know the command to use for counting/getting the kills of any character/unit (is their number automatically stored somewhere as of the usual setup, or do they have to be counted "manually" by an own command as things happen?); as for the latter point, in the given situation I have attempted using

{alive _x} count (enemygroup1 + enemygroup2 + enemygroup3 + [...]) < [number]

as the condition for a trigger which would trigger the "hint" (or "hintSilent"), which somehow didn't work (the group definitions of the enemy groups I put in the init lines of the group leaders, as e.g. "enemygroup2 = group this;"). Am about to attempt the use of a periodically running script like

while {true} do {[...]; sleep [10];};

triggered in mission init now, would appreciate attempts on useful hints and pre-made solutions, thanks in advance.

Also, about init: when "finishMissionInit" is contained, must it be the last command in init, or can commands after it be processed?

Edited by DeadCommunist

Share this post


Link to post
Share on other sites

Here is the prototype for the counting and display script so far. It is triggered from a switch which is activate just after the game is started (it didn't work from init, in the ways I tried). The relevant enemies are the members of the groups agrp1 through agrp10 (which are defined in the init lines of the groups' leaders (as there is "sleep 10" before the check, these variables certainly are available already at the first time the references to them in the script are activated)) - if 10 or less of them remain, the mission shall be considered having been successful (I'll bother with game-end scripting/editing later, for now there's just a Hint).

The application of this prototype did so far not result in anything visible at runtime except the display of the initial hint. The initial number of units in the agrp-groups is below 70, so there should be another hint displayed about 10 seconds after that, but it's not working.

EDIT: Initialization of variable "below71f" was missing - corrected, run attempt.

EDIT2: No visible improvements. Progress messages still not appearing. Initial count of units in agrp-groups certainly is below 70 (even if the numbers of soldiers and vehicles are added to one another), and if the agrp-arrays would be somehow not available to the script logic, acount would be 0 on the first time and all progress messages would display at once, wouldn't it, so it's most probably something else.

hint "MISSION IS WON IF ALL BUT 10 OR LESS OF THE ENEMY OCCUPATION UNITS ARE ELIMINATED.";

below71 = false;
below61 = false;
below51 = false;
below41 = false;
below31 = false;
below21 = false;
below11 = false;

below71f = false;
below61f = false;
below51f = false;
below41f = false;
below31f = false;
below21f = false;
below11f = false;

while {true} do {

sleep 10;
acount = (({alive _x} count agrp1) 
  +({alive _x} count agrp2)
  +({alive _x} count agrp3)
  +({alive _x} count agrp4)
  +({alive _x} count agrp5)
  +({alive _x} count agrp6)
  +({alive _x} count agrp7)
  +({alive _x} count agrp8)
  +({alive _x} count agrp9)
         +({alive _x} count agrp10));

if ((acount < 71) and (below71 == false)) then {below71 = true;};
if ((acount < 61) and (below61 == false)) then {below61 = true;};
if ((acount < 51) and (below51 == false)) then {below51 = true;};
if ((acount < 41) and (below41 == false)) then {below41 = true;};
if ((acount < 31) and (below31 == false)) then {below31 = true;};
if ((acount < 21) and (below61 == false)) then {below21 = true;};
if ((acount < 11) and (below11 == false)) then {below11 = true;}; 

if ((below71 == true) and (below71f == false)) then {
 hint "60 OR LESS ENEMY UNITS LEFT TO ELIMINATE.";
 below71f = true;
 };

if ((below61 == true) and (below61f == false)) then {
 hint "50 OR LESS ENEMY UNITS LEFT TO ELIMINATE.";
 below61f = true;
 };

if ((below51 == true) and (below51f == false)) then {
 hint "40 OR LESS ENEMY UNITS LEFT TO ELIMINATE.";
 below51f = true;
 };

if ((below41 == true) and (below41f == false)) then {
 hint "30 OR LESS ENEMY UNITS LEFT TO ELIMINATE.";
 below41f = true;
 };

if ((below31 == true) and (below31f == false)) then {
 hint "20 OR LESS ENEMY UNITS LEFT TO ELIMINATE.";
 below31f = true;
 };

if ((below21 == true) and (below21f == false)) then {
 hint "10 OR LESS ENEMY UNITS LEFT TO ELIMINATE.";
 below21f = true;
 };

if ((below11 == true) and (below11f == false)) then {
 hint "MISSION ACCOMPLISHED.";
 below11f = true;
 };  

};

Edited by DeadCommunist

Share this post


Link to post
Share on other sites

you can shorten all that massive nest of if statement for enemy count with hint by using this


_totalEnemy = {alive _x && side _x == EAST} count allUnits;

    if (_totalEnemy > 11) then
   {

     player sidechat format["THERE ARE %1  ENEMY UNITS LEFT TO KILL", _totalEnemy ];

   } Else { 

		    If (_totalEnemy < 11) then
               {

                     player sidechat format["THERE ARE %1  Mission is compleate", _totalEnemy ];

                     //call end mission code now

                };
           };



as far counting kills for each player arma give me 10

Share this post


Link to post
Share on other sites

hogmason: Thanks for the script. Adapted to the circumstances it would be, I guess:

hint "MISSION IS WON IF ALL BUT 10 OR LESS OF THE ENEMY OCCUPATION UNITS ARE ELIMINATED.";

while {true} do {
sleep 10;
_agrps  = (agrp1 + agrp2 + agrp3 + agrp4 + agrp5 + agrp6 + agrp7 + agrp8 + agrp9 + agrp10);
_acount = {alive _x} count units _agrps;
if (_acount > 11) then {hint format ["THERE ARE %1 ENEMY UNITS LEFT TO KILL", _totalEnemy];} 
 Else { 
  If (_totalEnemy < 11) then {hint "MISSION ACCOMPLISHED";};
 };
};

The enemies of which is count are specifically the members of these groups, not all on the map of the enemy side (which is, in this case, west).

These things are easily adapted to (but don't know if the respective code is written correctly/in a way in which it could work), but with your

script there is a continuous repetitive output, not only if margins of full 10 (60,50,40 etc.) are reached. That I do not want.

(Also: In my code there are no nested (i.e. contained-in-another) if-statements - I get what you mean, though).

Edited by DeadCommunist

Share this post


Link to post
Share on other sites

No Use this


hint "MISSION IS WON IF ALL BUT 10 OR LESS OF THE ENEMY OCCUPATION UNITS ARE ELIMINATED.";

while {true} do 
{

sleep 10;

 _agrps  = (agrp1 + agrp2 + agrp3 + agrp4 + agrp5 + agrp6 + agrp7 + agrp8 + agrp9 + agrp10);
    _acount = {alive _x} count units _agrps;

       if (_acount > 11) then 
	{
	    hint format ["THERE ARE %1 ENEMY UNITS LEFT TO KILL", _acount];
	} 
       Else 
	{ 

           If (_acount < 11) then 
		{

		hint "MISSION ACCOMPLISHED";

		};

       };

};



now im a bit skeptical about


 _agrps  = (agrp1 + agrp2 + agrp3 + agrp4 + agrp5 + agrp6 + agrp7 + agrp8 + agrp9 + agrp10);
    [color="#FF0000"]_acount = {alive _x} count units _agrps;[/color]

Just let me know

---------- Post added at 23:58 ---------- Previous post was at 23:56 ----------

(Also: In my code there are no nested (i.e. contained-in-another) if-statements - I get what you mean, though).

Yeah you gotta excuse me ive been codeing for 16 hrs straight on my latest pc program so my brain is a bit fried ATM lol

Share this post


Link to post
Share on other sites

Thanks for the help.

However, all of the versions are fail at producing visible runtime output after the initial line, except for your first suggestion, when put into repetition sequence (but as stated, it counts all units of the side, not just the units of these groups, also always outputs (not only at certain numbers)).

EDIT: Made changes to prototype, made group names global variables (with _) in editor (group leader init lines) and script - script still works as little as before. Exact current state see below.

hint "MISSION IS WON IF ALL BUT 10 OR LESS OF THE ENEMY OCCUPATION UNITS ARE ELIMINATED.";

_below71 = false;
_below61 = false;
_below51 = false;
_below41 = false;
_below31 = false;
_below21 = false;
_below11 = false;

_below71f = false;
_below61f = false;
_below51f = false;
_below41f = false;
_below31f = false;
_below21f = false;
_below11f = false;

while {true} do {

sleep 10;

_aunits = ((units _agrp1) 
          +(units _agrp2)
          +(units _agrp3)
          +(units _agrp4)
          +(units _agrp5)
   +(units _agrp6)
   +(units _agrp7)
   +(units _agrp8)
          +(units _agrp9)
   +(units _agrp10));

_acount = {alive _x} count _aunits;

if ((_acount < 71) and (_below71 == false)) then {_below71 = true;};
if ((_acount < 61) and (_below61 == false)) then {_below61 = true;};
if ((_acount < 51) and (_below51 == false)) then {_below51 = true;};
if ((_acount < 41) and (_below41 == false)) then {_below41 = true;};
if ((_acount < 31) and (_below31 == false)) then {_below31 = true;};
if ((_acount < 21) and (_below61 == false)) then {_below21 = true;};
if ((_acount < 11) and (_below11 == false)) then {_below11 = true;}; 

if ((_below71 == true) and (_below71f == false)) then {
 hint "60 OR LESS ENEMY UNITS LEFT TO ELIMINATE.";
 _below71f = true;
 };

if ((_below61 == true) and (_below61f == false)) then {
 hint "50 OR LESS ENEMY UNITS LEFT TO ELIMINATE.";
 _below61f = true;
 };

if ((_below51 == true) and (_below51f == false)) then {
 hint "40 OR LESS ENEMY UNITS LEFT TO ELIMINATE.";
 _below51f = true;
 };

if ((_below41 == true) and (_below41f == false)) then {
 hint "30 OR LESS ENEMY UNITS LEFT TO ELIMINATE.";
 _below41f = true;
 };

if ((_below31 == true) and (_below31f == false)) then {
 hint "20 OR LESS ENEMY UNITS LEFT TO ELIMINATE.";
 _below31f = true;
 };

if ((_below21 == true) and (_below21f == false)) then {
 hint "10 OR LESS ENEMY UNITS LEFT TO ELIMINATE.";
 _below21f = true;
 };

if ((_below11 == true) and (_below11f == false)) then {
 hint "MISSION ACCOMPLISHED.";
 _below11f = true;
 };  

};

Edited by DeadCommunist

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  

×