LUA scripting

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

Moderator: Panzer Corps 2 Moderators

Post Reply
vardlokkur
Lance Corporal - Panzer IA
Lance Corporal - Panzer IA
Posts: 10
Joined: Tue Apr 07, 2015 6:35 am

LUA scripting

Post by vardlokkur » Sun May 24, 2020 10:19 pm

Is it possible to get a little more detailed description of LUA APIs than the one we get with the game?

I've seen that LUA scripts for the default campaign scenarios use much more functions that is defined in PDF "Lua scripting ..."

I'm struggling for example with making Hex a Victory Hex, when I tried to do:

Code: Select all

VictoryHex = 2048
...
local hex = world:GetHex(.........)    
hex.special = hex.special | VictoryHex 
Hex becomes Victory Hex (at least it's description changes, and when you point the mouse over it, you'll see it's Victory Hex), but it is not marked on the map as Victory Hex (with green border) - I'm not sure if I should use some other API calls, or it's a game bug, or you cannot make the Hex a Victory Hex from LUA

terminator
General - Elite King Tiger
General - Elite King Tiger
Posts: 4211
Joined: Mon Aug 15, 2011 12:48 pm
Location: the loveliest country in the world

Re: LUA scripting

Post by terminator » Fri Jun 05, 2020 1:49 pm

There is no similar example in the official campaign?

dalfrede
Major - 8.8 cm FlaK 36
Major - 8.8 cm FlaK 36
Posts: 972
Joined: Wed Mar 15, 2017 7:48 pm

Re: LUA scripting

Post by dalfrede » Fri Jun 05, 2020 3:34 pm

At this point there is no LUA script documentation.
I do have a manual, but is of little help.

The script may need a trigger.
Otherwise just place it on the map in the editor.

Edit. To add graphics would require a call to the editor, not the game engine.
After you make a map you must compile it before the game can use it.
This suggests that you would have to add it in the editor, then add a script to turn it off, then on with a trigger.
Or use a shroud command that hides it.

You would probably have to ask Patrick Ward if it possible, since this is a graphics issue more than a game engine issue.
There comes a time on every project when it is time to shoot the engineer and ship the damn thing.

Kerensky
Content Designer
Content Designer
Posts: 7167
Joined: Wed Jan 12, 2011 2:12 am

Re: LUA scripting

Post by Kerensky » Sat Jun 06, 2020 12:36 am

If there isn't an example of something, trying to experiment is a recipe for a major headache.

Scripts are extraordinarily fragile.

The difference between
local action = world:MakeNewHeroAction(1, hero)

and
local action = world:MakeNewHeroAction(2, hero)

Is the difference between the scenario working flawlessly, or crashing immediately on trying to start.

My only advise is to use existing scripts you see in current content. The library is about to get a giant expansion of features soon, so watch out for this.

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

Re: LUA scripting

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

Hi Kerensky,

I am trying to add heros through lua into my scenario. I got it all working but the vital step of adding the hero through lua code. I tried your code snippet here, but it does not work for me. Any chance you could give us the lines to do so, please?
I am looking for something like this, or actually that is the latest of my trial and error work:

function CreateHero()

local action = world:MakeNewHeroAction(1, hero)
action.trait = "DoubleAttack"
world:Exec(action)
MessageBox(string_6)

end

Any help would be highly appreciated. Thank you for your time.

Kerensky
Content Designer
Content Designer
Posts: 7167
Joined: Wed Jan 12, 2011 2:12 am

Re: LUA scripting

Post by Kerensky » Fri Jun 12, 2020 8:57 pm

Adding heroes to Panzer Corps 2 scenarios is a feature coming with the Axis Operations DLC. Flashback did a great job working on the backend of the game to enable scripts like this to exist, so be sure to thank them for it.

Axis Operations Spanish Civil War is coming with a huge repository of a wealth of new LUA script types and working examples to reverse engineer from, including adding hero ability and stats to units on the map. It'll be here very soon, just wait for it and it will be available for everyone to experience and also learn from to integrate into their own custom content.

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

Re: LUA scripting

Post by AVerhoeven » Fri Jun 12, 2020 9:02 pm

Thank for the info great news

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

Re: LUA scripting

Post by NETSCAPE » Wed Nov 11, 2020 6:13 pm

So uh how do we add heroes? And is there a reference to see all available heroes and their name ie "DoubleAttack" as mentioned above?

Kerensky
Content Designer
Content Designer
Posts: 7167
Joined: Wed Jan 12, 2011 2:12 am

Re: LUA scripting

Post by Kerensky » Wed Nov 11, 2020 6:44 pm

You can probably pick any DLC scenario for a full example on how to set up a hero. And the more samples you look at, the more configurations you can inspect. Adolf Galland is pretty special because of his +stats and also class restriction.
It's how you also make multi-ability special heroes.

As for a list, be warned that not all of these work, so some experimentation and trial and error is required.



Strength, Initiative, Spotting, Range, Speed, Ammo, Fuel

ATSupport, AASupport, SingleEntity, QuadripleGun, PreciseOptics,
LowProfile, SuppressingFire, Recon, ReconPlane, MilitaryEngineer,
CloseFighter, LongRanged, Capturable, NoPurchase, NoOverstrength,
ArtySupport, FighterSupport, MachineGun, BridgeEngineer, Paratrooper,
Glider, BunkerKiller, CarpetBombing, ForcedMarch, EntKiller2, EntKiller3, EntKiller4,
NoZOC, IgnoresZOC, Camouflage, NoUpgrade, NoReplace, Minefield, MineKiller, MineSweeper,
CounterBattery, NoRetaliation, NoMoveAfterAttack, NoAttackAfterMove, OpenTop,
IgnoresEntrenchment, PhasedMovement, Overrun, NoRetreat, NoSurrender, NoEntrenchment,
Kamikaze, SingleShot, NoSplit, Alpine, LowAltitudeAttack, NoSupply, IncMaxOverstrength,
DoubleMove, DoubleAttack, Splitter, ShockTactics, OverwhelmingAttack, Envelopment, Liberator,
DoubleMassAttack, FastLearner, SixthSense, HitAndRun, LethalAttack, Survivor,
FastEntrenchment, SmartEntrenchment, RiverAssault, FastDeployment, LightningAttack, CombatLuck,
PathFinder, Provocator, Avenger, Prudent, TankKiller, Butcher, DefenderOfPeople, OnTheRoll,
Leadership, FearsomeReputation, AggressiveCounterattack, ThoroughPreparation, Overwatch,
CityFighter, Evasion (dont use this use Evasive), LastStand, Steamroller, StrikesFirst, OrganizedLanding, CheapReplacements,
Distraction, AllWeatherCombat, IgnoreGroundState, FerociousDefense, TerrainExpert,
TenaciousDefender, FierceFighter, Readiness, Resilient, Evacuation, IgnoreMassAttack, ExtendedSupport,
BlockSupply(not function), ReducedSlots, ZeroSlots, AimedShot(junk), DeepKnowledge, Famous, Legendary,
FlagKiller, EntrenchmentSupport, AllTerrainEntrenchment, HalfTrackSupport, DoubleSupport, ExpertSupport,
CripplingBlow, Exterminator, FastRetreat, Evasive, Scavenger, Interrogator, LearnsFromMistakes,
SafeTransit, Ambusher, FieldRepairs, FirstAid, RiverCrossing, FastRebase, SuperiorManeuver, Vigilant,
SkilledRecon, ExpertRecon, SkilledSupport, Unyielding, AimingAssistance, NoManagement,
Alphibious, VulnerableTarget, Submerged, Surfaced

Kerensky
Content Designer
Content Designer
Posts: 7167
Joined: Wed Jan 12, 2011 2:12 am

Re: LUA scripting

Post by Kerensky » Wed Nov 11, 2020 9:58 pm

The simple explanation for assigning heroes via the editor:

1. Set triggers in the editor. A simple 'new round' action with no condition necessary. This will fire when the scenario begins.
2. Look at reference files for format of function that creates hero. Assign a name, portrait image, and their various abilities. DLC examples have many basic heros, but also extra special heroes such as Galland in Spain, Oleh Dir in 1939, and enemy multi ability heroes such as Commandante Vega, and soon to show up de Gaulle in 1940.

And... that's it. It's very flexible to copy paste and edit once you set it up.

Post Reply

Return to “Panzer Corps 2 Scenario Design”