Jump to content
Sign in to follow this  
iceman77

Civilian casualty cap parameter

Recommended Posts

I currently use a script that counts civ deaths and end / fail a mission when DeadCivilians == 10. I would like to create a mission parameter somehow, where I could set the casualty cap amount for civilians, before the mission begins. How would I go about doing this? I realize I have to create some parameters in the description & init. I'm just not sure how to mesh that with this script/DeadCivilians variable.

init.sqf

null=[]execVM "civilianCasualties.sqf";

civilianCasualties.sqf

// Global variable to hold the death counter.
DeadCivilians = 0;

// Server will do all the work.
if isServer then {
 // Function to update death counter.
 fnc_countCivDeaths = {
   DeadCivilians = DeadCivilians + 1;

   // Send the new value to clients.
   publicvariable "DeadCivilians";
 };

 // Add killed -eventhandler to all civilians.
 {
   if (side _x == Civilian) then {
     _x addEventhandler ["killed",fnc_countCivDeaths];
   };
 } foreach allUnits;

// Client side.
} else {
 // Function to display the death count.
 fnc_showCivDeathCount = {
   hintsilent format ["Dead Civilians: %1",DeadCivilians];
 };

 // PublicVariable eventhandler to catch the update sent by the server.
 "DeadCivilians" addPublicVariableEventHandler {call fnc_showCivDeathCount};
};

Share this post


Link to post
Share on other sites

Hi man...

Create your description.ext if you don't have one and stick this in it....

class Params {

class CivCount {	//param 0
	title = "Civilian Count";
	values[] = {0, 10, 20, 50, 100};
	texts[] = {"No Civilians", "10 Civies", "20 Civies", "50 Civies", "100 Civies"};
	default = 10;
};

[color="#FF8C00"]	class Daytime {	//param 1
	title = "Day or Night";
	values[] = {0, 1};
	texts[] = {"Daylight", "Night"};
	default = 0;
};
[/color]
};

Then in your main code or wherever...

_numcivs = (paramsArray select 0);

The second parameter Daytime is just included to show how to do another one.

Share this post


Link to post
Share on other sites

Thanks, that works nicely. How would I get the civcap script to hint what player is killing a civilian. So far, as you can see it just says "dead Civilians: #".

Share this post


Link to post
Share on other sites

If you put something like this in the fnc_countCivDeaths part...then you can add the killer to the DeadCivilians variable (make it an array) and have the hint display both the dead civilian count and the last person to kill a civilian.

_deatharray =_this select 0;      //array passed from the killed eh

_victim = _deatharray select 0;   //victim
_killer = _deatharray select 1;   //killer

....or you can add another "killed" eventhandler to the Civilians that runs another script or calls another entirely different function that does something else.

The main thing is knowing that the victim and killer are passed when the "killed" EH is fired.

---------- Post added at 05:24 PM ---------- Previous post was at 05:19 PM ----------

I hope I didn't totally confuse you!

Edited by twirly

Share this post


Link to post
Share on other sites

In case you haven't done it yourself yet, this is the implementation of twirly's first suggestion:

// Global variable to hold the death counter.
DeadCivilians = [0, objNull];

// Server will do all the work.
if (isServer) then
{
// Function to update death counter.
fnc_countCivDeaths =
{
	DeadCivilians set [0, (DeadCivilians select 0) + 1];
	DeadCivilians set [1, _this select 1]; //Store the killer

	// Send the new value to clients.
	publicvariable "DeadCivilians";
};

// Add killed -eventhandler to all civilians.
{
	if (side _x == Civilian) then
	{
		_x addEventhandler ["killed", fnc_countCivDeaths];
	};
} foreach allUnits;

// Client side.
}
else
{
// Function to display the death count.
fnc_showCivDeathCount =
{
	hintSilent format ["%1 killed a civilian\nDead Civilians: %2/%3", name (DeadCivilians select 1), DeadCivilians select 0, paramsArray select 0];
};

// PublicVariable eventhandler to catch the update sent by the server.
"DeadCivilians" addPublicVariableEventHandler {call fnc_showCivDeathCount};
};

You are also going to have to change your fail trigger condition to:

(DeadCivilians select 0) == (paramsArray select 0)

Share this post


Link to post
Share on other sites

Hey iceman 77 I would appreciate it if you could make a sample mission of the script I would love to look inside to see how it works I'm trying to do the same thing for West units as well as for civilians to end a mission I am working on thanks avibird

Share this post


Link to post
Share on other sites
In case you haven't done it yourself yet, this is the implementation of twirly's first suggestion:

// Global variable to hold the death counter.
DeadCivilians = [0, objNull];

// Server will do all the work.
if (isServer) then
{
// Function to update death counter.
fnc_countCivDeaths =
{
	DeadCivilians set [0, (DeadCivilians select 0) + 1];
	DeadCivilians set [1, _this select 1]; //Store the killer

	// Send the new value to clients.
	publicvariable "DeadCivilians";
};

// Add killed -eventhandler to all civilians.
{
	if (side _x == Civilian) then
	{
		_x addEventhandler ["killed", fnc_countCivDeaths];
	};
} foreach allUnits;

// Client side.
}
else
{
// Function to display the death count.
fnc_showCivDeathCount =
{
	hintSilent format ["%1 killed a civilian\nDead Civilians: %2/%3", name (DeadCivilians select 1), DeadCivilians select 0, paramsArray select 0];
};

// PublicVariable eventhandler to catch the update sent by the server.
"DeadCivilians" addPublicVariableEventHandler {call fnc_showCivDeathCount};
};

You are also going to have to change your fail trigger condition to:

(DeadCivilians select 0) == (paramsArray select 0)

Hey thanks deadFast!! LOL it took me some time to figure out how to set a condition along with parameters. I used a condition numcivs < DeadCivilians. As this was the only one I tried that worked.Then I had to go and set the actual parameters back one tick to work properly. In any case I'll use your way instead (DeadCivilians select 0) == (paramsArray select 0) :yay:

Also, I couldn't wrap my head around the hintsilent format % shit. Thanks a ton man!!

@AVBIRD, sure I'll make you an example. Or you could >> DOWNLOAD << Twisted fork, it has the civilian death cap parameter. You can see clearly how it's working. If you still need help then that's okay too, I can make an exclusive example mission for you.

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  

×