Avoid accessing data of potentially killed unit

Fixes #8019.
This commit is contained in:
Gunter Labes 2023-11-04 21:27:44 +01:00
parent ec0f8f9942
commit 8b111a2a76

View file

@ -176,6 +176,7 @@ function wml_actions.harm_unit(cfg)
end
end
local unit_to_harm_id = unit_to_harm.id
if kill ~= false and unit_to_harm.hitpoints <= 0 then
wml_actions.kill { id = unit_to_harm.id, animate = toboolean( animate ), fire_event = fire_event, harmer and T.secondary_unit { id = harmer.id } }
end
@ -185,7 +186,7 @@ function wml_actions.harm_unit(cfg)
end
if variable then
wml.variables[string.format("%s[%d]", variable, index - 1)] = { id = unit_to_harm.id, harm_amount = damage }
wml.variables[string.format("%s[%d]", variable, index - 1)] = { id = unit_to_harm_id, harm_amount = damage }
end
-- both units may no longer be alive at this point, so double check