Command Modern Air Naval Operations : Lua Repository 2

This is another entry in my Lua Repository for CMANO. (Find the first one here) I have a large and ungainly notepad++ document with notes, ideas, scribbles, and even a bit of Lua. To start with we’ll run down what I currently have, later we’ll look at other functions from the commandlua.github.io list and make some other examples. If you’d like to see a particular script feel free to ask in the comments and I can see what I can do!

Create a single unit in an airfield

ScenEdit_AddUnit({type = 'Air', unitname = 'F-15C Eagle', loadoutid = 16934, dbid = 3500, side = 'Mercs', base='Home'})

This script places a single air unit with a name of F-15C Eagle with a particular loadout and dbid on side mercs into an airbase called home. Unitname can be whatever you’d like. Loadoutid is what weaponry the plane will come with, you can find this either in the Database Viewer or on a site like¬†https://wiki.baloogancampaign.com/index.php/Main_Page . The DBID is a unique number for that particular aircraft, again, the DB Viewer or Baloogans Wiki. Side is whatever side you’d like and the base is the name of the airbase they’ll go to.

 

ScenEdit_AddUnit({type = 'Air', unitname = 'JAS-39C Gripen', loadoutid = 17279, dbid = 3226, side = ScenEdit_PlayerSide(), base='Home'})

This is a neat addition, we can add another function right inside of this script and it will create a unit on whatever side we’re currently playing.

Create Multiple Aircraft

for planes = 1, 8, 1 do
ScenEdit_AddUnit({type = 'Air', unitname = 'JAS-39C Gripen', loadoutid = 17279, dbid = 3226, side = 'Mercs', base='Home'})
end

One plane is the loneliest plane! With this script we can make a group of 8 Gripens. But wait, they all have the same name! (Trust me, this can make it a pain down the road).

for planes = 1, 8, 1 do
ScenEdit_AddUnit({type = 'Air', unitname = 'JAS-39C Gripen #'..planes, loadoutid = 17279, dbid = 3226, side = 'Mercs', base='Home'})
end

This script will make 8 Gripens and sequentially order them.

Set Loadouts to be Immediately Ready

This one came about when I made the Hired Goons scenario and wanted the player to be able to select a loadout. Normally you’d have to wait 6 hours or so to have it all loaded.

ScenEdit_SetLoadout({UnitName = "F-15C Eagle", LoadoutID = 0, TimeToReady_Minutes = 0, IgnoreMagazines = 1})

Remember when I said having all the planes with the same name was bad? Say we wanted to do that for a bunch of planes with identical names, now we have problems.

for i=1,6 do ScenEdit_SetLoadout({UnitName = "Ghostrider #"..i, LoadoutID = 0, TimeToReady_Minutes = 0, ignoremagazines = 1}) end

This script will run through a list of 6 planes named Ghostrider and set them all to ready. You could use this same method to change loadouts across the board.

Swap Unit Side

ScenEdit_SetUnitSide({side='Opfor', name='airfield', newside='Blufor'})

This script swaps a unit from one side to another. Useful for changing airbase ownership or creating a “traitor” or defector unit.

Randomly Create and Delete Units

math.randomseed(os.time())
math.random()

a = math.random(1,3)

print(a)

if a == 1 then

ScenEdit_DeleteUnit({name="Radar (China JY-8A Wall Rust)", base="Lhasa Gonggar International Airport"})
print("The Radar Blew Up!")

elseif a == 2 then

ScenEdit_DeleteUnit({name="Radar (China JY-8A Wall Rust)", base="Lhasa Gonggar International Airport"})
ScenEdit_AddUnit({type="land", side="China", name="AAA Sec (35mm/90 Type 90 x 2) (2x)", dbid=1682, latitude="29.297778", longitude="90.911944"})
print("The Radar Blew up! But you detect AAA radar firing up...")

elseif a == 3 then

ScenEdit_AddUnit({type="land", side="China", name="AAA Sec (35mm/90 Type 90 x 2) (2x)", dbid=1682, latitude="29.297778", longitude="90.911944"})
ScenEdit_AddUnit({type="land", side="China", name="AAA Sec (35mm/90 Type 90 x 2) (2x)", dbid=1682, latitude="29.304571450518", longitude="90.8938412514606"})
print("The mercs cut a sewage line and alerted the base. You detect AAA radar firing up...")

end

This one is really cool and offers a ton of functionality. It takes one of three potential outcomes and then either creates or deletes some units. The print line will only show up in the Lua Console. In order to have the message displayed to the players you need to use :

ScenEdit_MsgBox ("test", 1)

By having all of your scripts be slightly random you can add a ton of variance to your scenario. Maybe when one event is triggered you get a pair of F-16’s but on another playthrough you instead have to face a pair of F-22’s! Or maybe, as is the case above, once detected the hostiles are slow to fire up the AAA so instead some MANPADs come out? This can really add a ton of replay-ability.

Assign Units to a Mission

for i=1,6 do ScenEdit_AssignUnitToMission("Jas Gripen 39C #"..i, "Suicide Run") end

This script assigns six Gripen’s to a mission titled Suicide run. You can combine this with the random script above and even nest in loops so you can have the same planes picked but with a random mission assigned. Tons of variance available!

Component Damage

With Chains of War we got a much more detailed damage system. It’d be a shame not to use this beauty!

local unit = ScenEdit_GetUnit({side="Opfor", unitname="JAS-39C Gripen#1"})
print(unit)
print(unit.components)

This script first gets the unit you’re interested in and assigns the units information to a variable called unit. We then print it from the console and see all of the information stored in the variable. Now with lua we can add a “dot” to get more unit info. We could print just unit.latitude or unit.proficiency and just get one variable back. This also works for unit.components. Unfortunately the unit.components output isn’t quite as eye friendly as the unit output is.

unit {
type = 'Aircraft',
subtype = '2002',
name = 'JAS-39C Gripen #1',
side = 'Opfor',
guid = '64f8da6a-b41a-4243-b847-a4edd40ea820',
proficiency = 'Regular',
latitude = '17.4524008208578',
longitude = '-13.4127018626729',
altitude = '76',
speed = '350',
throttle = 'Loiter',
autodetectable = 'False',
base = 'Home',
mounts = '4',
magazines = '4',
unitstate = 'Unassigned',
fuelstate = 'None',
weaponstate = 'None',
}
{ [1] = { comp_type = 'Sensor', comp_guid = '940d0435-30be-4b12-a6bd-96f856c28376', comp_dbid = 664, comp_name = 'PS-05/A', comp_status = 'Operational' }, [2] = { comp_type = 'Sensor', comp_guid = '9d30cf15-7756-4b1b-adca-7c46e28c66ab', comp_dbid = 1315, comp_name = 'BOW-21', comp_status = 'Operational' }, [3] = { comp_type = 'Sensor', comp_guid = 'f144c46e-3d7b-444b-b20e-a78a025cf62a', comp_dbid = 825, comp_name = 'Generic DECM [Advanced]', comp_status = 'Operational' }, [4] = { comp_type = 'Sensor', comp_guid = 'a83ca8de-3e75-4fea-9a3f-abeee5137875', comp_dbid = 0, comp_name = 'Mk1 Eyeball', comp_status = 'Operational' }, [5] = { comp_type = 'Mount', comp_guid = 'e8fa8287-d709-4a65-9f5a-11f9f3773e63', comp_dbid = 2134, comp_name = '27mm Mauser BK-27 [120 rnds]', comp_status = 'Operational' }, [6] = { comp_type = 'Mount', comp_guid = 'e265c572-a896-4b37-9c92-dfc0a00f3039', comp_dbid = 1757, comp_name = 'BOL 451 x 2 [320 Cartridges]', comp_status = 'Operational' }, [7] = { comp_type = 'Mount', comp_guid = '173be830-bea2-4963-962b-8752a8a6efda', comp_dbid = 1692, comp_name = 'BOP/B x 2 [12 Cartridges]', comp_status = 'Operational' }, [8] = { comp_type = 'Mount', comp_guid = 'c7ee67f4-1293-48ca-a3da-35a4220379cb', comp_dbid = 1687, comp_name = 'BOY 403 x 4 [60 Cartridges]', comp_status = 'Operational' }, [9] = { comp_type = 'CommDevice', comp_guid = '652c517e-c944-4661-8a56-8476b82d0be5', comp_dbid = 187, comp_name = 'UHF/VHF Radio [Secure]', comp_status = 'Operational' }, [10] = { comp_type = 'Engine', comp_guid = '3610af22-1a75-400e-8137-50564977d79f', comp_dbid = 594, comp_name = 'F404-GE-400 RM.12 #1', comp_status = 'Operational' } }

We see all sorts of ID’s, names, and status’s. We can break each and every single one of them or start a fire! Yay! Fire!

ScenEdit_SetUnitDamage({side="Opfor", unitname="JAS-39C Gripen #1", fires=1, components={{"F404-GE-400 RM.12 #1","None"}}}) \\ Sets unit component damaged

The above script will start a light fire and repair the F404 engine. We can change none to Light, Medium or Heavy. Setting the damage to None will repair any damage immediately.

ScenEdit_SetUnitDamage({side="Opfor", unitname="JAS-39C Gripen #1", fires=0, components={{"type", type="engine",2}}})

This script is a bit different. We have no fires (0) and instead of specifying the particular engine we can define a type as the engine and set it as 2, or medium damage. If we look at our unit.components list above we see types including sensor, mount, engine, and commdevice.

Arrayed Pilot List

This one isn’t useful unless you want to name all of your pilots something original. In my case I’m running a Let’s Play where the players can request pilot names. As such it’s really a pain in the ass to go through a list of 40 pilots (186 on the wait list) and fill each one in. This way I can propagate groups of planes from the list.

arr = {"pilot x", "pilot y"}

for i,line in ipairs(arr) do
ScenEdit_AddUnit({type = 'Air', unitname = line, loadoutid = 17279, dbid = 3226, side = 'Mercs', base='Home'})
end

As a reminder always test bits of your script in the console first before adding them to the events system. Sometimes you’ll get helpful debugging information from the console that you don’t get from the event system.

Gamer, Author, Engineer, Dad.

Next ArticleThe Strategy Gamer Podcast #5 : Graviteam Tactics Mius Front