Jump to content
Chance536

Get count of dead cup civilians.

Recommended Posts

So I’m trying to add a feature to my mission where the number of civilians killed by players effects things that can happen later in the game. I’m using cup civilians so checking the civilian side isn’t working for me. Is there a way to assign all my civilians to something that I can then assign an event handler to. I don’t care to go through every civilian and add them to an array or something. I just don’t know how. Then say I accomplish this how do I check in the init.sqf that one has died and add a number to the variable. The end result I’m looking for is that all civilian kills by players only are added to a global variable I can use to activate different triggers based on the value. I found several scripts to do it with vanilla civis but they don’t work with cup civis. That’s why I was thinking I could assign all mine to “something” that I can add an event handler to. You’ll probably have to put all this in idiot terms for me it’s been a long time since I’ve tried to program anything.

Share this post


Link to post
Share on other sites
5 hours ago, Chance536 said:

I’m using cup civilians so checking the civilian side isn’t working for me.

 

Works fine here, and there is no reason it shouldn't. Share your code.

  • Like 1

Share this post


Link to post
Share on other sites
addMissionEventHandler ["EntityKilled", {
  params ["_killedUnit","_killer","_triggerMan"];
  if (side group _killedUnit isEqualTo civilian && _killedUnit isKindOf "CAManBase" && side _triggerMan isEqualTo west) then {
    if (isNil {missionNameSpace getVariable "MyCivKillCounter"}) then {
      missionNameSpace setVariable ["MyCivKillCounter",0,true];
    };
    missionNameSpace setVariable ["MyCivKillCounter", (missionNameSpace getVariable ["MyCivKillCounter",0]) + 1, true];
  };
}];

This is the code I found on a other post on here that I modified. I pretty much just need that variable so I can use it for triggers. I don’t exactly fully understand it my main background in programming is with robots, which are much simpler. 

Share this post


Link to post
Share on other sites

Your code works, i'll repost here because you have lots of red dots on copy/paste (forums' bug).

addMissionEventHandler ["EntityKilled", { 
  params ["_killedUnit","_killer","_triggerMan"]; 
  if (side group _killedUnit isEqualTo civilian && _killedUnit isKindOf "CAManBase" && side _triggerMan isEqualTo west) then { 
    if (isNil {missionNameSpace getVariable "MyCivKillCounter"}) then { 
      missionNameSpace setVariable ["MyCivKillCounter",0,true]; 
    }; 
    missionNameSpace setVariable ["MyCivKillCounter", (missionNameSpace getVariable ["MyCivKillCounter",0]) + 1, true];
    systemChat str (missionNameSpace getVariable ["MyCivKillCounter",0]);
  }; 
}];

I added this line which you can delete, it's just for you to debug:

systemChat str (missionNameSpace getVariable ["MyCivKillCounter",0]);

This is also what you want to use on your triggers:

missionNameSpace getVariable ["MyCivKillCounter",0] > <your number here>

 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

@RCA3 beat me to it. However, be aware that a player's side changes from "west" to "enemy" after their rating drops below -2000 (killing 3 civs will do this). This breaks your code in that civ kills will no longer be counted for that player. Fortunately, you can manage player ratings with another handy EH:

 

https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#HandleRating

  • Like 3

Share this post


Link to post
Share on other sites
1 hour ago, Harzach said:

a player's side changes from "west" to "enemy" after their rating drops below -2000 (killing 3 civs will do this). This breaks your code in that civ kills will no longer be counted for that player.

 

Good point!

So, if you don't mind not increasing rating to your players when killing bad guys (or not decreasing rating when killing good guys) , the solution would be to add this into your initPlayerLocal.sqf

params ["_player", "_didJIP"];
_player addEventHandler ["HandleRating", { 
	params ["_unit", "_rating"];
	0 
}];

 

 

  • Like 3

Share this post


Link to post
Share on other sites

Thank you guys I got it to work now. I wasn’t aware of the rating thing. I’m pretty new to arma in general so I’m learning new things everyday.

  • Like 1

Share this post


Link to post
Share on other sites

You already have a nicely working solution from @RCA3 and @Harzach... I'm just propose a minor "improvement" (or let's just call it refactoring).

 

I believe you could skip the check for the existence (and consequent initialisation) of the MyCivKillCounter variable since the last line of your code uses the alternative syntax of getVariable which returns a default value if the variable does not exist.

 

Essentially, there must be a check inside the getVariable command which does the exact same thing. If this is true (which I believe it is but I can't guarantee that since I haven't seen the code of the command) then this check is effectively performed twice, which is redundant of course (the purpose of this alternative syntax is actually to avoid such manual checks to decrease bugs and increase ease of maintenance of the users' codebase).

 

Just to make sure what I proposed is understood, I duplicate your code with the "redundant" check removed (commented out to make sure the difference is clearly visible)

addMissionEventHandler ["EntityKilled", {
  params ["_killedUnit","_killer","_triggerMan"];
  if (side group _killedUnit isEqualTo civilian && _killedUnit isKindOf "CAManBase" && side _triggerMan isEqualTo west) then {
   /* The following section is removed (redundant check)
    * if (isNil {missionNameSpace getVariable "MyCivKillCounter"}) then {
    *   missionNameSpace setVariable ["MyCivKillCounter",0,true];
    * };
    */
    missionNameSpace setVariable ["MyCivKillCounter", (missionNameSpace getVariable ["MyCivKillCounter",0]) + 1, true];
  };
}];

Now, please note that most probably this won't make any huge difference in either speed or efficiency. It may not make a significant difference in maintenance, but I believe it is instructive and constructive in many ways to get advantage of as many features as possible, especially when their efficiency is better, or at worst equal to your implementation.

 

I believe this version is shorter, more clear and communicates your intent better. Nevertheless, since the difference is, most probably, negligible you should stick to your preferred version.

  • Like 2

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

×