From 11781f57a779db82c8c474a48a6149a04e4eef8c Mon Sep 17 00:00:00 2001 From: Jacob Gustafson <7557867+poikilos@users.noreply.github.com> Date: Tue, 12 Apr 2022 12:27:59 -0400 Subject: [PATCH] Detect if the object is dying rather than dead. The engine doesn't call on_punch when the object is already dead. The necessary fix is to accept the damage param and use it to predict if this call kills the object (resolves #61). --- api.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api.lua b/api.lua index b6b93d7..10c4d1c 100644 --- a/api.lua +++ b/api.lua @@ -735,9 +735,9 @@ function vehicles.explodinate(ent, radius) end) end -function vehicles.on_punch(self, puncher) +function vehicles.on_punch(self, puncher, time_from_last_punch, tool_capabilities, direction, damage) local hp = self.object:get_hp() - if hp == 0 then + if (hp - damage) < 1 then if self.driver then vehicles.object_detach(self, self.driver, {x=1, y=0, z=1}) end