Jump to content
Sign in to follow this  
dematti

Deny Roadkill TK

Recommended Posts

Hi,

 

Driving ai are still killing teammates on foot that are crossing their path.

I have used several ai driving mods/scripts trying to solve the issue but it doesn't help.

Going for the last resort, which is to completely deny roadkill by a teammate.

 

So, I'm looking for a script that will undo damage taken by a vehicle, only when the same side is driving it.

Can someone help? Thanks.

 

Share this post


Link to post
Share on other sites

Thanks, but tried that one before, doesn't work.

 

Tried solving it but i'm stuck here:

Using a waypoint script I'm adding an EventHandler (using "hit" for now):

The idea is to replenish damage when a unit has been hit by a friendly vehicle.

{
_unit addEventHandler ["Hit",{[_this select 1,"east"] execvm "Roadkill.sqf"}]
} foreach _unitsGroup;

script:
 

_killer = _this select 0;
_side = _this  select 1;
_vehicle = vehicle _killer;

if ((_vehicle isKindOf "LandVehicle") && (_side == "west") && (side _killer == west)) then {
    _this setdamage 0;
};
if ((_vehicle isKindOf "LandVehicle") && (_side == "resistance") && (side _killer == resistance)) then {
    _this setdamage 0;
};
if ((_vehicle isKindOf "LandVehicle") && (_side == "resistance") && (side _killer == west)) then {
    _this setdamage 0;
};
if ((_vehicle isKindOf "LandVehicle") && (_side == "west") && (side _killer == resistance)) then {
    _this setdamage 0;
};
if ((_vehicle isKindOf "LandVehicle") && (_side == "east") && (side _killer == east)) then {
    _this setdamage 0;
};
exit

I was hoping this would stop AI from teamkilling with vehicles.

But I get following error on line "_this setdamage 0;" : "array, expected object"

Can someone see what I'm doing wrong?

Share this post


Link to post
Share on other sites

_this is an array.

The hit eventhandler has the following entries in _this:

params ["_unit","_causedBy","_damage","_instigator"];

But as the biki says: in case of collision _causedBy isEqualTo _unit.

So try:

//defining the function for the HIT-Eventhandler:
fnc_roadkill = {
  //getting the params from the eventhandler:
	params ["_unit","_causedBy","_damage","_instigator"];
  //checking if _unit is the one who caused the damage (i.e. it's a collision):
	if ( _causedBy isEqualTo _unit ) exitWith {
      //reducing the damage of the unit by the amount of damage taken in the collision:
		_unit setDamage ((damage _unit)-_damage);
	};
};
//adding the eventhandler to all units in the array _unitsGroup (can't be a GROUP!):
{
	_x addEventhandler ["HIT",{
      //_this contains the params given to the code, so we just take _this and let fnc_roadkill do the rest:
		_this call fnc_roadkill;
	}];
} forEach _unitsGroup;

I'm fairly certain though that this won't work if the unit dies instantly from the crash. A HANDLEDAMAGE-EventHandler would be better suited for that.

Share this post


Link to post
Share on other sites

Great! Thanks, EH "hit" was only used for testing. I will change to "Handledamage" as suggested.

I did have the following questions about "Handledamage":
Does this mean I have to load the EH only once as im spawning each unit multiple times?

Quote

 

"HandleDamage" will continue to trigger even if the unit is already dead.

"HandleDamage" is persistent. If you add it to the player object, it will continue to exist after player respawned.

 

Share this post


Link to post
Share on other sites

No, you technically have to create the eventhandler on every unit you spawn.

But I can tell you directly: It doesn't work.

Share this post


Link to post
Share on other sites

Performance-wise its not worth it to do this

 

on a small scale, inside a Hit/HandleDamage event you can displace the affected unit, just move it to the side

Share this post


Link to post
Share on other sites

Hi,

 

Thanks for the suggestions.

I got both scripts, Eh "HIT" and "HANDLEDAMAGE" to work, but it seems that BOTH are not always launched on fast impact.

The "setdamage 0" part is not launching on time,  You can notice that when the soldier loses/drops its weapon (and ragdoll starts).

When that happens it is already too late and "settdamage" doesn't affect the unit anymore.

 

Is there something I can do to make the unit "unconscious" instead of immediately "ragdoll" dead?

If I need to take a different approach, any suggestions are welcome, the goal is to deny roadkill by ai teammates.

Thanks

 

Share this post


Link to post
Share on other sites

If you're using ace with revive and preventInstaDeath enabled you could simply put this in the evh:

_unit setDamage 0;	
if ( (missionnamespace getVariable ["ace_medical_level",2]) > 1 ) then {
	[_unit,_unit] call ACE_medical_fnc_treatmentAdvanced_fullHealLocal;
} else {
	_unit setVariable ["ace_medical_pain", 0, true];
	_unit setVariable ["ace_medical_morphine", 0, true];
	
	_unit setVariable ["ace_medical_bloodVolume", 100, true];
	
	_unit setVariable ["ace_medical_bodyPartStatus", [0,0,0,0,0,0], true];

	_unit setHitPointDamage ["hitHead", 0];
	_unit setHitPointDamage ["hitBody", 0];
	_unit setHitPointDamage ["hitArms", 0];
	_unit setHitPointDamage ["hitLegs", 0];

	[_unit,false] call ACE_medical_fnc_setUnconscious;
};

That'll revive the player immediately. Mind you, that would mean you'd be able to revive the player by driving him over.

Share this post


Link to post
Share on other sites

Ok, almost there! It works, but the units starts ending up in the middle of the car, repeatedly triggering the event until death.

Just need to add that one line which moves the unit a bit.

This one should be solvable :smile_o:

 

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  

×