Page 1 of 1

Lua Scripts for the game

Posted: Sun Jan 03, 2021 9:31 pm
by Ezequiel1996
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"

Re: Lua Scripts for the game

Posted: Sun Jan 03, 2021 9:32 pm
by Ezequiel1996
what do you think about this idea?

Re: Lua Scripts for the game

Posted: Sun Jan 31, 2021 10:57 pm
by cicciopastic
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?

Re: Lua Scripts for the game

Posted: Sun Jan 31, 2021 11:50 pm
by Ezequiel1996
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?
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.

Re: Lua Scripts for the game

Posted: Tue Feb 02, 2021 10:52 am
by cicciopastic
i will have a look. tks a lot!

Re: Lua Scripts for the game

Posted: Wed Feb 03, 2021 12:00 pm
by cicciopastic
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... :)

Re: Lua Scripts for the game

Posted: Wed Feb 03, 2021 12:35 pm
by jeannot le lapin
I use the freeware Notepad++ :

Capture d’écran (1899).jpg
Capture d’écran (1899).jpg (152.61 KiB) Viewed 4101 times

Re: Lua Scripts for the game

Posted: Sun Mar 21, 2021 5:41 pm
by cicciopastic
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"!!!!! :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol:

Re: Lua Scripts for the game

Posted: Sun Mar 21, 2021 6:38 pm
by cicciopastic
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!

Re: Lua Scripts for the game

Posted: Sun Mar 21, 2021 10:21 pm
by Grondel
viewtopic.php?f=597&t=104801

look here, might help.

Re: Lua Scripts for the game

Posted: Sun Mar 21, 2021 11:24 pm
by cicciopastic
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

Posted: Mon Mar 22, 2021 2:00 pm
by asuser
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.

Re: Lua Scripts for the game

Posted: Thu Mar 25, 2021 11:41 pm
by cicciopastic
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