Jump to content
Mynock

Seeking help modifying EH script for civilian casualties

Recommended Posts

So I grabbed this script from a youtube video because the basics of it do what I want. It's a Bangabob script as far as I am aware, but seeing as how he has been inactive on the forum for about a year now I don't think PM'ing him will lead to a response. I checked and there was nothing in the youtube video regarding modifications to this script, so as far as I can tell it should be okay to modify it some without seeking permission (which might be hard to obtain due to his inactivity).

This script checks if a player has killed a unit and if so displays their name in a map marker. Instead of displaying the map marker, I'd like it to instead just check how many civilians the player has killed total, and once that number meets or exceeds a threshold, to fail an objective via a trigger and task state module.

My situation is: I'm wanting to use this in a single player mission, but the mission has 6 playable units. The reason I want to use this particular script to count civilian deaths is because it checks to see if the player actually killed the civilian and not someone else; seeing as how erratic the AI can be I don't want to punish the player by having them fail the objective because some AI unit didn't watch his fire or an idiot civilian ran through the middle of an AI firefight.

This is the script as is:

if (isServer)then{
_unit=(_this select 0);

_unit addEventHandler ["killed", {
 _unit=		(_this select 0); // UNIT THAT DIED
 _killer=	(_this select 1); // UNIT THAT KILLED THE UNIT
 

if (isPlayer _killer)then{ // IF KILLER IS A PLAYER
 _id =		format ["civScriptid%1",_unit]; // UNIQUE MARKER NAME
 _text=		format ["%1 Killed a civilian",name _killer]; // FORM MARKER TEXT


	_mkr = createMarker [_id,getPosASL _unit]; // CREATE MARKER
	_mkr setMarkerShape "ICON";
	_mkr setMarkerType "hd_warning";
	_mkr setMarkerText _text;
	_mkr setMarkerColor "colorRed";
	_mkr setMarkerAlpha 0.5;
	
 _unit removeAllEventHandlers "killed"; // REMOVE EVENT HANDLER
			};
		}];
	};
This is what I think I want to do, but I'm hoping someone with more knowledge and experience can verify or tell me the proper way to do it:

if (isServer)then{
_unit=(_this select 0);

_unit addEventHandler ["killed", {
 _unit=		(_this select 0); // UNIT THAT DIED
 _killer=	(_this select 1); // UNIT THAT KILLED THE UNIT
 

if (isPlayer _killer)then{ // IF KILLER IS A PLAYER
 civdeathcount = civdeathcount + 1; // Adds 1 death to the counter I think?
	
 _unit removeAllEventHandlers "killed"; // REMOVE EVENT HANDLER
			};
		}];
	};
To use this method I'll need to define the global variable of civdeathcount at an initial value of 0 in the init.sqf file, correct? From there I was planning to use a trigger to check if the civdeathcount variable was equal to or greater than 2, and sync that to a failed task state module.

Share this post


Link to post
Share on other sites

Thanks for the link, but I don't want the mission to fail in my situation. I just want to activate a task state module through a trigger and was wondering if the method and changes I described above would cause that to happen.

I also wasn't sure if the isServer was necessary for a single player scenario.

Share this post


Link to post
Share on other sites

Ok, replace failMission with

_task = ["task1", "FAILED"] spawn BIS_fnc_taskSetState;

Share this post


Link to post
Share on other sites

In testing so far it seems to work in the way I described, next on the list is checking to see if it works after the player switches units. But is there some advantage I'm not aware of in putting the BI task state function in the script instead? I'm much more comfortable with triggers and modules personally, I've only been playing Arma for a year, so I don't come from the same line as the people who have scripted things manually for years and years with OFP, etc.

Share this post


Link to post
Share on other sites

Umm.. not really, if you're comfortable with triggers, by all means continue to use them.  There's the endMission gotcha to think about, but otherwise modules should be OK now.

Share this post


Link to post
Share on other sites

use this script for each unit

private ["_unit"];
params ["_unit"];

_unit removeAllEventHandlers "killed";

_unit addEventHandler ["killed", {

    private ["_unit", "_killer", "_killCount"];
    params [
        "_unit", //unit: Object - Object the event handler is assigned to 
        "_killer", //killer: Object - Object that killed the unit
    ];

    if ( (isPlayer _killer) and (faction _unit == "CIV_F") ) then { 
        _killCount = _killer getVariable ["killed_civilians", 0];
        _killCount = _killCount + 1;
        _killer setVariable ["killed_civilians", _killCount];
    };

}];

Then you can get killCount for each player individualy

_killedCivilians = player getVariable ["killed_civilians", 0];

Share this post


Link to post
Share on other sites

use this script for each unit

private ["_unit"];
params ["_unit"];

_unit removeAllEventHandlers "killed";

_unit addEventHandler ["killed", {

    private ["_unit", "_killer", "_killCount"];
    params [
        "_unit", //unit: Object - Object the event handler is assigned to 
        "_killer", //killer: Object - Object that killed the unit
    ];

    if ( (isPlayer _killer) and (faction _unit == "CIV_F") ) then { 
        _killCount = _killer getVariable ["killed_civilians", 0];
        _killCount = _killCount + 1;
        _killer setVariable ["killed_civilians", _killCount];
    };

}];
Then you can get killCount for each player individualy

_killedCivilians = player getVariable ["killed_civilians", 0];

What is the benefit of having a kill count for each player when there's only one player? Do you mean it will tie that kill count to a particular unit and save it when the player switches to another unit? All I'm trying to do is avoid counting civilian casualties caused by AI, because that doesn't seem fair when they don't see civilians as an obstacle and don't care about hitting them or not.

Share this post


Link to post
Share on other sites

Important thing in script is condition

(isPlayer _killer) and (faction _unit == "CIV_F")

In your script you count every kill that player did. You did not recognized if victim was enemy or civilian. If you have only civilians in your mission, then it is fine.

Share this post


Link to post
Share on other sites

Important thing in script is condition

(isPlayer _killer) and (faction _unit == "CIV_F")
In your script you count every kill that player did. You did not recognized if victim was enemy or civilian. If you have only civilians in your mission, then it is fine.
Well I guess I'm just too ignorant to understand why this is better, sorry. In my testing with the modifications to the script I did, I can drop as many enemies as I like, even friendlies if I'm feeling evil or have particularly bad aim, with no consequences. Only killing the civilian faction units I'm running the script on causes the objective to fail. When I try your version it doesn't seem to work the way I was hoping when I switch units because if I kill 1 civilian per unit, which is 6 total, the objective never fails. I don't know if that's because yours only uses a local variable for the script itself or not.

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

×