need LUA help spawning units

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

Moderator: Panzer Corps 2 Moderators

Post Reply
Senior Corporal - Destroyer
Senior Corporal - Destroyer
Posts: 109
Joined: Wed Apr 15, 2020 8:43 pm

need LUA help spawning units

Post by NETSCAPE » Fri May 29, 2020 5:42 pm

Hey guys I have absolutely zero experience with LUA. I opened up the "Defense of the Reich" scenario (again) and tried to make some sense of it but didn't get far... and what I want to do is slightly different I think.

Anyways, here is an image of the Multiplayer scenario I am working on (click to enlarge):


There are 3 cities on the far east and west of the map... I want specific victory hexes in those cities to act as "factories" and spawn X unit every X amount of turns after checking ownership of the flag/hex owner.

I'd really appreciate some help. I think this map will be epic.

Private First Class - Opel Blitz
Private First Class - Opel Blitz
Posts: 3
Joined: Fri Jun 12, 2020 1:20 pm

Re: need LUA help spawning units

Post by AVerhoeven » Fri Jun 12, 2020 1:28 pm

Hi Netscape,

Here the code to add a unit to the game:

-- Create the unit
-- 1. Create and execute purchase action, use unit type, transport type and overstrength as parameters
local create_action = world:MakePurchaseAction(owner, "Grenadier", "", 0)
create_action.auxiliary = false -- spawn core units
create_action.cost = 0 -- don't take money for units we generate

-- 2. Create and execute deploy action, place the unit in the hex we've picked.
local unit = world:GetUnit(
deploy_action = world:MakeDeployAction(unit, {4,12}) -- here go to the editor select ConfigureHexes and select the hex where you want the unit to be spawned, note it and enter the coordinates here {x,y} example here is {4,12}

you could do this a lot more automated, look at the defenderofthereich.lua file. Scenarios/fictional... folder at your install.

Hope that helps.



Post Reply

Return to “Panzer Corps 2 Scenario Design”