Changing unit type with LUA
Posted: Wed Aug 11, 2021 6:43 am
I tried to program an update of a BB with LUA (normal update not possible as I need NoPurchase BBs).
The check if the BB is in the correct hex work; prestige change and message works.
But the BB is not updated.
Has anyone one idea?
Hint: „u.type“ is changed – else I would see the message and prestige change more the once.
But the stats and name of the BB stays the same.
-- my test (IsItemInTable is the function from DLC1 – it works)
hex = {{15,34}}
function updateBB()
for id,u in pairs(world.units) do
if (u.type == GetUnitType("BBLittorio") and IsItemInTable(hex, u.position)) then
u.type = GetUnitType("BBIta40") -- update
local p = world:GetPlayer(0)
p.prestige = p.prestige - 20 -- -20 prestige
MessageBox("Hinweis", "Schlachtschiff wurde hochgerüstet.")
end
end
end
The check if the BB is in the correct hex work; prestige change and message works.
But the BB is not updated.
Has anyone one idea?
Hint: „u.type“ is changed – else I would see the message and prestige change more the once.
But the stats and name of the BB stays the same.
-- my test (IsItemInTable is the function from DLC1 – it works)
hex = {{15,34}}
function updateBB()
for id,u in pairs(world.units) do
if (u.type == GetUnitType("BBLittorio") and IsItemInTable(hex, u.position)) then
u.type = GetUnitType("BBIta40") -- update
local p = world:GetPlayer(0)
p.prestige = p.prestige - 20 -- -20 prestige
MessageBox("Hinweis", "Schlachtschiff wurde hochgerüstet.")
end
end
end