Lua Scripts for the game
Moderator: Panzer Corps 2 Moderators
-
Ezequiel1996
- Sergeant - 7.5 cm FK 16 nA

- Posts: 231
- Joined: Sat Jun 13, 2020 6:58 am
Lua Scripts for the game
hi i think we should make this post a sticky with Lua Scripts to create our own scripts, so that anybody can share the scripts to do triggers in game for the scenarios.
It would be really useful for the modders out there that doesn't know about scripting, so anyone can share their scripts for doing any kind of triggers in the game to create wonderful scenarios.
The rules could be attaching a file with the script with name of the script and what it does and explaining in the script what you need in order to the srcipt works.
i will add one as an example about how to adquire captured equipment after a hex capture.
i think will help all the modders so hard, because its really hard to script, and have information about this and how to create scripts is really unvaluabable
also if you found any errors or anything wrong with the scripts you can add a fix of the script and has to say something like " Ezequiel1996's Captured equipment after hex capture Fix"
It would be really useful for the modders out there that doesn't know about scripting, so anyone can share their scripts for doing any kind of triggers in the game to create wonderful scenarios.
The rules could be attaching a file with the script with name of the script and what it does and explaining in the script what you need in order to the srcipt works.
i will add one as an example about how to adquire captured equipment after a hex capture.
i think will help all the modders so hard, because its really hard to script, and have information about this and how to create scripts is really unvaluabable
also if you found any errors or anything wrong with the scripts you can add a fix of the script and has to say something like " Ezequiel1996's Captured equipment after hex capture Fix"
- Attachments
-
Tutorial Adding captured equipment after a hex capture.rar- (877 Bytes) Downloaded 207 times
-
Ezequiel1996
- Sergeant - 7.5 cm FK 16 nA

- Posts: 231
- Joined: Sat Jun 13, 2020 6:58 am
Re: Lua Scripts for the game
what do you think about this idea?
-
cicciopastic
- Administrative Corporal - SdKfz 232 8Rad

- Posts: 173
- Joined: Mon Oct 26, 2015 9:01 pm
Re: Lua Scripts for the game
this seems a nice idea. I'am having a look around to see how to add units during the game i.e. suppose i would like to add two infantry units on turn 2 on hex number xx ... i sould i do this?
-
Ezequiel1996
- Sergeant - 7.5 cm FK 16 nA

- Posts: 231
- Joined: Sat Jun 13, 2020 6:58 am
Re: Lua Scripts for the game
you can look for the following scripts on the dlc's AO , open the lua script file on the scenario folder of your liking, a good example for this should be the earlymadrid scenario of AO SCW, look for the pz II unit arriving, you will need also the utility scripts. there are explanations of what the scripts do in green. so you will need to adapt them in order to work in the specific way you want, that's where it gets tricky, so you have to do trial and error. at least it's the only way for now.cicciopastic wrote: ↑Sun Jan 31, 2021 10:57 pm this seems a nice idea. I'am having a look around to see how to add units during the game i.e. suppose i would like to add two infantry units on turn 2 on hex number xx ... i sould i do this?
-
cicciopastic
- Administrative Corporal - SdKfz 232 8Rad

- Posts: 173
- Joined: Mon Oct 26, 2015 9:01 pm
Re: Lua Scripts for the game
i will have a look. tks a lot!
-
cicciopastic
- Administrative Corporal - SdKfz 232 8Rad

- Posts: 173
- Joined: Mon Oct 26, 2015 9:01 pm
Re: Lua Scripts for the game
Hi guys,
yesterday i played a little bit with LUA scripts, but i didnt go very far ....
I am at my very firts steps on LUA ... i have a very basic question .... may i modify any current script in windows notepad and save it back or do i need a specific LUA editor? of course i am working safely making a different lua file and not changing anything on te original ones, but i see may attempts are not producing any effect on a little mod i am using as a test: I wasnt even able to write "hallo" on the second turn ot this test...
yesterday i played a little bit with LUA scripts, but i didnt go very far ....
I am at my very firts steps on LUA ... i have a very basic question .... may i modify any current script in windows notepad and save it back or do i need a specific LUA editor? of course i am working safely making a different lua file and not changing anything on te original ones, but i see may attempts are not producing any effect on a little mod i am using as a test: I wasnt even able to write "hallo" on the second turn ot this test...
-
jeannot le lapin
- 1st Lieutenant - 15 cm sFH 18

- Posts: 827
- Joined: Sun Dec 10, 2017 3:29 pm
Re: Lua Scripts for the game
I use the freeware Notepad++ :
-
cicciopastic
- Administrative Corporal - SdKfz 232 8Rad

- Posts: 173
- Joined: Mon Oct 26, 2015 9:01 pm
Re: Lua Scripts for the game
hi guys,
for the first time i manage to write a correct LUA script and use it in an example scenario!!!!
i managed to write on the first turn "hi dump"!!!!!

for the first time i manage to write a correct LUA script and use it in an example scenario!!!!
i managed to write on the first turn "hi dump"!!!!!
-
cicciopastic
- Administrative Corporal - SdKfz 232 8Rad

- Posts: 173
- Joined: Mon Oct 26, 2015 9:01 pm
Re: Lua Scripts for the game
hey ... i can't reopen my editor now! what's happening? help! ... i just introduced a new lua function and now i cant open my editor!
-
cicciopastic
- Administrative Corporal - SdKfz 232 8Rad

- Posts: 173
- Joined: Mon Oct 26, 2015 9:01 pm
Re: Lua Scripts for the game
ok grondel, now it is working ... just one question, why don't we keep this TD updated? grondel is helping me, but i think a LUA manual made up by users examples could be really useful for noobs like me
Re: Lua Scripts for the game
I also learn it with the hard way: Check the DLC and look in other LUA files and see what happens with it in the game. It might also be useful to first list what you can do with LUA:
Hero assignment, prestige change, depot conquest, prototype control, enemy hero and unit actions ... like that.
Hero assignment, prestige change, depot conquest, prototype control, enemy hero and unit actions ... like that.
-
cicciopastic
- Administrative Corporal - SdKfz 232 8Rad

- Posts: 173
- Joined: Mon Oct 26, 2015 9:01 pm
Re: Lua Scripts for the game
here i create a function to insert a large number of units on a specific turn (turn two in the example): probably there are more efficient way to do that, but this is what i was able to do. notice that if the hex where u put the unit is not free, than the unit will not be placed. hope this help (sorry but it is easier to me to use italian words and italian comments).
should we have a specif thread where we may post our lua attempts???????
any comment is welcome, ciao Pietro
-- questa è la condizione
function turnodue()
return world.round == 2
end
-- questa è la funzione
function due()
-- definisco la funzione piazzamento
function piazzamento(ex1, ex2, giocatore, unita, trasporto, forza)
local esagono = {ex1,ex2} -- esagono di piazzamento
local playe = world:GetPlayer(giocatore) -- quale giocatore
local create_action = world:MakePurchaseAction(playe, unita, trasporto, forza)
create_action.auxiliary = false -- unità core
create_action.cost = 0 -- costo zero
world:Exec(create_action)
local unit = world:GetUnit(create_action.id)
local hex = world:GetHex(esagono)
if (hex:GetUnit(0) == nil) then -- se l'esagono è vuoto
deploy_action = world:MakeDeployAction(unit,esagono)
world:Exec(deploy_action)
end
end
-- faccio i piazzamenti
piazzamento(15, 52, 0, "ESColonial", "OpelBlitz", -5)
piazzamento(16, 52, 0, "ESColonial", "OpelBlitz", -8)
piazzamento(17, 52, 0, "ESColonial", "OpelBlitz", -5)
end
should we have a specif thread where we may post our lua attempts???????
any comment is welcome, ciao Pietro
-- questa è la condizione
function turnodue()
return world.round == 2
end
-- questa è la funzione
function due()
-- definisco la funzione piazzamento
function piazzamento(ex1, ex2, giocatore, unita, trasporto, forza)
local esagono = {ex1,ex2} -- esagono di piazzamento
local playe = world:GetPlayer(giocatore) -- quale giocatore
local create_action = world:MakePurchaseAction(playe, unita, trasporto, forza)
create_action.auxiliary = false -- unità core
create_action.cost = 0 -- costo zero
world:Exec(create_action)
local unit = world:GetUnit(create_action.id)
local hex = world:GetHex(esagono)
if (hex:GetUnit(0) == nil) then -- se l'esagono è vuoto
deploy_action = world:MakeDeployAction(unit,esagono)
world:Exec(deploy_action)
end
end
-- faccio i piazzamenti
piazzamento(15, 52, 0, "ESColonial", "OpelBlitz", -5)
piazzamento(16, 52, 0, "ESColonial", "OpelBlitz", -8)
piazzamento(17, 52, 0, "ESColonial", "OpelBlitz", -5)
end

