Jump to content

Recommended Posts

Is it possible to detect if a player has damaged a unit but another unit has killed that unit (kill assist)?

I am using a Killed event handler for the unit that is killed & trying to combine that with a HitPart event handler but I can't get my head around the logic.

 

in HitPart EH:

playerShooting = (player isEqualTo _shooter);

unitShot = _target;

 

in Killed EH:

if (playerShooting) //Obviously player is not the shooter when the unit is killed
then
{
	if ((_killed isEqualTo unitShot) && !(vehicle player isEqualTo _killer))
	then
	{....blah blah Kill Assist};
};
			

also tried to use ((damage _target) < 1), but this is not true when _target is killed.  Is there a way to check if the player dealt the damage?

Share this post


Link to post
Share on other sites

You can ind all sources that damaged (hurt) the unit:
unitShot  setVariable ["killerFeed",[]];
unitShot  addEventHandler ["HandleDamage", {
  params ["_unit", "_selection", "_damage", "_source", "_projectile", "_hitIndex", "_instigator", "_hitPoint"];
  (_unit getVariable "killerFeed") pushBackUnique _source;
  _damage

}];

 

Not tested. Try also with _instigator

  • Like 3

Share this post


Link to post
Share on other sites
17 hours ago, pierremgi said:

You can ind all sources that damaged (hurt) the unit:
unitShot  setVariable ["killerFeed",[]];
unitShot  addEventHandler ["HandleDamage", {
  params ["_unit", "_selection", "_damage", "_source", "_projectile", "_hitIndex", "_instigator", "_hitPoint"];
  (_unit getVariable "killerFeed") pushBackUnique _source;
  _damage

}];

 

Not tested. Try also with _instigator

How do I use this script?

Share this post


Link to post
Share on other sites

Thank you for replying.

If I understand correctly, this should index (using pushBackUnique) the units that damage another unit into an array so I can check that array to see if a unit is in it? e.g. if (player in killerFeed).

For some reason I'm getting an error "Invalid number in expression" which points to '_source'.  I have tried '_instigator' as you suggested but as they are the same thing, no joy.  Am I right to be running this inside my HitPart EH? Trying to pass '_target' variable through scripts as a global variable is proving difficult, assuming because there is no value until the HitPart EH has fired.

 

 

Share this post


Link to post
Share on other sites

That works for me.

Tested with a group in SP preview. Just run this code in debug console (or a trigger set to true as condition):

{
  _x  setVariable ["killerFeed",[]];
  _x  addEventHandler ["HandleDamage", {
    params ["_unit", "_selection", "_damage", "_source", "_projectile", "_hitIndex", "_instigator", "_hitPoint"];
    (_unit getVariable "killerFeed") pushBackUnique _instigator;
    _damage
  }]
} forEach allUnits;

Then, shoot at any unit's legs. Then, point at this unit and in watch lines of debug console test: cursorObject getVariable "killerfeed"  : the result is an array is the name of the player inside.

 

So, if you want to use this array, you JUST need to check the variable on corpse (when unit die)

example:

addMissionEventHandler ["entityKilled", {
  params ["_killed", "_killer", "_instigator"];
  if (isNull _instigator) then {_instigator = UAVControl vehicle _killer select 0};
  if (isNull _instigator) then {_instigator = _killer};
  private _helpers = (_killed getVariable ["killerFeed",[]]) - [_instigator,objNull];
  _helpers = if (_helpers isEqualTo []) then [{""},{format ["helpers: %1", _helpers apply {name _x}] }];
  private _txt = formatText ["Killed By %1%2%3", name _instigator,lineBreak,_helpers];
  hint _txt
}];

 

  • Thanks 1

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

×