dematti 10 Posted May 9, 2017 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
Nicholas.Bell 11 Posted May 9, 2017 Rydygier's Liability Insurance automatically revives friendly roadkills. http://www.armaholic.com/page.php?id=27485 Share this post Link to post Share on other sites
dematti 10 Posted May 9, 2017 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
Belbo 462 Posted May 9, 2017 _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
dematti 10 Posted May 10, 2017 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
Belbo 462 Posted May 10, 2017 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
fn_Quiksilver 1636 Posted May 11, 2017 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
dematti 10 Posted May 13, 2017 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
Belbo 462 Posted May 13, 2017 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
dematti 10 Posted May 13, 2017 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 Share this post Link to post Share on other sites
fn_Quiksilver 1636 Posted May 13, 2017 First step is to move it out of the way. _unit setPos (_vehicle getRelPos [10,150]); Share this post Link to post Share on other sites