From 04f561cdad149dfd8e67204520a453e1233cbf18 Mon Sep 17 00:00:00 2001 From: Rose Date: Fri, 13 Oct 2023 23:19:54 -0700 Subject: [PATCH] Updated transform-unit.lua to try to select the currently selected unit if none is provided. It still can crash the game, however. --- modtools/transform-unit.lua | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/modtools/transform-unit.lua b/modtools/transform-unit.lua index 3d559d5ab3..8833420ee3 100644 --- a/modtools/transform-unit.lua +++ b/modtools/transform-unit.lua @@ -66,9 +66,17 @@ if args.clear then return end -if not args.unit then - error 'Specify a unit.' +local unit +if args.unit then + unit = df.unit.find(tonumber(args.unit)) +else + unit = dfhack.gui.getSelectedUnit(true) +end +if not unit then + error 'Select or specify a valid unit' + return end +local unit_id = unit.id if not args.duration then args.duration = 'forever' @@ -78,11 +86,10 @@ local raceIndex local race local caste if args.untransform then - local unit = df.unit.find(tonumber(args.unit)) - raceIndex = normalRace[args.unit].race + raceIndex = normalRace[unit_id].race race = df.creature_raw.find(raceIndex) - caste = normalRace[args.unit].caste - normalRace[args.unit] = nil + caste = normalRace[unit_id].caste + normalRace[unit_id] = nil else if not args.race or not args.caste then error 'Specficy a target form.' @@ -113,13 +120,12 @@ else end end -local unit = df.unit.find(tonumber(args.unit)) local oldRace = unit.enemy.normal_race local oldCaste = unit.enemy.normal_caste if args.setPrevRace then - normalRace[args.unit] = {} - normalRace[args.unit].race = oldRace - normalRace[args.unit].caste = oldCaste + normalRace[unit_id] = {} + normalRace[unit_id].race = oldRace + normalRace[unit_id].caste = oldCaste end transform(unit,raceIndex,caste,args.setPrevRace)