Lua in Command tutorial 2

Post new mods and scenarios here.

Moderator: MOD_Command

Post Reply
Tomcat84
Posts: 1952
Joined: Wed Jul 10, 2013 5:13 pm

Lua in Command tutorial 2

Post by Tomcat84 »

Hey all,

I've made another tutorial in closed beta showcasing some of the new Lua functionality that the 1.06 patch brings to Command. Compared to the first tutorial this one goes more in depth on practical usage of some of the new Lua functions and also shows a few non-Lua related tricks that you can use to build better scenarios.

The functionality mostly applies to scenario designers as it gives more tools to build an interesting AI opponent. So if you only play scenarios and dont build any you might find it less interesting, but still, you could get an idea of what you can face in future scenarios.



You can find the video tutorial HERE


Functionality showcased in this tutorial is as follows:

- Making a CAP change mission to become more aggressive once approached
- Having a 50% chance of an AWACS being added when the scen is loaded
- Removing radar information from fighters when the Fighter HQ is bombed (permanently or coming back online after X amount of minutes)
- Making tanks become detectable to the player side when crossing into an area
- Making those tanks retreat once they reach a certain amount of damage together
- Randomizing whether an SA-2 site is dumb with radar on or smart with radar off and a prosecution area at scen load
- Randomly adding either an SA-3, SA-6 or SA-8 at a location
- Randomly adding either an SA-3, SA-6 or SA-8 at a location with 40% chance for 3 or 6 and 20% for the 8
- Randomizing which CAPs a group of MiG-29s goes to
- Having the weather improve over time with slight amount of randomness
- Showing how to have a strike mission marshal somewhere first before
- Randomly selecting which target they go to.
- A few things with the EW radars
- Having SAMs go active once too many EW Radars are taken out
- Having SAMs go active when the SAM HQ is bombed
- Having SAMs go passive again when HQ backup is online after X minutes, UNLESS they were already active because EW radars were taken out


You can also find some info on how the scripts work on Baloogan's site:

http://wiki.baloogancampaign.com/index.php/CommandLua

as well as this great documentation by CKFinite:

http://commandlua.github.io/

I hope you enjoy this tutorial and find it useful.

Other than that let it also be noted that more Lua improvements are either included already in 1.06 or in the works for future patches, and this tutorial does not cover all of them.

Lastly let me note again for now that the attached scenarios are NOT COMPATIBLE with your current public build. You'll have to wait ever so briefly until 1.06 is released very soon! :)

But once you have it, you'll find there is one base scenario that the tutorial starts with, and one completed one that has everything setup and which you can reference in case something doesn't work, as well as a txt document with the scripts.

The video features time links to the parts that cover specific scripts in the description (hit show more) in case my excessive talking bores you and at the start in the video itself.

One important thing to note about the scripts as they are used in this tutorial is that if a unit dies and is then called upon in a script, there will be an error and any units after it in the script wont get their command. So if going exactly by this tutorial, try to think about whether a unit might die or not before the Lua event is executed.

One possible workaround example is posted by Baloogan here: http://forum.baloogancampaign.com/viewt ... ?f=10&t=87
Attachments
LuainCom..torial2.zip
(182.65 KiB) Downloaded 114 times
My Scenarios and Tutorials for Command

(Scenarios focus on air-warfare :) )
GlassHoppa
Posts: 21
Joined: Tue Dec 16, 2014 2:02 pm

RE: Lua in Command tutorial 2

Post by GlassHoppa »

Tomcat:

Thank you very much for this tutorial, really going in-depth on what LUA can do for our scenarios. I thought that your using the "side points" and moving markers in and out of target areas were especially ingenious ways of triggering events.

Question - can you use persistent values with ScenEdit_SetKeyValue()/ ScenEdit_GetKeyValue() ? By persistent, I mean between events.... Event A fires, stores a value, once value gets big enough it triggers Event B.. Same way that you are using the side points.

Thanks again!
User avatar
Gunner98
Posts: 5881
Joined: Fri Apr 29, 2005 12:49 am
Location: The Great White North!
Contact:

RE: Lua in Command tutorial 2

Post by Gunner98 »

Tomcat:

Very helpful and very clear, many clever ideas planted. Thanks a bunch, now its just a matter of biding our time until we can unleash this new capabilities on unsuspecting players out there [:D]

B
Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
ckfinite
Posts: 208
Joined: Fri Jul 19, 2013 10:33 pm

RE: Lua in Command tutorial 2

Post by ckfinite »

See: http://commandlua.github.io/#ScenEdit_SetKeyValue

The lua state also persists between events but is lost when the scenario is reloaded, whereas the key storer is not.
DeSade
Posts: 155
Joined: Mon Mar 01, 2004 5:08 pm
Contact:

RE: Lua in Command tutorial 2

Post by DeSade »

ORIGINAL: GlassHoppa

Question - can you use persistent values with ScenEdit_SetKeyValue()/ ScenEdit_GetKeyValue() ? By persistent, I mean between events.... Event A fires, stores a value, once value gets big enough it triggers Event B..

I would add to ckfinite answer that mentioned persistent values can be used by different events, but cant trigger event by themselves - at least not in current build imho
GlassHoppa
Posts: 21
Joined: Tue Dec 16, 2014 2:02 pm

RE: Lua in Command tutorial 2

Post by GlassHoppa »

Thank you ckfinite and DeSade (nice nick...)! Yeah, now that I have 1.06 loaded up it's pretty obvious that you cant use persistent values to trigger events. At least not directly, what I can see doing is nesting the PersistentKeyValue check within an action:

"if TRIGGER then ACTION"

where the ACTION is a luascript:

"If(PERSISTENTKEY>VALUE) then (DO SOMETHING)'.

Lots of experimentation ahead! [:)] Another question, perhaps answered before, do multiple triggers in an event have an "AND" relationship or an "OR" relationship?

Tomcat84
Posts: 1952
Joined: Wed Jul 10, 2013 5:13 pm

RE: Lua in Command tutorial 2

Post by Tomcat84 »

for now multiple triggers always have an OR relation ship in the event editor. Request for more is known to the devs. If you can find common ground in one trigger then you can use and or and if stuff in the actual lua script.
My Scenarios and Tutorials for Command

(Scenarios focus on air-warfare :) )
GlassHoppa
Posts: 21
Joined: Tue Dec 16, 2014 2:02 pm

RE: Lua in Command tutorial 2

Post by GlassHoppa »

Thanks for the quick reply! Patience in all things, I'm very happy with 1.06 so far and can certainly wait for "AND", "XOR", etc [:'(]
User avatar
snowburn
Posts: 188
Joined: Mon Sep 23, 2013 9:10 pm
Location: Bovril, Argentina

RE: Lua in Command tutorial 2

Post by snowburn »

is any way to get the GUID of the aircrafts/boats attached to a parent unit?
i need something like this (random proficiency for each a/c) :


arr_unit=get_uid_child_units('airbase1')
for index, unit_id in ipairs(arr_unit) do
ScenEdit_SetUnit ({unit_id, proficiency = math.random(0, 4) })
end
Post Reply

Return to “Mods and Scenarios”