LUA script generating duplicate hero traits (campaign only)

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

Moderator: Panzer Corps 2 Moderators

Post Reply
NETSCAPE
Administrative Corporal - SdKfz 251/1
Administrative Corporal - SdKfz  251/1
Posts: 127
Joined: Wed Apr 15, 2020 8:43 pm

LUA script generating duplicate hero traits (campaign only)

Post by NETSCAPE »

Below is a script that I had working with a template scenario to test building my division. However, after making the campaign structure and launching the mission it creates duplicates of the hero traits I assigned, meaning it creates 2 of the same traits for every unit. And yes I have the trigger counters set to 1 in the editor, using NewRoundAction as the condition. I even simplified the script. Initially I had 3 "TankHero" and 2 "SignalHero"... here is the script but I'm guessing the issue is caused by the campaign mode for some reason??? thanks for any help.

------

function TankHero()
CreateAndAssignTankHero1(0) -- specify id of the unit which will get this hero
CreateAndAssignTankHero2(4) -- specify id of the unit which will get this hero
CreateAndAssignTankHero3(64) -- specify id of the unit which will get this hero
CreateAndAssignTankHero4(48) -- specify id of the unit which will get this hero
CreateAndAssignTankHero5(49) -- specify id of the unit which will get this hero
end

function CreateAndAssignTankHero1(unit_id)
local hero = NewHero()
local unit = world:GetUnit(unit_id)
if (unit == nil) then return end
--hero.portrait = "/Game/Gui/Common/Heroes/DE/de_in_16.de_in_16"
hero.portrait = "/Game/Gui/Common/Heroes/generic_standin.generic_standin"
hero.name = NSLOCTEXT("scenario_AcrosstheRiver", "TankHero", "")
hero.extra_traits = {UnitTrait.Leadership}
local action = world:MakeNewHeroAction(unit.owner_id, hero)
world:Exec(action)

local assign_hero_action = world:MakeAssignHeroAction(unit, hero.id)
world:Exec(assign_hero_action)
end

function CreateAndAssignTankHero2(unit_id)
local hero = NewHero()
local unit = world:GetUnit(unit_id)
if (unit == nil) then return end
--hero.portrait = "/Game/Gui/Common/Heroes/DE/de_in_16.de_in_16"
hero.portrait = "/Game/Gui/Common/Heroes/generic_standin.generic_standin"
hero.name = NSLOCTEXT("scenario_AcrosstheRiver", "TankHero", "")
hero.extra_traits = {UnitTrait.Leadership}
local action = world:MakeNewHeroAction(unit.owner_id, hero)
world:Exec(action)

local assign_hero_action = world:MakeAssignHeroAction(unit, hero.id)
world:Exec(assign_hero_action)
end

function CreateAndAssignTankHero3(unit_id)
local hero = NewHero()
local unit = world:GetUnit(unit_id)
if (unit == nil) then return end
--hero.portrait = "/Game/Gui/Common/Heroes/DE/de_in_16.de_in_16"
hero.portrait = "/Game/Gui/Common/Heroes/generic_standin.generic_standin"
hero.name = NSLOCTEXT("scenario_AcrosstheRiver", "TankHero", "")
hero.extra_traits = {UnitTrait.Leadership}
local action = world:MakeNewHeroAction(unit.owner_id, hero)
world:Exec(action)

local assign_hero_action = world:MakeAssignHeroAction(unit, hero.id)
world:Exec(assign_hero_action)
end

function CreateAndAssignTankHero4(unit_id)
local hero = NewHero()
local unit = world:GetUnit(unit_id)
if (unit == nil) then return end
--hero.portrait = "/Game/Gui/Common/Heroes/DE/de_in_16.de_in_16"
hero.portrait = "/Game/Gui/Common/Heroes/generic_standin.generic_standin"
hero.name = NSLOCTEXT("scenario_AcrosstheRiver", "TankHero", "")
hero.extra_traits = {UnitTrait.Leadership}
local action = world:MakeNewHeroAction(unit.owner_id, hero)
world:Exec(action)

local assign_hero_action = world:MakeAssignHeroAction(unit, hero.id)
world:Exec(assign_hero_action)
end

function CreateAndAssignTankHero5(unit_id)
local hero = NewHero()
local unit = world:GetUnit(unit_id)
if (unit == nil) then return end
--hero.portrait = "/Game/Gui/Common/Heroes/DE/de_in_16.de_in_16"
hero.portrait = "/Game/Gui/Common/Heroes/generic_standin.generic_standin"
hero.name = NSLOCTEXT("scenario_AcrosstheRiver", "TankHero", "")
hero.extra_traits = {UnitTrait.Leadership}
local action = world:MakeNewHeroAction(unit.owner_id, hero)
world:Exec(action)

local assign_hero_action = world:MakeAssignHeroAction(unit, hero.id)
world:Exec(assign_hero_action)
end
Post Reply

Return to “Panzer Corps 2 Scenario Design”