For golems specifically? Oh, very, very good idea, having a filter on the choosable creatures. Then it would actually be useful.
EDIT: here you go, filterized:
local dialog = require('gui.dialogs')
function transform(target,race,caste,length)
if target==nil then
qerror("Not a valid target")
end
local defaultRace = target.enemy.normal_race
local defaultCaste = target.enemy.normal_caste
target.enemy.normal_race = race --that's it???
target.enemy.normal_caste = caste; --that's it!
dfhack.timeout(length,'ticks',function() target.enemy.normal_race = defaultRace target.enemy.normal_caste = defaultCaste end)
end
function selectCreature(unitID,length,filter) --taken straight from here, but edited so I can understand it better: https://gist.github.com/warmist/4061959/... again. Also edited for syndromeTrigger, but in a completely different way.
local creatures=df.global.world.raws.creatures.all
local tbl={}
local tunit=df.global.world.units.all[unitID]
for cr_k,creature in ipairs(creatures) do
for ca_k,caste in ipairs(creature.caste) do
local name=caste.caste_name[0]
if name=="" then name="?" end
if not filter or string.find(name,filter) then table.insert(tbl,{name,nil,cr_k,ca_k}) end
end
end
local f=function(name,C)
transform(tunit,C[3],C[4],length)
end
table.sort(tbl,function(a,b) return a[1]<b[1] end)
dialog.showListPrompt("Creature Selection","Choose creature:",COLOR_WHITE,tbl,f)
end
local args = {...}
selectCreature(tonumber(args[1]),tonumber(args[2]),args[3])