ChristianC wrote: ↑Fri May 26, 2023 7:11 pm
Hi, I'm seeking help with spawning units mid-game. I've taken a look around the forums on this subject, scenario lua files and manual - haven't figured it out. Can someone lend me assistance?
Just trying to spawn in a single tank at turn 2 for now to get a general understanding of this.
Lua should look like this to make it reusable:
function isturn2() --<----put this in the editor in the trigger Condition and put the check in NewRoundAction
return world.round == 2
end
function spawntank()--<---put this in the editor in the trigger function
player = 0 --<-- when u open scenarioparameters->players tab this is the player on the left, count up from there
zone = {{1,1},{2,1},{3,1},{4,1},{5,1},{1,2},{2,2},{3,2},{4,2},{5,2},{6,2},{1,3},{2,3},{3,3},{4,3},{5,3},{1,4},{2,4},{3,4},{4,4},{5,4},{6,4}}--<---just a cupple of hexes to make sure one is empty
units = { {"M4Sherman", "", 0, 1500} }
SpawnWave(player, zone, units)
end
function SpawnWave(player, zone, units)
local owner = world:GetPlayer(player)
local cur_hex = 1
for _,u in ipairs(units) do
while zone[cur_hex] do
hex = world:GetHex(zone[cur_hex])
if hex:GetUnit(0) == nil then break end
cur_hex = cur_hex + 1
end
if not zone[cur_hex] then return end
local create_action = world:MakePurchaseAction(owner, u[1], u[2], u[3])
create_action.auxiliary = true --<----------false if u want a core unit
create_action.cost = 0
create_action.faction = owner.factions[1]
world:Exec(create_action)
local unit = world:GetUnit(create_action.id)
deploy_action = world:MakeDeployAction(unit, zone[cur_hex])
world:Exec(deploy_action)
unit.experience = u[4]
player_aggressiveness = { 0, 85, 70, 70 }
unit.aggressiveness = player_aggressiveness[player+1]
end
end
if u still run into issues just ask, did this from scratch and didn´t do a testrun. might have a flaw or two.
sers,
Thomas