Jump to content
redarmy

Handle damage from friendly side

Recommended Posts

Greetings guys

 

Im trying to figure out a way through Handle damage to make it so that friendly units in my squad do no damage when the shoot me.Its for SP and in this instance i the player have no vest,no revive system and no respawn.

 

Its a persistent mission made across Altis with saving enabled however its basically one shot one kill with the way i have equipped units including myself.Play testing has made me realise that my own AI are more of a threat to me than zombies or enemy.

 

Does anyone know the correct command to enter in the player init to disable friendly fire to return the damage to 0?

 

I took a look at it but cant make much sense from it all but can tell its possible to achieve.

 

Many thanks

Share this post


Link to post
Share on other sites
Hi redarmy

 

The way I'd do it would be to add a "hitpart" eventhandler to the player. Off the top of my head something like:



player addEventHandler ["Hitpart",
{
_unit = _this select 0;
_shooter = _this select 1;
if (side _shooter == side _unit) then
{
_unit setdamage 0;
};
}];


I'm on my work lunchbreak so can't verify that this works. The drawback is that if you are already damaged then being hit by a friendly will return you to full health. I'm sure you or others can finesse this further

Share this post


Link to post
Share on other sites

 

Hi redarmy
 
The way I'd do it would be to add a "hitpart" eventhandler to the player. Off the top of my head something like:
player addEventHandler ["Hitpart",
{
_unit = _this select 0;
_shooter = _this select 1;
if (side _shooter == side _unit) then
{
_unit setdamage 0;
};
}];
I'm on my work lunchbreak so can't verify that this works. The drawback is that if you are already damaged then being hit by a friendly will return you to full health. I'm sure you or others can finesse this further

 

Hitpart won't work, because it may run after the damage is already dealt. A headshot will probably kill the unit.

So use handleDamage instead.

 

This might work:

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

Share this post


Link to post
Share on other sites

@Greenfist I wasn't sure if handledamage _this select 3 was the shooter, or the actual object that caused the damage. At any rate we've given redarmy a few options to try :)

Share this post


Link to post
Share on other sites

Thanks guys i got it working.I can crack on with making the mission now.

 

Appreciate it!

Share this post


Link to post
Share on other sites

I'm shortly going to try the version above, since the difference is that you're aiming for player-only.

 

I also realized the dangers of trusting the AI's trigger finger, and in my case, the AI racked up more deaths from friendly fire than from enemy action. So I made my whole squad proof against friendly fire.

 

I got this one from jshock at:

https://forums.bistudio.com/topic/167406-how-to-allow-friendly-fire/

 

Put it in the init.sqf

{

if (side _x isEqualTo WEST) then

{
_x addEventHandler
[
"HandleDamage",

{

_returnDamage = (_this select 2);
if ((side (_this select 0)) isEqualTo (side (_this select 3))) then
{
_returnDamage = 0;
};
_returnDamage;
}
];
};
} forEach allUnits;

I modified it for my squad only:

waitUntil {!isNull player};

{
    _x addEventHandler
    [
        "HandleDamage",
        {
            _returnDamage = (_this select 2);
            if ((side (_this select 0)) isEqualTo (side (_this select 3))) then
            {
                _returnDamage = 0;
            };
            _returnDamage;
        }
    ];
} forEach units group player;

I know you already solved it, but I'm still learning, and it can be helpful to see multiple ways to phrase the same thing.

Share this post


Link to post
Share on other sites

 

I'm shortly going to try the version above, since the difference is that you're aiming for player-only.

 

I also realized the dangers of trusting the AI's trigger finger, and in my case, the AI racked up more deaths from friendly fire than from enemy action. So I made my whole squad proof against friendly fire.

 

I got this one from jshock at:

https://forums.bistudio.com/topic/167406-how-to-allow-friendly-fire/

 

Put it in the init.sqf

{

if (side _x isEqualTo WEST) then

{
_x addEventHandler
[
"HandleDamage",

{

_returnDamage = (_this select 2);
if ((side (_this select 0)) isEqualTo (side (_this select 3))) then
{
_returnDamage = 0;
};
_returnDamage;
}
];
};
} forEach allUnits;

I modified it for my squad only:

waitUntil {!isNull player};

{
    _x addEventHandler
    [
        "HandleDamage",
        {
            _returnDamage = (_this select 2);
            if ((side (_this select 0)) isEqualTo (side (_this select 3))) then
            {
                _returnDamage = 0;
            };
            _returnDamage;
        }
    ];
} forEach units group player;

I know you already solved it, but I'm still learning, and it can be helpful to see multiple ways to phrase the same thing.

 

The two lads above helped me sort it but Jshocks script is actually a touch better as i now see the nessecity in protecting all AI on my side(who uncach in bis function task patrol,safe FILE formation) enemy appear at their front and its always a disaster for the front squad members.

 

Thanks for sharing

Share this post


Link to post
Share on other sites

hi everyone and sry for digging this old thread, but i have a question related to this and dident want to create a new thread:

 

why does this not work?

edit: for landvehicles

{
	if ((side _x) == west) then {_x addEventHandler ["HandleDamage",{ 
		_unit = _this select 0; 
		_damage = _this select 2; 
		_shooter = _this select 3; 
		if (side _shooter != side _unit) then {_unit setDammage (0.2 + getDammage _unit)} else {_damage = 0}; 
		_damage 
		}];
	};
}foreach allunits;

so i want to disable AI friendly fire from same side and if not from same side then increase damage when hit.

Share this post


Link to post
Share on other sites
11 hours ago, Alert23 said:

why does this not work?

edit: for landvehicles

 

11 hours ago, Alert23 said:

foreach allunits;

From allUnits biki: "Return a list of all units (all persons except agents)... " 

Share this post


Link to post
Share on other sites
1 hour ago, mrcurry said:

 

From allUnits biki: "Return a list of all units (all persons except agents)... " 

thank you for this information.

 

now i tried this but still no success

{  
  	if (_x isKindOf "Car") then {  
   			_x addEventHandler ["HandleDamage", {   
     			_unit = _this select 0;    
     			_damage = _this select 2;    
     			_shooter = _this select 3;    
     			if (side _shooter == east) then {_unit setDammage (0.2 + getDammage _unit)} else {_damage = 0};  
		_damage   
   		}];  
 	};  
}

 

Share this post


Link to post
Share on other sites

- Your last code can't work as is. _x has no sense here without   forEach vehicles (as example)

- where are you running your code?

  • Thanks 1

Share this post


Link to post
Share on other sites
On 12/29/2019 at 4:28 PM, pierremgi said:

- Your last code can't work as is. _x has no sense here without   forEach vehicles (as example)

- where are you running your code?

thank you for that info 😃

i got it working now but is it possible to also include the vehicle-crew?

im using this vehicle and the crew is exposed and still takes friendly damage.

how would i combine vehicle and crew?

like this?

{  
  	if (_x isKindOf "Car" OR _x isKindOf "Man") then {  
   			_x addEventHandler ["HandleDamage", {   
     			_unit = _this select 0;    
     			_damage = _this select 2;    
     			_shooter = _this select 3;    
     			if (side _shooter == east) then {_unit setDammage (0.2 + getDammage _unit)} else {_damage = 0};  
		_damage   
   		}];  
 	};  
}  //what would i write here?

 

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

×