Jump to content
Sign in to follow this  
mr_shadow

Reason of death

Recommended Posts

Hello, is that possible theoretically to do something like in dayz about the reason of death. Like checking if person was shot, ran over or died because of himself?is that also to make one of the reasons getting the variable? I guess it should be something with event handlers?

Share this post


Link to post
Share on other sites

Correct. You could use a "killed" EH or – if you want more precise information – a "handleDamage" Eventhandler. The latter can be a bit complex to handle but the basic principle is the same.

The EH has to save the last cause of harm into an object-variable on the corpse and then you can later use that variable when you check on the corpse.

Share this post


Link to post
Share on other sites

I'm sorry I was incorrect, one of the variables in my mission is bleeding, so how can I exactle get the varriable "bleeding" if it's more then 100? Do I have first to check for this variable and then start EH which will have the text message for the guy who pressed on action.(check body)

Share this post


Link to post
Share on other sites

Bleeding surely means "setDamage", so just include a check to see if it's fatal when you apply the bleeding-damage, then save that as reason of death.

That part should be rather simple really.

Share this post


Link to post
Share on other sites

Your PM box is full, so I'll write it here:

Only if you insist. Asking me nicely normally also does the trick ;)

I can take a closer look at it when I get home. Anyway, what do you mean with "3 event handlers" ?

Share this post


Link to post
Share on other sites

Ok, here goes:

 - removed - 
(code is in the next post)

This is the "realistic" variant, it will only give you information that makes sense. It does tell you what the person died from, but you won't magically know WHO did it.

That however, can easily be changed.

Furthermore, if you have any script (bleeding for example) that uses setDamage, you can provide the necessary data for the script manually.

Either this way (uses placeholders) to let the script generate the message.

this setVariable["killdata", ["name of the body", "classname of the killer", "name of the killer", int(0-3), int(damage value),"bullet classname",date], true];

int(0-3) represents the bodypart that got hit.

0 = head

1 = body

2 = arms

3 = legs

or you can provide a custom message:

this setVariable["killdata", ["This poor guy was bored to death.",date], true];

ps.: You will have to re-assign the eventhandlers when a person respawns.

Edited by Tajin

Share this post


Link to post
Share on other sites

Updated it slightly.

Put the following code in a scriptfile and execVM it from your init.:

allowForensics_default = false;

fnc_handleDeath = {
private ["_trg","_eh"];
_trg = _this select 0;
_eh = player getVariable["forensics_HandleDamage", -1];
_trg removeEventHandler ["HandleDamage",_eh];
if (local _trg) then {
	_trg setVariable["killdata", _trg getVariable["killdata",0], true];
	[_trg,"fnc_addCorpseAction",true,true] call BIS_fnc_MP;
};
};

fnc_HD = {
private ["_trg","_sel","_dmg","_src","_mun","_hitnum","_head","_body","_hands","_legs","_parts","_names","_i","_s","_x","_forEachIndex","_part","_type","_killdata"];
_trg = _this select 0;
_sel = _this select 1;
_dmg = _this select 2;
_src = _this select 3;
_mun = _this select 4;

_hitnum = _trg getVariable["HD_hitnum",0];

if (_sel == "head" && isNull _src) then {
	_hitnum = _hitnum + 1;
	_trg setVariable["HD_hitnum", _hitnum];
} else {
	if (_sel != "") then {
		_trg setVariable[format ["HD_%1_%2",_hitnum,_sel], _dmg];

		if (_sel == "legs") then {
			_head = _trg getVariable[format["HD_%1_head",_hitnum],0];
			_trg setVariable[format["HD_%1_head",_hitnum],nil];

			_body = _trg getVariable[format["HD_%1_body",_hitnum],0];
			_trg setVariable[format["HD_%1_body",_hitnum],nil];

			_hands = _trg getVariable[format["HD_%1_hands",_hitnum],0];
			_trg setVariable[format["HD_%1_hands",_hitnum],nil];

			_legs = _dmg;

			_parts = [_head,_body,_hands,_legs];
			_i = 0;
			_s = -1;
			{ if (_x > _i) then {_i = _x; _s = _forEachIndex; }; } forEach _parts;
			_part = _names select _s;

			if (_trg == _src) then {
				_type = "self";
			} else {
				_type = typeOf vehicle _src;
			};
			_killdata = [name _trg, _type, name _src,_s,_i,_mun,date];
			_trg setVariable["killdata",_killdata];
		};
	};
};
_dmg
};

fnc_addCorpseAction = {
_this addAction [
	"Inspect corpse.",
	{
		private ["_trg","_killdata","_text","_trgname","_killertype","_killername","_part","_partnames","_dmg","_mun","_date","_s","_caliber","_speed","_exp","_ctext","_diff"];
		_trg = _this select 0;
		_killdata = _trg getVariable ["killdata",0];
		if (typeName _killdata != "ARRAY") exitWith {};

		_text = "";


		if (count _killdata == 2) then {
			_text = _killdata select 0;
			_date = _killdata select 1;
		} else {
			_trgname = _killdata select 0;
			_killertype = _killdata select 1;
			_killername = _killdata select 2;
			_s = _killdata select 3;

			_dmg = _killdata select 4;
			_mun = _killdata select 5;
			_date = _killdata select 6;

			_partnames = ["head","body","arms","legs"];
			_part = _partnames select _s;

			if (_mun == "") then {
				if (_killertype != "self") then {
					_text = format ["%1 %2 was killed by unknown means. His %3 %4 gravely injured.", rank _trg, _trgname, _part, ["is","is","are","are"] select _s];
				} else {
					_text = format ["%1 %2 probably fell to death. His %3 %4 gravely injured.", rank _trg, _trgname, _part, ["is","is","are","are"] select _s];
				};
			} else {
				_caliber = getNumber( configfile >> "CfgAmmo" >> _mun >> "caliber");
				_speed = getNumber( configfile >> "CfgAmmo" >> _mun >> "typicalSpeed");
				_exp = getNumber( configfile >> "CfgAmmo" >> _mun >> "explosive");

				if (_exp > 0) then {
					_text = format ["%1 %2 was killed by an explosion. His %3 %4 gravely injured.", rank _trg, _trgname, _part, ["is","is","are","are"] select _s]
				} else {
					_ctext = "";
					if (_caliber < 1) then { _ctext = "a small caliber bullet";
					} else { if (_caliber < 2 ) then { _ctext = "a bullet";
						} else { if (_caliber < 4) then { _ctext = "a large caliber bullet";
							} else { _ctext = "a very large bullet";
							};
						};
					};
					_text = format ["%1 %2 got killed by %5. His %3 %4 gravely injured.", rank _trg, _trgname, _part, ["is","is","are","are"] select _s, _ctext];
				};
			};
		};

		_diff = ((dateToNumber date) - (dateToNumber _date)) * 1000000;
		if (_diff < 20) then {_text = _text + " The body is still warm.";
		} else { if (_diff < 57) then {_text = _text + " He has only been dead for a few minutes.";
			} else { if (_diff < 171) then {_text = _text + " He has been dead for roughly an hour.";
				} else { if (_diff < 2739) then {_text = _text + " He has been dead for a while.";
					} else { _text = _text + " He has been dead for a long time.";
					};
				};
			};
		};

		hintC _text;
	},
	"",
	-5,
	false,
	false,
	"",
	'
		_this getVariable ["allowForensics", allowForensics_default]
	'
];
};

fnc_initForensics = {
_unit = _this select 0;
waitUntil {sleep 1; alive _unit};

_eh_HD		= _unit getVariable ["forensics_HandleDamage", -1];
_eh_killed	= _unit getVariable ["forensics_Killed", -1];
_eh_respawn	= _unit getVariable ["forensics_Respawn", -1];
if (_eh_HD > -1) then { _unit removeEventHandler["HandleDamage",_eh_HD]; };
if (_eh_killed > -1) then { _unit removeEventHandler["Killed",_eh_HD]; };
if (_eh_respawn > -1) then { _unit removeEventHandler["Respawn",_eh_HD]; };

_unit setVariable["forensics_HandleDamage", _unit addEventHandler["HandleDamage",{_this call fnc_HD;}] ];
_unit setVariable["forensics_Killed", _unit addEventHandler["Killed",{_this call fnc_handleDeath;}] ];
_unit setVariable["forensics_Respawn", _unit addEventHandler ["Respawn", {
	[] spawn {
		sleep 1;
		(_this select 0) setVariable["forensics_HandleDamage", (_this select 0) addEventHandler["HandleDamage",{_this call fnc_HD;}] ];
	};
}] ];		
};

[player] spawn fnc_initForensics;

Initalization for the players is included this time.

Edited by Tajin

Share this post


Link to post
Share on other sites
Sounds like you're using a respawnTemplate with "respawnOnStart = 1", is that so?
Could you please change it to player globalchat? For the player who pressed.

Simply change "hintC" to "player globalChat". Though I think "hintC" makes more sense here.

No, im not using it, the globalchat is not saying any info as well.

I've added the execvm and 2 eventhandlers to init

Edited by mr_shadow

Share this post


Link to post
Share on other sites
I've added the execvm and 2 eventhandlers to init

Read above --->

Updated it slightly.

Put the following code in a scriptfile and execVM it from your init.

ps.: I've now added the variable "allowForensics_default".

When that variable is true, everyone can check bodies.

If it is false, only someone with the skill can do it.

The "skill" in this case is just an objectVariable.

---> player setVariable ["allowForensics",true];

Share this post


Link to post
Share on other sites
Updated it slightly.

Put the following code in a scriptfile and execVM it from your init.

Thats what i meant.

For now it works only for AI, which have this 2 EHs.

It appears for players bodies, but doesnt work.

Share this post


Link to post
Share on other sites

Then some other script (probably the injury system) is messing something up. That is beyond my control.

Share this post


Link to post
Share on other sites

Can you test it then on dedicated to be sure that its so?

Or just kill yourself by the AI and the press inspect? It doesnt work.

We already found out that is not about the med system.

Edited by mr_shadow

Share this post


Link to post
Share on other sites

The script doesn't even differentiate between AI and players.

Copy it again from my post, and do everything as described there.

Maybe even try it in a clean mission.

That worked for me.

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  

×