Jump to content
Sign in to follow this  
1para{god-father}

Civilian kill Counter

Recommended Posts

SHK_DeadCivilianCount = 0;
SHK_DeadCivilianLimit = 3;
SHK_EndMission = false;
[] spawn {
 waituntil {SHK_EndMission};
 cuttext ["Game over. Unfortunately, you killed too many civilians.","PLAIN",2];
 sleep 10;
 endmission "END2";
};

SHK_fnc_deadCivilians = {
 hintsilent format ["Civilians dead: %1",_this];
 if (_this >= SHK_DeadCivilianLimit) then {
   SHK_EndMission = true;
   publicvariable "SHK_EndMission";
 };
};
SHK_eh_killed = {
 SHK_DeadCivilianCount = SHK_DeadCivilianCount + 1;
 publicvariable "SHK_DeadCivilianCount";
 if isdedicated then {
   if (_this >= SHK_DeadCivilianLimit) then {
     SHK_EndMission = true;
     publicvariable "SHK_EndMission";
   };
 } else {
   SHK_DeadCivilianCount call SHK_fnc_deadCivilians;
 };
};
if isserver then {
 {
   if (side _x == Civilian && _x iskindof "Man") then {
     _x addEventHandler ["killed", SHK_eh_killed];
   };
 } foreach allunits;
} else {
 "SHK_DeadCivilianCount" addpublicvariableeventhandler { (_this select 1) call SHK_fnc_deadCivilians };
};
[] spawn {
 waituntil {!isnil "BIS_alice_mainscope"};
 waituntil {!isnil "bis_fnc_variablespaceadd"};
 [bIS_alice_mainscope,"ALICE_civilianinit",[{_this addEventHandler ["killed", SHK_eh_killed]}]] call bis_fnc_variablespaceadd;
};

  • Like 1

Share this post


Link to post
Share on other sites

As always SHK, very nice work.

One subtle thing, to ensure the civs are killed by BLUFOR and not OPFOR or dying falling of buildings, etc for both ALICE module and editor placed civis, I need to add something of this sort to your script?

this setvariable

[

"ALICE_civilianinit",

[{

_this addeventhandler ["killed",{if(_this select 1 == player) then {McH_Civ_Killed = McH_Civ_Killed + 1;}}]

}]

] call bis_fnc_variablespaceadd

from here:

http://forums.bistudio.com/showpost.php?p=1454291&postcount=12

I'll try to hack this in, but it will be pure trial and error, so any help appreciated!

Share this post


Link to post
Share on other sites

One note, since I did something similar recently -- all dead bodies are considered to be on civilian side. So if you add the same event handler to every unit on the map every kill will register as a civilian kill. To get around this you can use faction.

Share this post


Link to post
Share on other sites
I need to add something of this sort to your script?

Well, I didn't test it, but my guess would be that it won't work that way, because EHs are only added on server and at least on dedi player will never be the killer. On hosted, only the person who is hosting is.

So, instead of having a condition with player in it, just use side to check if its east/west, or just not civ. First check what side the killer is, if it's even returned for accidents.

Share this post


Link to post
Share on other sites

Hi SHK,

I am also trying to get this to work when just Bluefor kill a civi , as way to often they just walk off something and kill themslef and the kill counter add up !.

How would i just check that Bluefor killed the civi ?

Thanks

Share this post


Link to post
Share on other sites
SHK_eh_killed = {
 private "_side";
 _side = side (_this select 1);
 if (_side == WEST) then {
   SHK_DeadCivilianCount = SHK_DeadCivilianCount + 1;
   publicvariable "SHK_DeadCivilianCount";
   if isdedicated then {
     if (_this >= SHK_DeadCivilianLimit) then {
       SHK_EndMission = true;
       publicvariable "SHK_EndMission";
     };
   } else {
     SHK_DeadCivilianCount call SHK_fnc_deadCivilians;
   };
 };
};

Share this post


Link to post
Share on other sites

This worked great for me in Takistan, but I'm curious if anyone has used this with ambient civs in Duala?

I'm playing as a PMC, and I have changed the "WEST" in the code to "GUER", but so far no go.

Wondering if it's a problem with the 'custom' ambients in Duala.

Share this post


Link to post
Share on other sites

Independent/Guerilla/Resistance side is actually Resistance. The string format is "GUER".

Share this post


Link to post
Share on other sites

Thank you for correcting me sir. It's now working like a charm.

As always, grateful for your time.

Share this post


Link to post
Share on other sites

Sorry, yet another question regarding this. Any way to keep track of DAC-spawned units?

Thanks

Share this post


Link to post
Share on other sites

I've never checked out DAC, but I'd imagine that there is a way to define init or add eventhandlers to units?

Then it just takes something like this:

_this addEventHandler ["killed", SHK_eh_killed]

Share this post


Link to post
Share on other sites

That's doing the trick, sort of. I found out how to execute what I am calling "counter.sqf" with your very first code post from page one, after a DAC group is spawned. There is a problem however, I need to figure out how to prevent the script from being run repeatedly as that is multiplying the counter. Making progress at least. Thanks.

---------- Post added at 08:21 AM ---------- Previous post was at 08:06 AM ----------

had to do quite a bit of digging but i figured out how to execute it only once, using DAC. the manual says nothing about the ability to execute other scripts along with DAC, just after a group is created and other things.

Share this post


Link to post
Share on other sites

If you don't mind my asking, how? I have experimented a little with the config_events file (or whatever it's called) and event handlers in the past, but never got anything like that working. What method did you use with DAC to do that?

Share this post


Link to post
Share on other sites

from DAC_Config_Creator:

if(DAC_Code < 2) then
{
//===========================================|
// StartScriptOnServer                       |
//===========================================|
//player sidechat "ServerStart"
//[] execVM "myServerScript.sqf";
[] execVM "counter.sqf";
//onMapSingleClick "_fun = [_pos,_shift]execVM ""Action.sqf""";
//[[sec1,""]] execVM "DAC\Scripts\DAC_Init_Sector.sqf";
}

Since it's four pages back, here is his very first code post (out of the ~10) that I am using for now.

Share this post


Link to post
Share on other sites

SHK,

Thanks very much for continuing to develop this one. I tried getting it to run as a separate "deathcounter.sqf" but cannot seem to get it to run reliably on a dedicated server. Its pretty critical to regain balance in a mission I am developing.

I don`t have the knowledge, can you help...pretty please.

Share this post


Link to post
Share on other sites

Should work just fine if you are starting the script on every machine.

Got the example mission in post 22 to work?

Share this post


Link to post
Share on other sites

shuko,

Doah.....won`t work when I put civiliandeathcount,sqf anyway

Got it cracked now, thanks for the quick response.

I had added a server check to an earlier version, so that was probably the dedi issue, thanks

Edited by UGLY58

Share this post


Link to post
Share on other sites

Shuko,

Still not getting a public variable HINT on a dedi server, seems to work fine locally in the editor, including end mission.

EDIT:

Sorry noticed after posting that you have some additional code for ALICE generated civilians in your message 22 sample...I will try that.

Edited by UGLY58

Share this post


Link to post
Share on other sites

Shuko, I have built upon your code using the method from that thread I started, and of course it works beautifully on a listen server but I haven't a clue what to change at the bottom, or if I need to do something entirely different for a dedicated. By the way, I won't be surprised if I am using redundant code. Beginner, remember.

deadmarinecount = 0;
deadcivcount = 0;
fnc_scoreboard = {
 _text = format["marines murdered: %1",deadmarinecount];
 hint parsetext _text;
 _text = (_text + "<br/>" + format ["civilian casualties: %1",deadcivcount]);
 hint parsetext _text;
};

if isserver then {
 {
   if (_x iskindof "USMC_Soldier_Base") then {
     _x addEventHandler ["killed", {
       deadmarinecount = deadmarinecount + 1;
       publicvariable "deadmarinecount";
       if !isdedicated then {
         deadmarinecount call fnc_scoreboard;
       };
     }];
   };
 } foreach allunits;
};

if isserver then {
 {
   if (_x iskindof "Civilian") then {
     _x addEventHandler ["killed", {
       deadcivcount = deadcivcount + 1;
       publicvariable "deadcivcount";
       if !isdedicated then {
         deadcivcount call fnc_scoreboard;
       };
     }];
   };
 } foreach allunits;
};
/*
if !isdedicated then {
 "deadmarinecount" addpublicvariableeventhandler { ? };
 "deadcivcount" addpublicvariableeventhandler { ? };
};
*/

Share this post


Link to post
Share on other sites

I had been looking for an explanation on those; the BIKI didn't exactly suffice. Thanks.

Share this post


Link to post
Share on other sites

Shuko,

I have never seen that site, nice explanations. Let me see if I can crack it, I guessed that was the issue but your right I don`t understand it fully.

Dorian,

Yeah agree the BIKI is pretty poor when it comes to the server/client code execution stuff.

Schuko - "Better to learn than mimic" - thanks

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  

×