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

Civilian kill Counter

Recommended Posts

Ok I have looked through the threads but cannot get it to work,

So if anyone could let me know how I can do this I would be really grateful!

I need to count how many Civilians have been killed and show this on the top right somewhere for everyone to see if they reach 10 it will end the game.

Many thanks

Paul

Share this post


Link to post
Share on other sites

I've seen several threads with working method of doing this. If you found at least one of those, what makes you think that someone copy pasting the code into this new thread will somehow make you have a higher chance of succeeding?

Share this post


Link to post
Share on other sites

I haven't been able to get any of them working either. :/ And I've been around awhile. ;)

Share this post


Link to post
Share on other sites

Simple 1+1 on server and then updating clients with pv+pveh?

Share this post


Link to post
Share on other sites

hehe

You'd think. :)

Post the code that works, and I can see what I've been doing wrong. :) Every time I think I have the EH-scope thing worked out... I don't....

Share this post


Link to post
Share on other sites

In my opinion script should go like this:

1) search through all units to find civilians

http://community.bistudio.com/wiki/allUnits

http://community.bistudio.com/wiki/side

2) add eventHandler killed to all of them

http://community.bistudio.com/wiki/addEventHandler

3) execute one simple script that would update a number of killed civilians...

4) on every update check a critical level for ending mission

This is just a draft. I hope it would help. Sorry don't have time now to write that script down and test it, but I truly hope someone will get the idea and make it.

Cheers

Share this post


Link to post
Share on other sites

Just made this in 10mins, tested to work in SP, on hosted and dedicated servers.

SHK_DeadCivilianCount = 0;
SHK_DeadCivilianLimit = 10;
SHK_fnc_deadCivilians = {
 hintsilent format ["Civilians dead: %1",_this];
 if (_this >= SHK_DeadCivilianLimit) then {
   player sidechat "mission end"; // end mission, do whatever
 };
};
if isserver then {
 {
   if (side _x == Civilian) then {
     _x addEventHandler ["killed", {
       SHK_DeadCivilianCount = SHK_DeadCivilianCount + 1;
       publicvariable "SHK_DeadCivilianCount";
       if !isdedicated then {
         SHK_DeadCivilianCount call SHK_fnc_deadCivilians;
       };
     }];
   };
 } foreach allunits;
};
if !isdedicated then {
 "SHK_DeadCivilianCount" addpublicvariableeventhandler { (_this select 1) call SHK_fnc_deadCivilians };
};

Edit: It might need a more precise filter, because lot's of random stuff tends to be civilian. So, something like this

if (side _x == Civilian && _x iskindof "Man") then {

might be in order to replace this

if (side _x == Civilian) then {

Edited by Shuko

Share this post


Link to post
Share on other sites

Excellent! :D Can't wait to test it myself!

Edit: in looking at it, I believe my mistake has been the omission of that last bit about !isdedicated - I never would've worked that out! THanks!

Edited by TRexian

Share this post


Link to post
Share on other sites

thanx shk :) that's what I meant with idea. I don't even have time to sit in front my PC and finish the addon, too many other obligations.

I learned from your example that one can call the variable. I was using it coupled with compile /+ format syntax. Thanx

so psvialli there you have it. hope you will use it well.

Share this post


Link to post
Share on other sites
Excellent! :D Can't wait to test it myself!

Edit: in looking at it, I believe my mistake has been the omission of that last bit about !isdedicated - I never would've worked that out! THanks!

Actually, that isnt even required. Doesnt matter if its there or not. :)

The PVEH is only for clients (non host) anyway, so you can go with a simple else:

SHK_DeadCivilianCount = 0;
SHK_DeadCivilianLimit = 10;
SHK_fnc_deadCivilians = {
 hintsilent format ["Civilians dead: %1",_this];
 if (_this >= SHK_DeadCivilianLimit) then {
   player sidechat "mission end"; // whatever
 };
};
if isserver then {
 {
   if (side _x == Civilian && _x iskindof "Man") then {
     _x addEventHandler ["killed", {
       SHK_DeadCivilianCount = SHK_DeadCivilianCount + 1;
       publicvariable "SHK_DeadCivilianCount";
       if !isdedicated then {
         SHK_DeadCivilianCount call SHK_fnc_deadCivilians;
       };
     }];
   };
 } foreach allunits;
} else {
 "SHK_DeadCivilianCount" addpublicvariableeventhandler { (_this select 1) call SHK_fnc_deadCivilians };
};

Share this post


Link to post
Share on other sites

hehe

Regardless, I can tell you how many fumbling iterations I've tried and not gotten it to work. Yours is the first concise post I've found with a solution. :thumbsup:

How about this - if another global/public variable is set to true it marks the location of the kill on the map? :)

Share this post


Link to post
Share on other sites

Untested:

SHK_fnc_deadCivilians = {
 hintsilent format ["Civilians dead: %1",_this];
 if (SOMEOTHERVAR && isserver) then {
   private "_m";
   _m = createMarker [format ["marker_deadcivilian_%1",SHK_DeadCivilianCount],getpos _this];
   _m setMarkerShape "ICON";
   _m setMarkerType "Dot";
   _m setMarkerColor "ColorWhite";
 };
 if (_this >= SHK_DeadCivilianLimit) then {
   player sidechat "mission end"; // whatever
 };
};

EDIT: Hmm actually, you probably have to move the "if !isdedicated then {" check from the EH code into the function. Otherwise it won't work in dedi servers.

Edited by Shuko

Share this post


Link to post
Share on other sites

Thank you so much it works perfect !

---------- Post added at 08:04 PM ---------- Previous post was at 07:28 PM ----------

If I wanted to expand this and count Offor Kills as well i know i need to change iskindof to the correct type but what to I tried "offor" and "Solider" but they are not correct

many thanks

Share this post


Link to post
Share on other sites
I learned from your example that one can call the variable. I was using it coupled with compile /+ format syntax.

If you ever done this then it is the practically the same with the difference being it is in a separate file:

_myFunc = compile preProcessFile "MyScript.sqf";
...
call _myFunc;

Share this post


Link to post
Share on other sites

EDIT: Hmm actually, you probably have to move the "if !isdedicated then {" check from the EH code into the function. Otherwise it won't work in dedi servers.

Uh oh... I'm sorry, but as I'm trying to implement this, it seems like there's a circular reference. :)

If I understand, the conditional in the EH is:

       if !isdedicated then {
         SHK_DeadCivilianCount call SHK_fnc_deadCivilians;
       };

If you move that into the function, then if it is not dedicated, it will endlessly test and start that function?

I suspect there is a different "then" necessary? Maybe only run the function if it isn't dedicated?

Oh, and thanks! :)

Share this post


Link to post
Share on other sites

When I wrote that, I think I meant it like this:

SHK_DeadCivilianCount = 0;
SHK_DeadCivilianLimit = 10;
SHK_fnc_deadCivilians = {
 if (SOMEOTHERVAR && isserver) then {
   private "_m";
   _m = createMarker [format ["marker_deadcivilian_%1",SHK_DeadCivilianCount],getpos _this];
   _m setMarkerShape "ICON";
   _m setMarkerType "Dot";
   _m setMarkerColor "ColorWhite";
 };
 if !isdedicated then {
   hintsilent format ["Civilians dead: %1",_this];
   if (_this >= SHK_DeadCivilianLimit) then {
     player sidechat "mission end"; // whatever
   };
 };
};
if isserver then {
 {
   if (side _x == Civilian && _x iskindof "Man") then {
     _x addEventHandler ["killed", {
       SHK_DeadCivilianCount = SHK_DeadCivilianCount + 1;
       publicvariable "SHK_DeadCivilianCount";
       SHK_DeadCivilianCount call SHK_fnc_deadCivilians;
     }];
   };
 } foreach allunits;
} else {
 "SHK_DeadCivilianCount" addpublicvariableeventhandler { (_this select 1) call SHK_fnc_deadCivilians };
};

Edited by Shuko

Share this post


Link to post
Share on other sites

Hi Shk, where it has exceeded the kill limit , I have put in there Endmission "END1" but I would like to pause the end so they can see the side chat message first , have tried Sleep 15 but that does not work.

How can I hold off endmission to allow them to read the message that they killed to many Civis?

Many thanks

Share this post


Link to post
Share on other sites

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

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

test mission

Share this post


Link to post
Share on other sites

Hi Shk,

It might be me , but when i try this with the Ambient Civilain Module it does not work ?

If I place Civilians on the map then it works fine.

Do i need to do anything to get it to work with the Ambient Civi Module ?

Share this post


Link to post
Share on other sites

The code above was only meant for missions where units were placed in editor.

See what it does when you add this to init.sqf:

[] spawn {
 waituntil {!isnil "BIS_alice_mainscope"};
 waituntil {!isnil "bis_fnc_variablespaceadd"};
 [bIS_alice_mainscope,"ALICE_civilianinit",[{_this addEventHandler ["killed", {SHK_DeadCivilianCount = SHK_DeadCivilianCount + 1;publicvariable "SHK_DeadCivilianCount";if !isdedicated then {SHK_DeadCivilianCount call SHK_fnc_deadCivilians;};}];}]] call bis_fnc_variablespaceadd;
};

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  

×