Wrap DEAD event handler in pcall as it sometimes fails (#3497)

This commit is contained in:
zhexu14 2025-04-06 22:43:52 +10:00 committed by GitHub
parent 5f66b6230f
commit 023c56700e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -176,16 +176,19 @@ local function onEvent(event)
end end
if event.id == world.event.S_EVENT_DEAD and event.initiator then if event.id == world.event.S_EVENT_DEAD and event.initiator then
dead_events[#dead_events + 1] = event.initiator.getName(event.initiator) get_initiator_name_success, initiator_name = pcall(event.initiator.getName, event.initiator)
local position = event.initiator.getPosition(event.initiator) if get_initiator_name_success then
local destruction = {} dead_events[#dead_events + 1] = event.initiator.getName(event.initiator)
destruction.x = position.p.x local position = event.initiator.getPosition(event.initiator)
destruction.y = position.p.y local destruction = {}
destruction.z = position.p.z destruction.x = position.p.x
destruction.type = event.initiator:getTypeName() destruction.y = position.p.y
destruction.orientation = mist.getHeading(event.initiator) * 57.3 destruction.z = position.p.z
destroyed_objects_positions[#destroyed_objects_positions + 1] = destruction destruction.type = event.initiator:getTypeName()
write_state() destruction.orientation = mist.getHeading(event.initiator) * 57.3
destroyed_objects_positions[#destroyed_objects_positions + 1] = destruction
write_state()
end
end end
if event.id == world.event.S_EVENT_HIT then if event.id == world.event.S_EVENT_HIT then