Prevent AddMultiDamage execution with zero/negative damage#1103
Prevent AddMultiDamage execution with zero/negative damage#1103dystopm wants to merge 1 commit intorehlds:masterfrom
Conversation
| return; | ||
|
|
||
| #ifdef REGAMEDLL_FIXES | ||
| if (flDamage <= 0.0f) // avoid zero or negative damage TakeDamage |
There was a problem hiding this comment.
This fix makes sense.
However, there is one detail I remember, some custom maps intentionally use negative damage values (e.g., env_laser with damage = -300) as a way to heal players.
The maps I recall include bhop_zerocheaters, deathrun_forest, deathrun_friends, but there are many more with different scenarios.
This is not a bug but rather a hidden feature that level designers sometimes rely on. With your change, such maps would stop working as intended, since TakeDamage would never be triggered.
So the fix could unintentionally break existing community content.
One possible approach could be to allow negative values (skip only flDamage == 0).
There was a problem hiding this comment.
I don't think flDamage == 0 should be skipped either, there is high chance that heavily customized servers might already use zero damage sources for things, to me it seems that the if damage was zero check should be done on the plugin developer's side to maintain current flexibility. It's always better the more things there are to hook into and modify than less.
|
Sometimes plugins just need to detect the |
Purpose
The
AddMultiDamagefunction can be skipped entirely when no damage will be applied. While some existing cases already avoid calling it with zero damage (e.g.FireBullets3, shield hit avoidsTraceAttack->AddMultiDamagecalls), there are other scenarios where it is still invoked with adamagevalue of0or less (e.g., hitting a player with shotgun pellets while they have an active Shield).These unnecessary calls not only waste processing but can also have unintended side effects for APIs implemented by developers that rely on
TakeDamagebeing called only when damage is actually applied. This PR ensures that the function only executes whenflDamage > 0.Approach
Added a simple check at the start of
AddMultiDamageto immediately return if theflDamageparameter is0or less.