Lua in Command tutorial 2 (Full Version)

All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios



Message


Tomcat84 -> Lua in Command tutorial 2 (12/8/2014 7:04:50 PM)

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/viewtopic.php?f=10&t=87




GlassHoppa -> RE: Lua in Command tutorial 2 (12/16/2014 5:40:38 PM)

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!




Gunner98 -> RE: Lua in Command tutorial 2 (12/16/2014 11:20:00 PM)

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




ckfinite -> RE: Lua in Command tutorial 2 (12/17/2014 5:27:47 PM)

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 -> RE: Lua in Command tutorial 2 (12/17/2014 5:51:20 PM)


quote:

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 -> RE: Lua in Command tutorial 2 (12/17/2014 9:04:55 PM)

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 -> RE: Lua in Command tutorial 2 (12/17/2014 9:14:51 PM)

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.




GlassHoppa -> RE: Lua in Command tutorial 2 (12/17/2014 9:31:26 PM)

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 [:'(]




snowburn -> RE: Lua in Command tutorial 2 (12/18/2014 10:19:54 PM)

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




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
2.5