Finally two rather ugly workarounds, which seem to do the trick until something better is found.
The first one replaces the "WoundCommander" function in game_commanders.lua to achieve a small (5% in this example) chance of a commander getting killed if his unit gets destroyed, else the commander gets injured as usual.
Code: Select all
function WoundCommander(commander, recoverTime)
local faction = game:GetFactionById(data.commanders[commander.id+1].faction)
if math.random(1,20) == 1 then
table.remove(faction.luaData.commanders, commander.id)
else
if recoverTime == nil then
recoverTime = 3
end
faction.luaData.commanders[commander.id].unit = nil
faction.luaData.commanders[commander.id].turns = math.random(recoverTime, recoverTime + 2)
end
end
While this here is my somewhat successful attempt to create a way to remove a specific commander to be used for special events. In this example's case it's Austria's Hotzendorf (whose commander.id is 23) at the start of the second gameturn.
Code: Select all
function SendCommanderToHell()
local austria = game:GetFactionById(3)
if game.turn == 2 then
for unit in austria.units do
if unit.commander ~= nil then
local commander = unit.faction.luaData.commanders[commander]
if unit.commander.id == 23 then
unit:DetachCommander()
table.remove(austria.luaData.commanders[23])
end
end
end
end
end
It seems to work alright as long as the commanders is actually placed with some unit at the time the event gets triggered.
However, I still have no idea how to remove a detached or wounded commander from the production tab, so any suggestions on how to solve this or other comments are welcome!