Skip to content

Fix onClientVehicleDamage not firing for boat collisions - #5327

Open
Flashmyname wants to merge 1 commit into
multitheftauto:masterfrom
Flashmyname:fix/2212-boat-damage-event
Open

Fix onClientVehicleDamage not firing for boat collisions#5327
Flashmyname wants to merge 1 commit into
multitheftauto:masterfrom
Flashmyname:fix/2212-boat-damage-event

Conversation

@Flashmyname

@Flashmyname Flashmyname commented Sep 5, 2026

Copy link
Copy Markdown

Summary

CBoat does not override CVehicle::VehicleDamage, its vtable slot points at the empty stub, so the hooks that raise onClientVehicleDamage for cars, bikes and planes never ran for boats. Boat collision damage is applied inline in CBoat::ProcessControl instead. This PR hooks that health subtraction the same way the existing VehicleDamage2 hooks do, with the collided vehicle as the attacker and no weapon. Damage proof boats are skipped first, as they are for cars.

Motivation

Fixes #2212. Scripts received onClientVehicleCollision and could watch a boat lose health, but never got the damage event, so the damage could not be cancelled:

addEventHandler("onClientVehicleDamage", root, function()
    cancelEvent()
end)

Weapon damage on a boat already fired the event because it goes through CVehicle::InflictDamage, which is the "not always" in the report.

Note for scripts: a boat collision now raises several damage events, one per damage tick the game applies, and cancelEvent() in the handler blocks the damage.

Test plan

Tested in game with a client resource logging the collision, the damage events and the vehicle health:

  1. Ram a Speeder into a moored boat at speed.
  2. The damage events fire with the loss the game applies and add up to the health drop, with the boat that was hit as the attacker.
  3. With cancelEvent() in the handler the boat stays at full health.
  4. Shooting a boat still fires the event as before.

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.

Comment thread Client/multiplayer_sa/CMultiplayerSA_VehicleDamage.cpp Outdated
Comment thread Client/multiplayer_sa/CMultiplayerSA_VehicleDamage.cpp
CBoat applies its collision damage inline in CBoat::ProcessControl instead of
going through VehicleDamage, so hook that health subtraction the way the
existing VehicleDamage2 hooks do and boats raise the event, cancelEvent
included.

The health store right after the subtraction is part of the same code, so
CBoat_ApplyDamage moves here from CMultiplayerSA_1.3.cpp and the two become one
hook. A damage proof boat still keeps the loss out of its health.

Fixes multitheftauto#2212.
@Flashmyname
Flashmyname force-pushed the fix/2212-boat-damage-event branch from d5b4964 to 03b719e Compare September 5, 2026 18:23
@Flashmyname
Flashmyname requested a review from FileEX September 5, 2026 18:26
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.

Damage handler does not always trigger for boats

2 participants