Changing unit type with LUA

A forum to discuss custom scenarios, campaigns and modding in general.

Moderator: Panzer Corps 2 Moderators

Post Reply
peterw
Administrative Corporal - SdKfz 232 8Rad
Administrative Corporal - SdKfz 232 8Rad
Posts: 154
Joined: Fri Apr 25, 2014 7:08 am

Changing unit type with LUA

Post by peterw »

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
Post Reply

Return to “Panzer Corps 2 Scenario Design”