Jump to content
Sign in to follow this  
jstibbsy

Instant kill enemy (opfor)

Recommended Posts

Hey, I'm having trouble getting instant kill for enemy units to work. They don't follow what it's meant to do. I'd love some help cause I'm so confused why they aren't following the code: 

1. {_x addeventhandler ["hit",{_x addEventHandler ["HandleDamage", {_x setdamage 1;}];}]} foreach (allunits - playableunits); <-- tried that
2. {_x addeventhandler ["hit",{_x setdamage 1;}]} foreach (allunits - playableunits); <-- tried that
3. {_x addEventHandler ["HandleDamage", {_x setdamage 1;}];} foreach (allunits - playableunits);

Any help would be appreciated!

Share this post


Link to post
Share on other sites
10 minutes ago, jstibbsy said:

Hey, I'm having trouble getting instant kill for enemy units to work. They don't follow what it's meant to do. I'd love some help cause I'm so confused why they aren't following the code: 


1. {_x addeventhandler ["hit",{_x addEventHandler ["HandleDamage", {_x setdamage 1;}];}]} foreach (allunits - playableunits); <-- tried that
2. {_x addeventhandler ["hit",{_x setdamage 1;}]} foreach (allunits - playableunits); <-- tried that
3. {_x addEventHandler ["HandleDamage", {_x setdamage 1;}];} foreach (allunits - playableunits);

Any help would be appreciated!

 

What exactly do you want to happen?

Your examples make it seem like you're utterly confused, heh.

 

Cheers

Share this post


Link to post
Share on other sites

Your EH must return a value to override the engine's amount of damage. Here 1 for full damage. I added switchableUnits exception to make it compatible in SP:

 

{_x addEventHandler ["HandleDamage", {1}] } foreach (allunits - playableunits - switchableUnits);

 

That's all you need.

Share this post


Link to post
Share on other sites
On 29/08/2017 at 7:03 PM, Grumpy Old Man said:

 

What exactly do you want to happen?

Your examples make it seem like you're utterly confused, heh.

 

Cheers

I was very confused, it was just when I shot an enemy with my gun it'd kill them in one shot. 

 

17 hours ago, pierremgi said:

Your EH must return a value to override the engine's amount of damage. Here 1 for full damage. I added switchableUnits exception to make it compatible in SP:

 

{_x addEventHandler ["HandleDamage", {1}] } foreach (allunits - playableunits - switchableUnits);

 

That's all you need.

Thanks, I'll try it when I'm home. I have it so if it's single player then all the other MP units don't spawn. 

  • Like 1

Share this post


Link to post
Share on other sites
6 minutes ago, jstibbsy said:

I was very confused, it was just when I shot an enemy with my gun it'd kill them in one shot. 

 

Thanks, I'll try it when I'm home. I have it so if it's single player then all the other MP units don't spawn. 

 

Pierres example will be added to all units, so even your AI squadmates will get instantly killed when getting hit.

This will add an eventhandler to all opfor units as you requested, so they will be killed instantly when getting hit.

{_x addEventHandler ["HandleDamage", {1}]} forEach (allUnits select {side _x isEqualTo east}); 

Cheers

Share this post


Link to post
Share on other sites
2 hours ago, Grumpy Old Man said:

 

Pierres example will be added to all units, so even your AI squadmates will get instantly killed when getting hit.

This will add an eventhandler to all opfor units as you requested, so they will be killed instantly when getting hit.


{_x addEventHandler ["HandleDamage", {1}]} forEach (allUnits select {side _x isEqualTo east}); 

Cheers

haha my saviour again!

Share this post


Link to post
Share on other sites

Just be aware that opfor units will die with even the tiniest amount of damage, probably hitting a wall while driving might be enough, didn't test that, also ricochets from a P07 are enough.

You could always tweak the number since it's being added to the current damage of the unit.

 

If a unit has 0 damage, gets hit, the eventhandler adds 1 damage to the unit.

Now if a unit has 0.2 damage, gets hit and the eventhandler returns 0.5, it will set the damage of the unit to 0.7.

Every hit after that will kill the unit.

 

This EH is also a bit tricky to tweak since it will fire on every incoming damage, main problem being that bullets are able to pass through multiple selections, triggering the EH multiple times.

 

Thought you might wanna know, heh.

 

Cheers

Share this post


Link to post
Share on other sites
9 hours ago, Grumpy Old Man said:

Just be aware that opfor units will die with even the tiniest amount of damage, probably hitting a wall while driving might be enough, didn't test that, also ricochets from a P07 are enough.

You could always tweak the number since it's being added to the current damage of the unit.

 

If a unit has 0 damage, gets hit, the eventhandler adds 1 damage to the unit.

Now if a unit has 0.2 damage, gets hit and the eventhandler returns 0.5, it will set the damage of the unit to 0.7.

Every hit after that will kill the unit.

 

This EH is also a bit tricky to tweak since it will fire on every incoming damage, main problem being that bullets are able to pass through multiple selections, triggering the EH multiple times.

 

Thought you might wanna know, heh.

 

Cheers

I'm not incorporating vehicles or anything. You'll see what I've done when I realise the mission.

Share this post


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

I'm not incorporating vehicles or anything. You'll see what I've done when I realise the mission.

Just in case for someone interested:

As GOM said, allUnits returns warriors. OK. But if they are in a vehicle and your vehicle gets small damage (bumping a wall or else), sometimes, the crew takes some damages also. In your case, units can die for nuts.

A workaround, if needed, is to avoid lethal damage, just usual one, for units inside vehicles.

 

{_x addEventHandler ["HandleDamage", {if (isNull objectParent (_this select 0) ) then {1} } ]} forEach (allUnits select {side _x isEqualTo east});

 

  • Like 1

Share this post


Link to post
Share on other sites
5 hours ago, pierremgi said:

Just in case for someone interested:

As GOM said, allUnits returns warriors. OK. But if they are in a vehicle and your vehicle gets small damage (bumping a wall or else), sometimes, the crew takes some damages also. In your case, units can die for nuts.

A workaround, if needed, is to avoid lethal damage, just usual one, for units inside vehicles.

 

{_x addEventHandler ["HandleDamage", {if (isNull objectParent (_this select 0) ) then {1} } ]} forEach (allUnits select {side _x isEqualTo east});

 

 

Just be aware that with your example the unit will take regular projectile damage when sitting inside a vehicle, so if the unit is sitting on a quadbike and you shoot it, it won't be an instant kill.

So we need to make the unit still instant killable and handle damage from crashes to not kill units.

A simple solution could be this:

{_x addEventHandler ["HandleDamage", {

	params ["_unit","_selection","_damage","_damageSource"];
	if (isNull _damageSource) exitWith {_damage};
	1

}]} forEach (allUnits select {side _x isEqualTo east});

If a collision is cause of the damage, the damagesource returns objNull, this way units can still get one hit killed even inside a vehicle and are not prone to die when hitting a bush.

 

Cheers

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  

×