Jump to content
Sign in to follow this  
Roach_

How to make How to make playable units invincible to friendly AI fire?

Recommended Posts

I'm having a problem here with a mission and the AI, specially the "friendly" AI. More than once they'll disregard the fact that you're in front of them when they engage the enemy. I've tried an eventhandler script but it seems to only work on non-playable units. Haven't been able to find anything all day, so here's what I've got so far:

EH_NoTK = {
   _source = _this select 3;
   if (side _source == EAST) then 
   {
   _this
   }
   else
   {
   0
   };
};  

and this is the unit's init line:

this addEventHandler ["HandleDamage", {_this call EH_NoTK}];

Any help would be very appreciated since most of the time in this mission you get killed by fratricide and I really suck at scripting.

Thanks in advance.

Edited by MarcGF
Title mistake

Share this post


Link to post
Share on other sites

Try this code (if east side units are enemy):

EH_NoTK = {
_source = _this select 3;

if ((side _source) == east) then {_this select 2} else {false};
};

Share this post


Link to post
Share on other sites
Try this code (if east side units are enemy):

EH_NoTK = {
_source = _this select 3;

if ((side _source) == east) then {_this select 2} else {false};
};

Nope, same as always, as long as it's the player or a playable unit it has no effect whatsoever.

Appreciate it, nonetheless.

Share this post


Link to post
Share on other sites

Should work in theory. (untested)

unit addEventHandler ["HandleDamage",
{
if (side (_this select 3) != side (_this select 0)) then //if not the same side then set damage
{
	(_this select 0) setDamage ((damage (_this select 0)) - (_this select 2));
};

0;
}];

Share this post


Link to post
Share on other sites
Should work in theory. (untested)

unit addEventHandler ["HandleDamage",
{
if (side (_this select 3) != side (_this select 0)) then //if not the same side then set damage
{
	(_this select 0) setDamage ((damage (_this select 0)) - (_this select 2));
};

0;
}];

Thanks man, will try it right away.

---------- Post added at 22:59 ---------- Previous post was at 22:43 ----------

Thanks man, will try it right away.

No luck.

Share this post


Link to post
Share on other sites

player addEventHandler ["HandleDamage",{
if (side (_this select 0) == side (_this select 3)) then {
	false;
};
}];  

---------- Post added at 23:14 ---------- Previous post was at 22:57 ----------

Integrated into your function:

// this addEventHandler ["HandleDamage", {_this call EH_NoTK}];

EH_NoTK = {
_unit = _this select 0;
   _source = _this select 3;
   if ((side _unit) == (side _source)) then {
	false;
   };
};  

Share this post


Link to post
Share on other sites
player addEventHandler ["HandleDamage",{
if (side (_this select 0) == side (_this select 3)) then {
	false;
};
}];  

---------- Post added at 23:14 ---------- Previous post was at 22:57 ----------

Integrated into your function:

// this addEventHandler ["HandleDamage", {_this call EH_NoTK}];

EH_NoTK = {
_unit = _this select 0;
   _source = _this select 3;
   if ((side _unit) == (side _source)) then {
	false;
   };
};  

Still doesn't seem to work.

Share this post


Link to post
Share on other sites

Hmm. Well it works in the editor for Arma3. The arguments the EH provides and the way it works hasn't changed at any point in time. I don't have Arma2 installed atm to get down to the brass tacks. I'm not sure what to say =(. Good luck.

---------- Post added at 17:10 ---------- Previous post was at 16:44 ----------

Maybe your trying to use player variable to add the EH to the player object, before the player variable has been initialized on the clients machine :confused:

waitUntil (!isNull player && {time > 0}};
player addEventHandler ["HandleDamage",{
   if (side (_this select 0) == side (_this select 3)) then {
       false;
   };
}];  

Share this post


Link to post
Share on other sites
Hmm. Well it works in the editor for Arma3. The arguments the EH provides and the way it works hasn't changed at any point in time. I don't have Arma2 installed atm to get down to the brass tacks. I'm not sure what to say =(. Good luck.

---------- Post added at 17:10 ---------- Previous post was at 16:44 ----------

Maybe your trying to use player variable to add the EH to the player object, before the player variable has been initialized on the clients machine :confused:

waitUntil (!isNull player && {time > 0}};
player addEventHandler ["HandleDamage",{
   if (side (_this select 0) == side (_this select 3)) then {
       false;
   };
}];  

It's alright man, I'm just glad people are taking their time to help me out. As for the code, how should I integrate that one into my mission, exactly?

Share this post


Link to post
Share on other sites

init.sqf

if (!isDedicated) then {
waitUntil (!isNull player && {time > 0}};
player addEventHandler ["HandleDamage",{
	if (side (_this select 0) == side (_this select 3)) then {
		false;
	};
}];  
};

Share this post


Link to post
Share on other sites
init.sqf

if (!isDedicated) then {
waitUntil (!isNull player && {time > 0}};
player addEventHandler ["HandleDamage",{
	if (side (_this select 0) == side (_this select 3)) then {
		false;
	};
}];  
};

Nothing, seems unsolvable. By the way, I should mention that this is for an SP mission, although I plan on making it MP once this is fixed.

Share this post


Link to post
Share on other sites

Try this:

if (!isDedicated) then 
{
waitUntil {!isNull player && time > 0};
player addEventHandler ["HandleDamage",{if (side (_this select 0) == side (_this select 3)) then {false;};}];
};

tested it in SP editor with a radio trigger call.

I think it had to do with the curly braces v. round braces v. no braces in certain places.

Edited by OpusFmSPol

Share this post


Link to post
Share on other sites
I think it had to do with the curly braces v. round braces v. no braces in certain places.

Ahh yes good spot on the one typo (wrong bracket) before the waitUntil. It's still nice to use lazy evaluation though. So...

if (!isDedicated) then {
waitUntil {!isNull player && {time > 0}};
player addEventHandler ["HandleDamage",{
	if (side (_this select 0) == side (_this select 3)) then {
		false;
	};
}];  
};

Edited by Iceman77

Share this post


Link to post
Share on other sites
Ahh yes good spot on the one typo (wrong bracket) before the waitUntil. It's still nice to use lazy evaluation though. So...

if (!isDedicated) then {
waitUntil {!isNull player && {time > 0}};
player addEventHandler ["HandleDamage",{
	if (side (_this select 0) == side (_this select 3)) then {
		false;
	};
}];  
};

Oh I saw it too now. Tested it, but it seems that now nothing can kill me.

Share this post


Link to post
Share on other sites

How about this?

if (!isDedicated) then 
{
   waitUntil {!isNull player && (time > 0)};
   player addEventHandler 
["HandleDamage",
	{
		_damage = _this select 2;
		if (side (_this select 0) == side (_this select 3)) then 
		{
			_damage = 0;
		};
		_damage;
	}
];  
};  

Works for me in A2 editor if you just use the following in a units init field:

this addEventHandler ["HandleDamage", {_damage = _this select 2; if (side (_this select 0) == side (_this select 3)) then {_damage = 0;};_damage;}];

Test by placing two units on map, both same side, then one of the opposing side.

Edited by panther42

Share this post


Link to post
Share on other sites
How about this?

if (!isDedicated) then 
{
   waitUntil {!isNull player && (time > 0)};
   player addEventHandler 
["HandleDamage",
	{
		_damage = _this select 2;
		if (side (_this select 0) == side (_this select 3)) then 
		{
			_damage = 0;
		};
		_damage;
	}
];  
};  

Works for me in A2 editor if you just use the following in a units init field:

this addEventHandler ["HandleDamage", {_damage = _this select 2; if (side (_this select 0) == side (_this select 3)) then {_damage = 0;};_damage;}];

Test by placing two units on map, both same side, then one of the opposing side.

Oh panther it works! Thanks man! And everyone who supported the cause thank you too.

Sincerely, much appreciated.

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  

×