Jump to content
olegreyghost

Script is mis-identifying dead units

Recommended Posts

I was using the civilian casualty counter script posted by the Grumpy Old Man. The purpose is to end the mission if there are too many civilian casualties and notify the player with a debriefing screen.
 

MyCivKillCounter = 0;
addMissionEventHandler ["EntityKilled",{
 params ["_killedUnit","_killer","_triggerMan"];
 if (side _killedUnit isEqualTo civilian AND side _triggerMan isEqualTo west)  then {
   MyCivKillCounter = MyCivKillCounter + 1;
   if (MyCivKillCounter >= 3) then {endMission "End4"};
  };
}];

The problem is it ended the mission when the enemy units were killed.  The debriefing screen showed opfor units killed, but not any civilians.
This was a recurring problem so I switched to a similar script posted by Kylania.   Both are used in the init.sqf.

if (isServer) then
{
 FNH_civilians_killed = 0;
 addMissionEventHandler ["EntityKilled",
 {
  _killed = _this select 0;
  if (side group _killed == civilian) then
  {
   FNH_civilians_killed = FNH_civilians_killed + 1;
   if (FNH_civilians_killed > 2) then
   {
    ["End6", true, 4] call BIS_fnc_endMission
   };
  };
 }];
};

This worked fine thru a month of testing and adding other things to the mission. 

After I made  a change to some triggers for text communications, the error popped up again.  The triggers are separate & not related in any way to the civilians.

 

I am using the islamic state guerilla units from project OpFor as the enemy units.
LOP_ISTS_OPF_Infantry_Rifleman_2 & _3       LOP_ISTS_OPF_Infantry_SL.

 

Any help in resolving the problem will be greatly appreciated....

Share this post


Link to post
Share on other sites

All deads are civilian

Replace : side _killedUnit isEqualTo civilian  by ([_killedUnit,true] call BIS_fnc_ObjectSide) isEqualTo CIVILIAN

Share this post


Link to post
Share on other sites
2 hours ago, olegreyghost said:

I was using the civilian casualty counter script posted by the Grumpy Old Man. The purpose is to end the mission if there are too many civilian casualties and notify the player with a debriefing screen.
 


MyCivKillCounter = 0;
addMissionEventHandler ["EntityKilled",{
 params ["_killedUnit","_killer","_triggerMan"];
 if (side _killedUnit isEqualTo civilian AND side _triggerMan isEqualTo west)  then {
   MyCivKillCounter = MyCivKillCounter + 1;
   if (MyCivKillCounter >= 3) then {endMission "End4"};
  };
}];

The problem is it ended the mission when the enemy units were killed.  The debriefing screen showed opfor units killed, but not any civilians.
This was a recurring problem so I switched to a similar script posted by Kylania.   Both are used in the init.sqf.


if (isServer) then
{
 FNH_civilians_killed = 0;
 addMissionEventHandler ["EntityKilled",
 {
  _killed = _this select 0;
  if (side group _killed == civilian) then
  {
   FNH_civilians_killed = FNH_civilians_killed + 1;
   if (FNH_civilians_killed > 2) then
   {
    ["End6", true, 4] call BIS_fnc_endMission
   };
  };
 }];
};

This worked fine thru a month of testing and adding other things to the mission. 

After I made  a change to some triggers for text communications, the error popped up again.  The triggers are separate & not related in any way to the civilians.

 

I am using the islamic state guerilla units from project OpFor as the enemy units.
LOP_ISTS_OPF_Infantry_Rifleman_2 & _3       LOP_ISTS_OPF_Infantry_SL.

 

Any help in resolving the problem will be greatly appreciated....

 

The snippet was from a thread which evolved a bit further, first post including my example you used.

Later in the thread as KK pointed out as well as @pierremgi stated here, all killed units belong to the civilian side, so I altered the snippet to check for the units group instead, as seen in this post.

 

To further enhance it and make only infantry units count it could look like this:

addMissionEventHandler ["EntityKilled",{

    params ["_killedUnit","_killer","_triggerMan"];

    if (side group _killedUnit isEqualTo civilian AND typeOf _killedUnit isKindof "CAManBase" AND side _triggerMan isEqualTo west) then {

		_oldCount = missionNamespace getVariable ["GOM_fnc_CivKillCounter",0];
		_newCount = _oldCount + 1;
		missionNamespace setVariable ["GOM_fnc_CivKillCounter",_newCount,true];
        
        if (_newCount >= 3) then {endMission "End4"};

    };

}];

Checking for the side of the group is another solution, since it takes a few seconds for a dead unit to be removed from its group.

You could also use the solution posted by @pierremgi.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

@pierremgi & @Grumpy Old Man:

 

Thank you both for the for taking the time to point out my error.  It was that thread that I found the snippet.

Didn't realize there was more to it.  Will update my reading habits...

Will try solution proposed by @pierremgi , as it is easier for me to follow.

 

Question on calling the ending:

       Can I use  { ["End4", true, 4] call BIS_fnc_endMission };  in place of   {endMission "End4"};
 

Regards....

Share this post


Link to post
Share on other sites
16 minutes ago, olegreyghost said:

@pierremgi & @Grumpy Old Man:

 

Thank you both for the for taking the time to point out my error.  It was that thread that I found the snippet.

Didn't realize there was more to it.  Will update my reading habits...

Will try solution proposed by @pierremgi , as it is easier for me to follow.

 

Question on calling the ending:

       Can I use  { ["End4", true, 4] call BIS_fnc_endMission };  in place of   {endMission "End4"};
 

Regards....

Depends, if you want to use it in multiplayer you'd better use BIS_fnc_endMissionServer.

 

Cheers

Share this post


Link to post
Share on other sites

No.  It is just a single player mission.  Everything is OJT.

 

Found out if I use @pierremgi s snippet I am missing  ( which would probably throw an error.

 

Changing   (side _killedUnit isEqualTo civilian AND side _triggerMan isEqualTo west)  to

   (  [_killedUnit,true] call BIS_fnc_ObjectSide  ) isEqualTo CIVILIAN AND side _triggerMan isEqualTo west  ).   This last parenthesis is an orphan. 

 

What would be the correct syntax for the new statement??

 

 

Share this post


Link to post
Share on other sites
36 minutes ago, olegreyghost said:

No.  It is just a single player mission.  Everything is OJT.

 

Found out if I use @pierremgi s snippet I am missing  ( which would probably throw an error.

 

Changing   (side _killedUnit isEqualTo civilian AND side _triggerMan isEqualTo west)  to

   (  [_killedUnit,true] call BIS_fnc_ObjectSide  ) isEqualTo CIVILIAN AND side _triggerMan isEqualTo west  ).   This last parenthesis is an orphan. 

 

What would be the correct syntax for the new statement??

 

 

Always post the full snippet, might look something like this:

 

addMissionEventHandler ["EntityKilled",{

    params ["_killedUnit","_killer","_triggerMan"];

    if (([_killedUnit,true] call BIS_fnc_ObjectSide) isEqualTo CIVILIAN AND typeOf _killedUnit isKindof "CAManBase" AND side _triggerMan isEqualTo west) then {

		_oldCount = missionNamespace getVariable ["GOM_fnc_CivKillCounter",0];
		_newCount = _oldCount + 1;
		missionNamespace setVariable ["GOM_fnc_CivKillCounter",_newCount,true];
        
        if (_newCount >= 3) then {endMission "End4"};

    };

}];

 

Cheers

Share this post


Link to post
Share on other sites

Thanks, that helped clear it up.

 

Also for the heads up on posting the full snippet.

 

Regards......

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

×