Page 1 of 1

LUA scripting

Posted: Sun May 24, 2020 10:19 pm
by vardlokkur
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

Re: LUA scripting

Posted: Fri Jun 05, 2020 1:49 pm
by terminator
There is no similar example in the official campaign?

Re: LUA scripting

Posted: Fri Jun 05, 2020 3:34 pm
by dalfrede
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.

Re: LUA scripting

Posted: Sat Jun 06, 2020 12:36 am
by Kerensky
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)

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.

Re: LUA scripting

Posted: Fri Jun 12, 2020 1:32 pm
by AVerhoeven
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"


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

Re: LUA scripting

Posted: Fri Jun 12, 2020 8:57 pm
by Kerensky
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.

Re: LUA scripting

Posted: Fri Jun 12, 2020 9:02 pm
by AVerhoeven
Thank for the info great news

Re: LUA scripting

Posted: 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?

Re: LUA scripting

Posted: Wed Nov 11, 2020 6:44 pm
by Kerensky
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

Re: LUA scripting

Posted: Wed Nov 11, 2020 9:58 pm
by Kerensky
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.