Open Hiranus opened 1 month ago
I tried to achieve similar result in LUA to be able to train animals from unit overlay but for some reason it didn't work, so it would be good to check if it really works for tamed animals.
function set_training(training,option)
local unit = dfhack.gui.getSelectedUnit(true)
if not unit then return end
local assignments = df.global.plotinfo.training.training_assignments
local animal_assignment = nil
for i = 0, #assignments-1 do
if assignments[i].animal_id == unit.id then
animal_assignment = assignments[i]
break
end
end
print(animal_assignment ~= nil ,dfhack.units.isMarkedForTraining(unit))
if animal_assignment ~= nil and not dfhack.units.isMarkedForTraining(unit) then
dfhack.units.unassignTrainer(unit)
animal_assignment = nil
end
print(animal_assignment ~= nil)
if animal_assignment ~= nil then
print("altering")
animal_assignment.flags[training] = option
return
end
print("adding")
animal_assignment = df.new(df.training_assignment)
animal_assignment.animal_id = unit.id
animal_assignment.flags.any_trainer = true
animal_assignment.flags[training] = option
assignments:insert('#',animal_assignment)
end
https://github.com/DFHack/dfhack/blob/5b5a1ac363d83615584caa37535e943679a2b0b8/library/modules/Units.cpp#L418
https://github.com/DFHack/dfhack/blob/5b5a1ac363d83615584caa37535e943679a2b0b8/library/modules/Units.cpp#L426
These two lines should also check if animal is already trained with either war or hunt. Vanilla UI does not allow for retraining of the same animal multiple times, it can only be done once.
Also, only adult animals can be trained.
https://github.com/DFHack/dfhack/blob/5b5a1ac363d83615584caa37535e943679a2b0b8/library/modules/Units.cpp#L509
Animal can also get trainer in vanilla UI when it is (fully) tamed and player tries to war/hunt train it. For whatever reason you just need to reopen UI for trainer info to appear.![obraz](https://github.com/user-attachments/assets/caf0611a-de8a-4062-bfb6-6b06e8d1ba14)