Jump to content
redarmy

tank and man harmony?

Recommended Posts

I cant ever seem to create a mission with infantry threading anywhere near friendly tanks without pancaked results.

Is there a script or init command out there to disable damage from one unit to another,disable friendly fire? Or anything that will better my infantry and armour rolling side by side without accidents wether they are in safe or combat mode?

Share this post


Link to post
Share on other sites

You could probably use a handleDamage Eventhandler on your infantry and filter out any damage caused by friendly tanks.

Either that, or some dark-magic invovling "EpeContact"-Eventhandlers.

Share this post


Link to post
Share on other sites

This will stop units taking damage from hit and runs. They'll get knocked over and go into ragdoll, but won't be hurt.

{
	_damageEH = _x addEventHandler [
		"HandleDamage",
		{
			private ["_damage", "_source"];
			_damage = _this select 2;
			_source = _this select 4;

			if (_source == "") then {0} else {_damage};
		}
	];

} forEach myUnitArray;

The "" damage type also includes falling damage, so they'll be immune to that too.

Share this post


Link to post
Share on other sites
I cant ever seem to create a mission with infantry threading anywhere near friendly tanks without pancaked results.

Is there a script or init command out there to disable damage from one unit to another,disable friendly fire? Or anything that will better my infantry and armour rolling side by side without accidents wether they are in safe or combat mode?

It's not really acceptable is it? Still no proper AI love.

Share this post


Link to post
Share on other sites

I was testing the latest ALiVE version last week and called in for supplies/reinforcements. AI commander creates a vehicle convoy and sends to my location (2 HEMMTT trucks with a fire team in each). Upon arrival, both teams disembark and the trucks attempt to turn around and RTB (all on paved roads btw). Trucks end up running over 7 of the 8 units in the fire teams before heading back to base.

I laughed.. I cried... :p

Share this post


Link to post
Share on other sites
It's not really acceptable is it? Still no proper AI love.

I forgive BIS.I really do.

Maybe if i was an arma2 player/ofp. I wouldnt have any patience left;)

---------- Post added at 05:38 ---------- Previous post was at 05:36 ----------

I was testing the latest ALiVE version last week and called in for supplies/reinforcements. AI commander creates a vehicle convoy and sends to my location (2 HEMMTT trucks with a fire team in each). Upon arrival, both teams disembark and the trucks attempt to turn around and RTB (all on paved roads btw). Trucks end up running over 7 of the 8 units in the fire teams before heading back to base.

I laughed.. I cried... :p

Hahaha "we got a man...ehhh team down" trucks/tanks dont only "accidently" flatten our guys.I feel like they intentionally aim for them....and me.

---------- Post added at 05:41 ---------- Previous post was at 05:38 ----------

This will stop units taking damage from hit and runs. They'll get knocked over and go into ragdoll, but won't be hurt.

{
	_damageEH = _x addEventHandler [
		"HandleDamage",
		{
			private ["_damage", "_source"];
			_damage = _this select 2;
			_source = _this select 4;

			if (_source == "") then {0} else {_damage};
		}
	];

} forEach myUnitArray;

The "" damage type also includes falling damage, so they'll be immune to that too.

That will work nicely,thank you 2nd ranger.

Foreach myunitarray...thats the name of group? so ForEach group1 for example.

Also does this work in units init,or should it be in SQF INIT?

Thanks mate

Share this post


Link to post
Share on other sites

Yes the myUnitArray could be the group your are wanting this to target, and this would need to be an sqf call, or depending on how your mission is working this particular situation, you could put it in the init.sqf.

Share this post


Link to post
Share on other sites
Yes the myUnitArray could be the group your are wanting this to target, and this would need to be an sqf call, or depending on how your mission is working this particular situation, you could put it in the init.sqf.

I see.

That should be just what i need.

How do i modify it for all units of a faction/all factions?

something like foreach allunits?

Share this post


Link to post
Share on other sites

Yeah. Damn AI drivers. For all units, including spawned later and to filter out enemy, so you still can ram them, that would be something like:

sleep 1;

_ehadded = [];

while {true} do
{
	{		
	_ehadded pushBack _x;

	_x addEventHandler ["HandleDamage",
		{
		_unit = _this select 0;
		_damage = _this select 2;
		_source = _this select 3;
		_proj = _this select 4;

		if ((side _source) getFriend (side _unit) < 0.6) exitWith {_damage};

		if (_proj == "") then {0} else {_damage};
		}]
	}
foreach (allUnits - _ehadded);

sleep 15
};

Hmm. Could be nice addon too. I must create one and test it in HWS. Only there is strange glitch, when unit is spawned via script under loading screen and just then added to the array, later it's refference my change (from something like BIS_fnc_setObjectVar_object1 into usual like R Bravo 4-2:2), thus not recognized as contained in the array, so every unit in some circumstances may get EH twice. setVariable method of marking units having EH may be used instead of array, but it's probably worse regarding performance. (about that) In most cases friendliness condition could be used even out of EH, to avoid checking it each time unit takes damage, just enemies wouldn't get EH. But it will be not sufficient, if friendliness changes on the fly and will be unfair, as enemies still will be rammed to death by own forces.

Edited by Rydygier

Share this post


Link to post
Share on other sites

Expanded 2nd Ranger's snippet into such code:

sleep 1;

_ehadded = [];
RYD_LI_Run = true;
RYD_LI_Cycle = true;
RYD_LI_Remove = false;

while {RYD_LI_Run} do
{
	{		
	_ehadded pushBack _x;

	_ix = _x addEventHandler ["HandleDamage",
		{
		_unit = _this select 0;
		_damage = _this select 2;
		_source = _this select 3;
		_proj = _this select 4;

		if (isNull _source) exitWith {0};
		if (_unit == _source) exitWith {_damage};
		if ((side _source) getFriend (side _unit) < 0.6) exitWith {_damage};

		if (_proj == "") then {0} else {_damage};
		}];

	_x setVariable ["RYD_LI_EH",_ix];
	diag_log format ["unit: %1",_x];
	}
foreach (allUnits - _ehadded);

RYD_LI_Cycle = false;
sleep 5;
RYD_LI_Cycle = true;
};

if (RYD_LI_Remove) then
{
	{
	switch (true) do
		{
		case (isNil {_x}) : {_ehadded set [_foreachIndex,0]};
		case not ((typeName _x) in [(typeName objNull)]) : {_ehadded set [_foreachIndex,0]};
		case (isNull _x) : {_ehadded set [_foreachIndex,0]};
		}
	}
foreach _ehadded;

_ehadded = _ehadded - [0];

	{
	_ix = _x getVariable "RYD_LI_EH";

	if not (isNil "_ix") then
		{
		_x removeEventHandler ["HandleDamage",_ix]
		}
	}
foreach _ehadded
};

and packed into addon, if anyone interested:

Liability Insurance 1.0

(CBA required, it's testing version for now)

- units rammed by allied vehicle get no damage;

- vehicles still may ram to death enemies;

- unit still will get damage from falls.

Share this post


Link to post
Share on other sites

Your a gentleman Rydygier.

essential addon.Most overlooked blunder by BIS fixed today.

You have saved me and many others countless headaches and micro managing!

Sincere thanks for making the effort here.

EDIT:

Love the addon name;)

Share this post


Link to post
Share on other sites

You're welcome. :) Basic idea was not mine though.

Share this post


Link to post
Share on other sites

Since you're using CBA anyway, you could optimize that quite a bit by using init_eventhandlers for every object (or atleast every "Man") instead of running that allUnits-loop.

Share this post


Link to post
Share on other sites

Thanks, indeed. Just never studied CBA features deeply, so wasn't awared about that possibility, so code snippet "how to" would save me some time. Anyway, I'll try it in the next version.

Share this post


Link to post
Share on other sites

Maybe something like this:

class CfgPatches 
{
class RYD_LI 
{
	units[] = {};
	weapons[] = {};
	requiredAddons[] = {"Extended_EventHandlers"};
	requiredVersion = 0.1;
};
};

class Extended_PostInit_EventHandlers
{
RYD_LI_Post_Init = "RYD_LI_Post_Init_Var = [] execVM '\RYD_LI\LIInit.sqf'";
};

class Extended_Init_EventHandlers {
class Man {
	RYD_LI_Init_Man = "(_this select 0) call RYD_LI_Init;";
};
};

RYD_LI_Init would then be the function that adds the HandleDamage eventhandler.

Share this post


Link to post
Share on other sites

CAManbase I suppose, we don't want ehs for animals. If I define RYD_LI_Init in the LIINit.sqf, then this doesn't work, like init eh for man is executed before RYD_LI_init is defined. Maybe if there would be call compile preprocessfile instead of execVM? But it worked that way:

Config.cpp:

class CfgPatches  
{ 
class RYD_LI  
	{ 
	units[] = {}; 
	weapons[] = {}; 
	requiredAddons[] = {"Extended_EventHandlers"}; 
	requiredVersion = 0.1; 
	}; 
}; 

class CfgFunctions
{
class RYD
	{
	class AI
		{
		class Insurance 
			{
			file = "\RYD_LI\LIInit.sqf";
			preInit = 1;
			postInit = 0;
			recompile = 0;
			ext = ".sqf";
			};
		};
	};	
};

class Extended_Init_EventHandlers 
{ 
class CAManBase 
   		{ 
	RYD_LI_Init_Man = "(_this select 0) call RYD_LI_Init;"; 
	}; 
}; 

LLInit.sqf:

RYD_LI_Init = 
{
_this addEventHandler ["HandleDamage",
	{
	_unit = _this select 0;
	_damage = _this select 2;
	_source = _this select 3;
	_proj = _this select 4;

	if (isNull _source) exitWith {0};
	if (_unit == _source) exitWith {_damage};
	if ((side _source) getFriend (side _unit) < 0.6) exitWith {_damage};

	if (_proj == "") then {0} else {_damage};
	}];
};

But with such approach one thing, I would like to add, seems not easy to figure out - removing EH from dead bodies. In the loop way I could add such thing easy. But here? I suppose, only via second EH, "Killed", that will remove "HandleDamage" EH and will remove itself. Still, every unit will get two EHs in such case. So, after all, not sure, which way is better for performance. Unless... a check for "" selection, if new, summed damage is >= 1, if so, remove the EH from within. Hmm.

EDIT: Seems, it works. Config as above, while new LIInit.sqf is that:

RYD_LI_Init = 
{
_ix = _this addEventHandler ["HandleDamage",
	{
	_unit = _this select 0;
	_sel = _this select 1;
	_damage = _this select 2;
	_source = _this select 3;
	_proj = _this select 4;

	if (isNull _source) exitWith {0};

	_totalDam = 0;

	if (_sel isEqualTo "") then
		{
		_totalDam = (damage _unit) + _damage
		};

	if (_unit == _source) exitWith 
		{
		if not (_totalDam < 1) then
			{
			_ix = _unit getVariable "RYD_LI_MyEH";
			if not (isNil {_ix}) then
				{
				_unit removeEventHandler ["HandleDamage",_ix]
				}
			};

		_damage
		};

	if ((side _source) getFriend (side _unit) < 0.6) exitWith 
		{
		if not (_totalDam < 1) then
			{
			_ix = _unit getVariable "RYD_LI_MyEH";
			if not (isNil {_ix}) then
				{
				_unit removeEventHandler ["HandleDamage",_ix]
				}
			};

		_damage
		};

	if (_proj == "") then {0} else 
		{
		if not (_totalDam < 1) then
			{
			_ix = _unit getVariable "RYD_LI_MyEH";
			if not (isNil {_ix}) then
				{
				_unit removeEventHandler ["HandleDamage",_ix]
				}
			};

		_damage
		};
	}];

_this setVariable ["RYD_LI_MyEH",_ix]
};

So, Liability Insurance 1.1. :)

Edited by Rydygier

Share this post


Link to post
Share on other sites

Thank you Rydygier. Great idea to all involved... ai driving is tragic...

Any chance of a A3 smart cam add on with the pp effects from war stories...

I like watching the ai fight it out some days. .. and a configurable smart cam like war stories would be awesome!

Share this post


Link to post
Share on other sites
Any chance of a A3 smart cam add on with the pp effects from war stories...

Well, it was an addon in A2, so if there is an interest, I can think about addon for A3 too. But let's keep on the topic here, about smart cam we can talk more meanwhile in the HWS thread. :)

Share this post


Link to post
Share on other sites
Well, it was an addon in A2, so if there is an interest, I can think about addon for A3 too. But let's keep on the topic here, about smart cam we can talk more meanwhile in the HWS thread. :)

sounds great... downloading liability insurance now...

Share this post


Link to post
Share on other sites
I forgive BIS.I really do.

Maybe if i was an arma2 player/ofp. I wouldnt have any patience left;)

Just imagine if you had to suffer through Arma1. Basically arma2 pre alpha hahaha.

Share this post


Link to post
Share on other sites
Just imagine if you had to suffer through Arma1. Basically arma2 pre alpha hahaha.

Hahaha those days i was marvelling at the "Realism" of console battlefield games.

Share this post


Link to post
Share on other sites

Rydygier,

Iv been testing this vigoursly,Its mostly working.

However sometimes AI are still found dead,run over by vehicle.

Iv tessted with a "stampede" type of setting(lots of BMP-2s,waypoints full spead combat straight for friendly infantry position.

I have noticed head on collisions wont kill or harm infantry.

But still saw them dead.Tested on myself trying to get killed,sure enough running in front of armour just pushed me aside.I found that by timing it rite and impacting the side of the vehicle,i took damage and died.

Im guessing ai did too.

Not sure if your aware just had to point it out.

As is however...in ten stampede tests of hundreds of AI,with tonnes of armour on collision course with them,experienced just one KIA.

Working great so far.

Share this post


Link to post
Share on other sites

Quick guess would be, impacting the side of vehicle may be recognized as damage self-inflicted, like falls, then it could pass through event handler, like any damage, where source == damaged unit. If so, then we could either make units invulnerable also for falls, what IMO sucks a bit, or accept status quo. But I have to run some tests to know, if that's the case.

Edited by Rydygier

Share this post


Link to post
Share on other sites
impacting the side of vehicle may be recognized as damage self-inflicted, like falls, then it could pass through evnet handler

Probably - in a mission I'm working on, several AI are ejected from a Hellcat when it lands. One of the AI always gets stuck running against the heli's rocket pod, and when the heli takes off, that AI is always injured. I used a handleDamage EH to try and prevent it, and discovered that the source of the damage in this particular case can be caused by any of the following: the helicopter itself, the helicopter pilot, objNull, "", and some unknown source which sometimes slips through the EH. After what you said, I'll add the unit itself to the blacklist and see if that works.

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

×