OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: Surdus Priest on 15 Sep 2007, 15:24:43

Title: reduce damage taken
Post by: Surdus Priest on 15 Sep 2007, 15:24:43
i need a way to make a unit godmode to everthing but headshots or direct explosive impacts

or better yet a way to make a unit die after a set number of hits

surdus
Title: Re: reduce damage taken
Post by: Mr.Peanut on 15 Sep 2007, 16:55:22
This has been asked soooo many times....

Code: [Select]
this addEventhandler ["HIT",{_this select 0 setDamage 0}];
Will make an infantry unit almost invulnerable. If you want a unit to die after so many hits using only event handlers(recommended) you will need something like:
Code: [Select]
this setVariable ["nHits",0] ; this addEventhandler ["HIT",{_nhits = getVariable (_this select 0) ; _nhits = _nhits + 1 ; if (_nhits > 5) then {_this select 0 setDamage 1 ; _this select 0 removeAllEventHandlers "HIT";} else {_this select 0 setVariable ["nHits", _nhits];}];
What a mouthful that was! Of course you could use a looping script to count the hits or a trigger, but this way is probably the best.

Title: Re: reduce damage taken
Post by: Wolfrug on 15 Sep 2007, 18:11:03
Actually the eventhandler-hit-setdamage 0 no longer works in ArmA. Not sure why, but it doesn't (it never worked for the Player character in OFP either, anyway). Or, well -> it WORKS, as in whenever you're hit it sets your damage to 0, however if you're hit and KILLED (headshot, close-range torso shot, high caliber weaponry) you won't be revived.

To make it work, use a very high negative number, such as -100 instead of 0. That will make the unit nigh invincible. However, anything capable of doing more damage than "-100" in one shot will still kill the unit (I think for instance a direct hit from a SABOT will sometimes kill the soldier etc).

It's an ArmA thing.  :dunno:

Wolfrug out.
Title: Re: reduce damage taken
Post by: Surdus Priest on 15 Sep 2007, 19:59:06
so would this work in the initiation of the unit:

this setdamage -100

then use a looping script or repeating trigger such as:

Condition: unit damage > -100
Activation: unit setdamage -100

would that work?
Title: Re: reduce damage taken
Post by: Mr.Peanut on 16 Sep 2007, 03:23:49
If you search recent threads for setDamage I believe someone claimed that using a negative value only works the first time.
Title: Re: reduce damage taken
Post by: Wolfrug on 16 Sep 2007, 14:39:25
Actually, no. You can't check negative damage values using "damage" or "getdamage" -> if you set the damage to, say, -100, it will still show up as 0. As to a looping script: I'm sure that'd work, why not. But the "hit" eventHandler also works.

However be advised it IS buggy. Here's the thread where it was previously discussed:

Making units tougher (http://www.ofpec.com/forum/index.php?topic=29789.0)

In my testing I came to the conclusion that this is not really a viable solution because:

a) the "hit" eventhandler isn't handled well by many units at a time
b) quick, consecutive and high-damage hits are sometimes too fast for the game to keep up with, and once the magical threshold of "damage == 1" is passed, the unit can by no means be revived.  :(

But for one unit that needs to be invincible for whatever reason: sure, why not? :)

Wolfrug out.
Title: Re: reduce damage taken
Post by: Surdus Priest on 16 Sep 2007, 16:09:18
this seems to work:

Code: [Select]
;v = unit

_number = -1000

#loop

?((damage v) > 0):_number = _number +100

v setdamage _number
~0.1

goto "loop"

with the health value set to -1000 the unit can survive any standard bullets such as assault rifles.

however heavy machine guns or close proxy explosions or sniper shots will kill him.

?((damage v) > 0):_number = _number +100;  this line means that the unit can survive up to 10 of these shots.  so with this under the right conditions, it could possiblly make a fight with a unit into a boss battle, even better if the unit is a tank.

i'd still like to know how to make the damage done not matter and no matter what attacks are made, the unit would survive..
Title: Re: reduce damage taken
Post by: SgtWolf on 24 Sep 2007, 22:01:59
Can I ask why do you use eventhandlers when for the desired result of a unit being "invincible" basically can just involve having setdamage 0 looping in a script?  ???
Title: Re: reduce damage taken
Post by: LCD on 24 Sep 2007, 23:13:59
cuz it seems in ArmA when unit dies it cant b revived like in OFP so even if we have a loopin setdamage unit dat got hit in da head will stay dead...  :no: or at least... so i heard... never bothered 2 check dat :P ;)

LCD OUT
Title: Re: reduce damage taken
Post by: Cheetah on 24 Sep 2007, 23:17:28
If you take the loop time really really short, it should work. However, the hit eventhandler is failsafe, the looping script isn't as far as I know. For example, a MG fires a lot of bullets per minute which may lead to your looping script not healing the unit fast enough. And you need a negative setdammage to handle headshots.
Title: Re: reduce damage taken
Post by: h- on 25 Sep 2007, 16:45:02
eventHandler also beats looping scripts performance wise, eventhandler is not a looping condition check..