Skip to content

Add onPedHit event - #5179

Open
FileEX wants to merge 3 commits into
multitheftauto:masterfrom
FileEX:feature/onPedHit
Open

Add onPedHit event#5179
FileEX wants to merge 3 commits into
multitheftauto:masterfrom
FileEX:feature/onPedHit

Conversation

@FileEX

@FileEX FileEX commented Aug 14, 2026

Copy link
Copy Markdown
Member

Summary

This PR adds a new server-side onPedHit event, which is triggered when a ped/player is hit by another player/ped with a melee weapon, a physical weapon attack (such as hitting with a rifle butt), or a vehicle.

Motivation

The main purpose of this event is to make it easier to detect god mode cheats. For firearms, we can use onPlayerWeaponFire on the server side to check whether the player actually took damage. For projectiles, we can use onPlayerProjectileCreation, and for the fire extinguisher and spray can, we have isPedChoking. However, there is currently no way to check whether a player was hit by a melee attack.

With god mode cheats, the onPedDamage event isn't triggered because the server keeps receiving the same HP value from the client. This event will allow us to check whether the player actually took damage after being hit.

I know it's still not perfect and can be bypassed, but if an onElementHealthChange event is added someday, there will be no way to bypass it, because even clever tricks like changing the HP in a timer would still be easily detectable on the server side.

Test plan

addEventHandler('onPedHit', root, function(attacker, weapon, bodypart, loss)
    print(source) -- victim
    print(attacker, weapon, bodypart, loss)
end)

Checklist

  • Your code should follow the coding guidelines.
  • Smaller pull requests are easier to review. If your pull request is beefy, your pull request should be reviewable commit-by-commit.

@FileEX FileEX added the enhancement New feature or request label Aug 14, 2026
@PlatinMTA

Copy link
Copy Markdown
Contributor

a bit offtopic but yes onElementHealthChange would be really useful, not even to detect cheats but just for general purposes like disabling a "grey screen" shader when a player recovers its health. right now you basically need to know where the players can heal up and hook it up or just have a timer running to catch the changes of health. well there are other methods but its just inconvenient.

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants