Skip to content

Player death on direct Health variable modification.#240

Open
Donelast wants to merge 7 commits into
Facepunch:mainfrom
Donelast:main
Open

Player death on direct Health variable modification.#240
Donelast wants to merge 7 commits into
Facepunch:mainfrom
Donelast:main

Conversation

@Donelast

Copy link
Copy Markdown
Contributor

Previously, the Health value could drop into the negatives when modified directly, making the player invulnerable. Since s&box attracts newcomers who might use visual programming to create entities, they may not realize that damage should be applied via the OnDamage function.

To address this, I’ve implemented a check so that if health is set below 1 directly, the player dies correctly. This resolves the issue of negative health values and immortality.

Fixed a bug where health and armor wouldn't go above 100. Changed calculations from percentages to absolute values so high stats now display correctly
Previously, the Health value could drop into the negatives when modified directly, which caused the player to become invulnerable. Since s&box attracts newcomers who might use standard visual programming to create entities, they may not realize that damage should be applied via the OnDamage function, and instead simply modify Health directly.

To address this, I’ve implemented a check so that if health is directly set below 1, the player dies correctly. This resolves the issue where direct modification resulted in negative health and kept the player alive. Previously, direct changes led to player immortality and negative health values.
Previously, the Health value could drop into the negatives when modified directly, making the player invulnerable. Since s&box attracts newcomers who might use visual programming to create entities, they may not realize that damage should be applied via the OnDamage function.

To address this, I’ve implemented a check so that if health is set below 1 directly, the player dies correctly. This resolves the issue of negative health values and immortality.
@DevulTj

DevulTj commented Apr 30, 2026

Copy link
Copy Markdown
Member

this code is very stinky

@Donelast

Copy link
Copy Markdown
Contributor Author

What do I need to rewrite?

@pk8k

pk8k commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

What's the point of _isTakingDamage flag?

Would it make sense to use the field keyword and just detect in the property setter whether Health got set to 0 and call the relevant event, aka converting the damage method to a utility that just changes Health?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants