Is there a way.....?

All discussions & material related to Command's Lua interface

Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command

Post Reply
DWReese
Posts: 2469
Joined: Fri Mar 21, 2014 11:40 am
Location: Miami, Florida

Is there a way.....?

Post by DWReese »

I like to create scenarios that uses randomization. In my mind, the enemy forces (computer-controlled) may be augmented by a random result and tele-ported in at the start of the scenario. Therefore, you (as the game player) would never know exactly what forces that you are facing. I know how to do this. But, here's a twist.....

What if I had various hangers of planes (similar to what is already on the base) and I had them (possibly) tele-ported to the base's location? Notice, I didn't say into the base. That's the problem. If I transport these to the location, then they still aren't actually ON the base itself.

So, is there a way to GROUP or INCORPORATE the newly transported hanger of aircraft INTO the base, so that it would be able to become part of the base WITHOUT ME actually doing it? (Otherwise, it would be useless.) I do realize that I could do this MANUALLY, but as a game player who is playing against the computer, I would like the computer to do it without my knowledge. I assume that, if it could be done, this would require some LUA coding, but I don't know too much about that.

If this is possible, and someone knows how to do it, could they please provide a DETAILED example (i.e. sample code) that I could essentially use as a guide to adapt to my own scenario to perform this function?

I do believe that this is an interesting and useful concept, if it can be done.

Thanks in advance.

KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: Is there a way.....?

Post by KnightHawk75 »

Entirely possible.
In the event, after the teleport action, add a second action of lua script action.
Then for each teleported unit get unit and assign it to related airbase group name (unit.group="airbase unit name").

Or ditch the whole pre-made + teleport unit thing (unless for some reason you really need it) and just script the actual creation of units at the base with certain dice rolls generating certain units and loadouts (and hangers if needed) or not as the case may be.

Post in the lua section specifically what you want and I'll dummy up a sample for it.

As is I'm interpreting what you wrote as say 4 different "packages" of units to be possible at a set airbase and say a 25% chance each time you play of one of those 4 being chosen and applied to the base, is that the sort of sample you want? Do you want each and every unit to have a random chance of appearance at the base? Should generated units also be assigned to missions etc...type of things I mean when I says post specifically what you want in the sample.
DWReese
Posts: 2469
Joined: Fri Mar 21, 2014 11:40 am
Location: Miami, Florida

RE: Is there a way.....?

Post by DWReese »

Wow! Thank you for responding. Thank you for the offer.

Planes to add:

Up to a maximum of 6, coming in increments of 2 (if possible). If not, one is fine, and one is probably more realistic anyway.

The plane(s) to add is the Chinese J-11BSH Flanker C (#4449 in the database)

The call signs (if needed) would be Argonaut 9, 10, 11, 12, 13, 14, etc.)

The Load Out would be Standard CAP (6 PL 12, and 2 PL-8B) The ID is #22439. They all have the same Loadout.

I would prefer to have them in Hangers that could hold 2 Large Aircraft (18.1-26m Long) The hangers can be created new, if necessary, or I do have existing space in existing hangers. Whatever is easier.

The mission is Fiery Cross CAP 1 (AA Patrol).

The 25 percent appearance-thing is fine. I can adjust it as needed. And, yes, each unit should have the same chance of appearing. So, I might get the first (Argonaut 11), and the fourth (Argonaut 14), when everything is complete, if it works that way.

Hopefully, I addressed all of you questions.

Thanks again for doing this. I really find this to be very interesting.
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: Is there a way.....?

Post by KnightHawk75 »

Gotcha thanks, should be enough to whip up a sample scene up for you that you can adjust\learn from.
DWReese
Posts: 2469
Joined: Fri Mar 21, 2014 11:40 am
Location: Miami, Florida

RE: Is there a way.....?

Post by DWReese »

Thank you so much.

Please just work on this when it is convenient for you. There is no rush. I'm not in any hurry, so please don't put yourself out in any way.

Thanks again.
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: Is there a way.....?

Post by KnightHawk75 »

Attached is a RandomHangerAddDemo.scen using db486 - Load it and select Red.

On Scene load it will...

Check if the hanger generation has run before or not (ie if someone started and saved the file previously), if it has not run it will run, if it has run it will skip it.

If it runs it will run though 6 possible hanger locations, for each one there is a 25% change it will generate the hanger (up to 3 hanger max) and assign the hanger to the base named Red_Airbase. For each generated hanger it will put 2 of the specified fighters in that hanger, give it the specified load-out (regardless of if munitions exist at the base yet), mark them both 'ready', and assign it to a mission 'Fiery Cross CAP 1'. Then mark itself as having run regardless of how many if any have been generated.

The Red_Airbase is just a sample existing airbase group so you can switch between group and single view and see the new stuff is added to the base.

At the top of the GlobalStartupScript action script there are values you can use to easily adjust a few things.
Such as:
gKH.SceneGlobals.PerHangerChancePct = 25; --percent chance for each hanger.
gKH.SceneGlobals.RedbaseHangerMax = 3; --cap at 6 aircraft.

There are others with comments to let you know how they are used.
Obviously you'll need to change the lat\lon info in the gKH.SceneGlobals.Redbase1Hangers table at the top of the script for your actual usage in another scene.
If you need to change the dbid for the hanger (41) it's in gKH.CreateHangerUnitPackage function
If you need to change the dbid,loadout etc of the aircraft it's in DoRandomHangerGeneration function.
There is a special action on red side, you can use while testing and reset the special run-once marker if you save a file after it's run. If you just want to see different random runs, don't save and just keep reopening the file you should get relatively different results each time.
There is only minimal error checking in the routines, so make sure things like lat\lon you change are actually on land etc, but a few things are logged to \logs\luahistory-date-.txt, like hitting the max, generation already having been done, the random numbers generated,etc. If you have any questions to how something works or don't understand a piece of the code, feel free to ask.

Attachments
RandomHangerAddDemo.zip
(15.72 KiB) Downloaded 23 times
DWReese
Posts: 2469
Joined: Fri Mar 21, 2014 11:40 am
Location: Miami, Florida

RE: Is there a way.....?

Post by DWReese »

Thank you so much for the detailed explanation.

I intend on working on it tomorrow. This is exactly what I had hoped to do.

You are a genius.

Thanks again.
jkgarner
Posts: 175
Joined: Thu Apr 30, 2020 12:42 pm

RE: Is there a way.....?

Post by jkgarner »

@KnightHawk75:

I am just interested in the Lua script to do that... (I can not read your commercial scenarios in my version) How about throwing just the script out?

That would be execellent!

Thanks
[8D]
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: Is there a way.....?

Post by KnightHawk75 »

@jkgarner

Sure, it's nothing fancy, script attached to place in startup event. I think everything used should work in the pro version.





Attachments
RandomHangerAddDemo.txt
(6.62 KiB) Downloaded 27 times
Post Reply

Return to “Lua Legion”