Jump to content
swiso

trigger "mission fail" if "x" amount of civilians killed

Recommended Posts

Can anybody suggest me a trigger command that end the mission as a failed mission (I will use "End4" for this) if BLUFOR ( the only playable side) kill a civilian ? ( or let say a certain amount of civilians...like 3)

Thanks !

Share this post


Link to post
Share on other sites

The best way, imo, is to let the game's own system handle it. You get a large penalty for killing a civ and when your score gets below -2000, your side switches to "ENEMY", so you could just use

side player == enemy

as a condition. To get more control, you need to use an event handler, e.g.:

civsKilled = 0;

{
	if (side _x == civ) then {
		_x addEventHandler ["Killed", {
			if (_this select 1 == player) then {
				civsKilled = civsKilled +1;
			}
		}]
	}
} count allUnits;

And set the condition to something like civsKilled == 3;

  • Like 1

Share this post


Link to post
Share on other sites

The best way, imo, is to let the game's own system handle it. You get a large penalty for killing a civ and when your score gets below -2000, your side switches to "ENEMY", so you could just use

side player == enemy

as a condition. To get more control, you need to use an event handler, e.g.:

civsKilled = 0;

{
	if (side _x == civ) then {
		_x addEventHandler ["Killed", {
			if (_this select 1 == player) then {
				civsKilled = _civsKilled +1;
			}
		}]
	}
} count allUnits;

And set the condition to something like civsKilled == 3;

 

Won't work because you're using the local variable _civsKilled, it's undefined.

The side enemy check is neat, could work out fine.

 

This should do the trick:

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"};

    };

}];

Cheers

  • Like 3
  • Thanks 2

Share this post


Link to post
Share on other sites

Won't work because you're using the local variable _civsKilled, it's undefined.

That was just a typo. :P

Share this post


Link to post
Share on other sites

Thanks guys.

Grumpy Old Man, should I copy and paste that script to the "description.ext" file or directly to the "Condition" spot on the trigger ?

 

Should add a trigger in the game map named something like " Mission failed trigger 2" ("mission failed trigger 1" is if all players are killed) and then "On Activation" I should type : "end4" call BIS_fnc_endMission ?

What I should type in the "Condition" spot ?

Thanks

 

PS : sorry I am not very expert on editing...I was just able to create my first mission.... :icon_redface:

Share this post


Link to post
Share on other sites

Put it in the init.sqf, no triggers needed, should instantly end the mission after the third civilian has been shot by blufor.

The description.ext hasn't much to do with scripts.

 

Cheers

Share this post


Link to post
Share on other sites

Put it in the init.sqf, no triggers needed, should instantly end the mission after the third civilian has been shot by blufor.

The description.ext hasn't much to do with scripts.

 

Cheers

Thank you very much mate.

When back from work I will try it.

Best regards.

Share this post


Link to post
Share on other sites

This should do the trick:

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"};

    };

}];

Cheers

 

Works like a charm with civilian but I wonder why it won't work when using east or opfor in the condition?

Share this post


Link to post
Share on other sites

Because all dead units are civilian even if they are not. The code might need tweaking to test side of the group of killed unit.

  • Like 3

Share this post


Link to post
Share on other sites

Works like a charm with civilian but I wonder why it won't work when using east or opfor in the condition?

 

Like KK said, once a unit is dead its side is civilian regardless of the side it belonged to before dying/getting destroyed.

Unfortunately this is some wonky solution to stop units shooting at stuff that's already dead.

 

Why there is no "dead" side is beyond me, would make more sense.

 

Possible solution:

MyWestKillCounter = 0;

addMissionEventHandler ["EntityKilled",{

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

    _configSide = [getNumber (configfile >> "CfgVehicles" >> typeOf _killedUnit >> "side")] call BIS_fnc_sideType;
    hint str _configside;

    if (_configSide isEqualTo west AND side _triggerMan isEqualTo west) then {

        MyWestKillCounter = MyWestKillCounter + 1;

        if (MyWestKillCounter >= 3) then {endMission "End4"};

    };

}];

This will check for the side of the units config.

 

Could cause errors since after killing 2-3 units the killer gets put on the "enemy" side, making the second condition in the first if statement false.

To prevent this you have to check for the config side of the shooters unit too, which isn't really a simple solution either, if you're switching sides or setting captive states during the mission.

 

Cheers

  • Like 4

Share this post


Link to post
Share on other sites
On 19/10/2016 at 10:07 AM, Grumpy Old Man said:

 

Like KK said, once a unit is dead its side is civilian regardless of the side it belonged to before dying/getting destroyed.

Unfortunately this is some wonky solution to stop units shooting at stuff that's already dead.

 

Why there is no "dead" side is beyond me, would make more sense.

 

Possible solution:


MyWestKillCounter = 0;

addMissionEventHandler ["EntityKilled",{

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

    _configSide = [getNumber (configfile >> "CfgVehicles" >> typeOf _killedUnit >> "side")] call BIS_fnc_sideType;
    hint str _configside;

    if (_configSide isEqualTo west AND side _triggerMan isEqualTo west) then {

        MyWestKillCounter = MyWestKillCounter + 1;

        if (MyWestKillCounter >= 3) then {endMission "End4"};

    };

}];

This will check for the side of the units config.

 

Could cause errors since after killing 2-3 units the killer gets put on the "enemy" side, making the second condition in the first if statement false.

To prevent this you have to check for the config side of the shooters unit too, which isn't really a simple solution either, if you're switching sides or setting captive states during the mission.

 

Cheers

 

They didn't thank you, but lemme do it for them:
Thank you, sir.  Your support given to this thread helped me a lot :)

  • Like 2

Share this post


Link to post
Share on other sites

Just to enhance the variety of solutions, it's also possible to retrieve the side of the unit through its group.

Again, wonky solution for detecting killed civilians by blufor but should work in most cases:

MyCivKillCounter = 0;

addMissionEventHandler ["EntityKilled",{

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

    if (side group _killedUnit isEqualTo civilian AND side _triggerMan isEqualTo west) then {

        MyCivKillCounter = MyCivKillCounter + 1;

        if (MyCivKillCounter >= 3) then {endMission "End4"};

    };

}];

Unfortunately it's not possible to check if the unit was captive before getting killed, since captive command returns false for all dead units, even if it was setCaptive true at the moment of death.

Ticket is out if it's a bug, doesn't seem like it's intended the way it works now.

 

Cheers

  • Like 2

Share this post


Link to post
Share on other sites

I wanted to do something different, that whenever certain amount of civilians die, no matter who or what killed them, the mision fails. Most of the deaths are roadkills and the Side command didn't really work with that, because when a unit dies it is set to CIV side and it was hard to tell in my script if the killedunit was a CIV or a soldier. So I ended using the Faction command and it worked like a charm:

MyCivKillCounter = 0;

addMissionEventHandler ["EntityKilled",{

    params ["_killed","_killer","_instigator"];

	 _faction = faction _killed;
	
    if (_faction isEqualto "CIV_F") then {

        MyCivKillCounter = MyCivKillCounter + 1;

        if (MyCivKillCounter >= 1) then {["end2", false] call BIS_fnc_endMission; hint "One or more civilians died!"};

    };

}];

Edit: Using Side command also affects all the editor spawned objets. They belong to the civilian group as well and also recognised by _killed if they get destroyed. This could cause unwanted results. Faction command only gives you the original faction name.
 

  • Like 2

Share this post


Link to post
Share on other sites

Thanks for this.  I found it useful.  I ended up with the section from Grumpy in my init.sqf.  I took the end parts out and put them in triggers so I could have hints to the players to stop as well as a countdown and fail mission.

 

MyCivKillCounter = 0;

addMissionEventHandler ["EntityKilled",{

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

    if (side _killedUnit isEqualTo civilian AND side _triggerMan isEqualTo west) then {

        MyCivKillCounter = MyCivKillCounter + 1;

    };

}];

 

Share this post


Link to post
Share on other sites

You are speaking about the player side, so I assume there are several players. Right?

Your code will stay on players' PC. I mean local on each player, so your myCivKillCounter wil be local, allowing each player to kill 3 civilians (If I understood). Is it the expected effect?

Share this post


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

You are speaking about the player side, so I assume there are several players. Right?

Your code will stay on players' PC. I mean local on each player, so your myCivKillCounter wil be local, allowing each player to kill 3 civilians (If I understood). Is it the expected effect?

 

Yes.  Player side.  If it would be only local to player, how would one do this for all players on a server?  Also, I noticed in my tests that even destroying buildings counts against the civilian kills.  What if I only want to count civilian AI?

What I was hoping to do is warn players if they are killing civilian AI and fail the mission if a number of civilian AI are killed.

Share this post


Link to post
Share on other sites

You need to add the isKindOf "CAManBase" condition ("Man" counts rabbits thanks to BI)

 

For a global count (all the players fail for too much civilian victims) they are several means but I suggest you the global (public) variable property of the setVariable command:

 

(you don't need to initialize the counter here)

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];
    if (missionNameSpace getVariable ["MyCivKillCounter",0] >= 3) then {
      "everyoneLost" call BIS_fnc_endMissionServer;
    };
  };
}];

EDITED

Now, you have have a simple common counter for west (AIs or players)

 

you can try:

[ ["end2", false], BIS_fnc_endMission] remoteExec ["call",west];

if you have several sides of players.

 

  • Like 2

Share this post


Link to post
Share on other sites
On 9/22/2016 at 1:38 PM, Grumpy Old Man said:

Put it in the init.sqf, no triggers needed, should instantly end the mission after the third civilian has been shot by blufor.

The description.ext hasn't much to do with scripts.

 

Cheers

===========================

The scripting's not working anymore?;

 

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"};     }; }];

 

Seems to have stopped working? is there an 2019 update.   Its not differentiating between civilian & any other faction, East, independent. CUP or vanilla. Seems once any unit is dead they're civilians & as soon as 3 (or whatever # set)  enemy units have been killed mission also ends.

Share this post


Link to post
Share on other sites
4 minutes ago, jgaz-uk said:

===========================

The scripting's not working anymore?;

 

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"};     }; }];

 

Seems to have stopped working? is there an 2019 update.   Its not differentiating between civilian & any other faction, East, independent. CUP or vanilla. Seems once any unit is dead they're civilians & as soon as 3 (or whatever # set)  enemy units have been killed mission also ends.

That's not the snippet I posted, you're missing the "side group _killedUnit" and instead have "side _killedUnit" instead for some reason.

Of course this won't work.

The snippet I posted on the other hand still works in 2019.

 

Cheers

Share this post


Link to post
Share on other sites

I copied it directly from your "This should do the trick" previously  Posted September 22, 2016

 

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"};     }; }];

 

======================================

 

I changed the scripting to the "side group _killedUnit" & with default civs it works fine.
 But using the civilian module spawning in CUP Takistani civilians. nothing happens, is it a name problem, or because they're spawned in by the Module?

 

Share this post


Link to post
Share on other sites

Yes from the init, also tried an "initServer" works with vanilla civilians, but not  the CUP civs. tried using faction names, still nix.

Looking to prevent players NOT PIDing targets & just blasting away from a distance in missions.

WIP.

Share this post


Link to post
Share on other sites
On 9/22/2016 at 4:07 AM, Grumpy Old Man said:

 

Won't work because you're using the local variable _civsKilled, it's undefined.

The side enemy check is neat, could work out fine.

 

This should do the trick:


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"};

    };

}];

Cheers

 

I try it, that work fine.

I would like to use it to spawn guerrilla if too much civ are killed in a specific town, so i just replace the last line :

if (MyCivKillCounter >= 3) then {[] execVM "test.sqf"};

test.sqf its my script for spawning guerilla, so i would like to know if its possible to count dead civilian only inside a trigger area cause i would like to spawn the guerilla unit only in the town where are killed the civilian.

 

 

 

For exemple

Share this post


Link to post
Share on other sites

Simple way:

 

Set up a trigger

Activation is Civilian, Once and Present

in the condition field:   count  thislist   <  4:

When there are less than 4 civilians in the trigger area, the trigger will fire.

 

(You have to actually use civilians. BlueForce are blue colour,  OpForce are red colour and Civilians are purple colour).

 

 

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

×