Jump to content
Sign in to follow this  
farooqaaa

Handle Damage before it's processed

Recommended Posts

According to Arma 2 Wiki the player event "HandleDamage" should process the damage returned from that event but it's not working in Arma 3 and damage is handled by the engine no matter what this event returns.

Example code:

player addEventHandler ["HandleDamage", { _damage = 0; _damage; }];

I know that I can set allowDamage to false to stop the player from taking damage but that's not what I want to do. I want to customize the damage before it is processed.

Can anyone help? How does Arma 3 handle this event?

Thanks

Share this post


Link to post
Share on other sites

When returning a value, you can't have a semi colon.

---------- Post added at 06:51 ---------- Previous post was at 06:50 ----------

player addEventHandler ["HandleDamage", { _damage = 0; _damage }];

fixed.

Share this post


Link to post
Share on other sites

Thanks for the fast response. I did that but still no luck.

This doesn't make the player invincible:

player addEventHandler ["HandleDamage", { 0 }];

And this doesn't make it die instantly after taking any amount of damage:

player addEventHandler ["HandleDamage", { 1 }];

Share this post


Link to post
Share on other sites

Wrong area to post this. Try troubleshooting.

Mods will move this.

Share this post


Link to post
Share on other sites

Yeah, I dunno why that's not working.

Try this:

player addEventHandler ["HandleDamage", {player setDamage 0;}];

EDIT:

Using this code on an AI unit named AI_unit will make him invincible.

AI_unit addEventHandler ["HandleDamage", {}];

Using the same code on a player does not make the player invincible.

Pretty sure the HandleDamage event is just broken right now.

Edited by Outlawled

Share this post


Link to post
Share on other sites

if (!Isdedicated) then {

waitUntil {!isNull player};

player addEventHandler ["HandleDamage", {_damage = _this select 2; _unit setdamage _damage;}];

};

A few notes: It gets executed 5 times, for each selection ("head_hit", "torso", "legs", "arms" and ""). Using the example code above will give you undesired behavior most likely.

Personally, I would put it in a call anyway, but:

private ["_unit", "_selectionName", "_amountOfDamage",
"_sourceOfDamage", "_typeOfProjectile","_statusBodyParts"];
_unit = _this select 0;
_selectionName = _this select 1;
_amountOfDamage = _this select 2;
_sourceOfDamage = _this select 3;
_typeOfProjectile = _this select 4;

// modify _amountOfDamage here however you like. For example:
// _amountOfDamage = _amountOfDamage/2; // (not advised to do this, see below)
// one note: The damage passed on is damage done by the bullet + previous damage on the selection (ie previous damage was 0.2, bullet did 0.6 damage. Damage passed on would be 0.8). 
// in arma 3, I found that when setting damage with sethit, any value above or equal to 1.0, kills the unit.

// safest bet, if you want to modify damage is storing it in an array with setvariable on the unit. Grabbing the previous variable, extract that from the passed on damage (_amountOfDamage), and modify that number. 
// Then you add the outcome to this, add that to the original value and adjust _amountOfDamage with this.
// Example:
// _storedDamage = _unit getvariable "stored_damage":
// _difference = _amountOfDamage - _storedDamage;
// _amountOfDamage = _storedDamage + (_difference/2);

if (_selectionName != "") then {
_unit setHit [_selectionName, _amountOfDamage];
};

This might be what you're after? Note, you have to set damage yourself, this handler does not do that for you, thus the setHit. Feel free to PM if you got any questions.

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  

×