@@ -26,7 +26,7 @@ local function getDeathStringFromCause(cause)
2626end
2727
2828-- Returns a cause of death given a unit
29- function getDeathCauseFromUnit (unit )
29+ local function getDeathCauseFromUnit (unit )
3030 local str = unit .name .has_name and ' ' or ' The '
3131 str = str .. dfhack .units .getReadableName (unit )
3232
@@ -104,7 +104,7 @@ local function getDeathEventForHistFig(histfig_id)
104104end
105105
106106-- Returns the cause of death given a histfig
107- function getDeathCauseFromHistFig (histfig )
107+ local function getDeathCauseFromHistFig (histfig )
108108 local histfig_unit = df .unit .find (histfig .unit_id )
109109 if not histfig_unit then
110110 qerror (" Cause of death not available" )
@@ -149,6 +149,15 @@ local function get_target()
149149 return selected_item .hist_figure_id , df .unit .find (selected_item .unit_id )
150150end
151151
152+ -- wrapper function to take either a unit or a histfig and get the death cause
153+ function getDeathCause (target )
154+ if df .unit :is_instance (target ) then
155+ return getDeathCauseFromUnit (target )
156+ else
157+ return getDeathCauseFromHistFig (target )
158+ end
159+ end
160+
152161if dfhack_flags .module then
153162 return
154163end
@@ -161,7 +170,7 @@ elseif hist_figure_id == -1 then
161170 if not selected_unit then
162171 qerror (" Cause of death not available" )
163172 end
164- print (dfhack .df2console (getDeathCauseFromUnit (selected_unit )))
173+ print (dfhack .df2console (getDeathCause (selected_unit )))
165174else
166- print (dfhack .df2console (getDeathCauseFromHistFig (df .historical_figure .find (hist_figure_id ))))
175+ print (dfhack .df2console (getDeathCause (df .historical_figure .find (hist_figure_id ))))
167176end
0 commit comments