Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

AssignedBase

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> AssignedBase Page: [1]
Login
Message << Older Topic   Newer Topic >>
AssignedBase - 4/19/2021 7:09:11 PM   
Parel803

 

Posts: 385
Joined: 10/10/2019
From: Netherlands
Status: offline
Good evening,

Is there a way to give a home base to an A/C when initiated in air via AddUnit? Wanna make a ferry mission with an A/C already on its way but not having the closest Airfield as homebase.
If it's already on the forum please direct me in the right direction, could not find it.

with regards Gert-Jan
Post #: 1
RE: AssignedBase - 4/22/2021 10:37:22 AM   
jkgarner

 

Posts: 150
Joined: 4/30/2020
Status: offline
To assign a base upon creation of an aircraft you use the base attribute.

As an example I have included some of my Lua code that does this...

Assuming you have the side ('USA') and the bases already defined (imported or manually created), the following code first defines how many of which aircraft I want at my bases (in this case 'Elmendorf AFB/JBER'), then it create the specified number of aircraft at the specified base. To create more aircraft at other locations, just add records to the aircraft table.

Hat's off to Rory Noonan, who got me started down this automated path of creation... (this code was largely lifted from his code):
local aircraftTable = {
    {side='USA', type='Aircraft', name='Sunliner', dbid=4118, base='Elmendorf AFB/JBER', quantity=6,},
    {side='USA', type='Aircraft', name='Champion', dbid=4325, base='Elmendorf AFB/JBER', quantity=4,},
}

for k,v in ipairs (aircraftTable) do
	for i = 1, v.quantity do
		ScenEdit_AddUnit({
			side=v.side,
			type=v.type,
			name=v.name..' #'..i,
			dbid=v.dbid,
			base=v.base,
			loadoutID = 3,
		})
	end
end
Good luck.

(in reply to Parel803)
Post #: 2
RE: AssignedBase - 4/22/2021 5:36:04 PM   
Parel803

 

Posts: 385
Joined: 10/10/2019
From: Netherlands
Status: offline
Thank you for your answer and time. Gonna try this evening.

Just an addon question: this initiates A/C on a base? I like to give a homeplate when a initiate a A/C (via LUA) already in the air. This to make that base the originating AF for an 'ferry' mission. Now it looks like it chooses the closest AF(hope it makes some sense).
I see a destination AF in the mission but not the originating.

with regards Gert-Jan

< Message edited by Parel803 -- 4/22/2021 5:40:41 PM >

(in reply to jkgarner)
Post #: 3
RE: AssignedBase - 4/24/2021 1:55:38 AM   
KnightHawk75

 

Posts: 984
Joined: 11/15/2018
Status: online
quote:

ORIGINAL: Parel803

Thank you for your answer and time. Gonna try this evening.

Just an addon question: this initiates A/C on a base? I like to give a homeplate when a initiate a A/C (via LUA) already in the air. This to make that base the originating AF for an 'ferry' mission. Now it looks like it chooses the closest AF(hope it makes some sense).
I see a destination AF in the mission but not the originating.

with regards Gert-Jan

Gert-Jan,
jkgarner's example is fine, but as you noted it's for inserting into a base, not assigning a home base during in-air\at-sea creation. To do the home base assignment mid-air or mid-sea etc do the following:

1. Get the base object you want to assign\reassign to be "home base" in while it's in the air.
2. Create the unit
3. Assign the actual base unit object to the unit.base property, it will assign\resign it as it's home-base now.
or
1. Create the unit
2. Use ScenEdit_SetUnit({guid=somenewunit.guid,base=GUID_OFTHE_HOMEBASE_HERE});

local somebase = ScenEdit_GetUnit({name='Blue__SUA__1', guid='4FH7PU-0HM86KFITJL3F'});
local somenewunit = ScenEdit_AddUnit({side='Blue', type='Aircraft', name='Raptor #22', dbid=4875,
 latitude='29.8843979404608', longitude='-98.8596697171624',altitude="40,000 FT",loadoutid=27862});
somenewunit.base = somebase;

--or..
local somenewunit = ScenEdit_AddUnit({side='Blue', type='Aircraft', name='Raptor #22', dbid=4875,
 latitude='29.8843979404608', longitude='-98.8596697171624',altitude="40,000 FT",loadoutid=27862});
ScenEdit_SetUnit({guid=somenewunit.guid,base="4FH7PU-0HM86KFITJL3F"});


< Message edited by KnightHawk75 -- 4/24/2021 2:08:14 AM >

(in reply to Parel803)
Post #: 4
RE: AssignedBase - 4/24/2021 6:58:57 AM   
Parel803

 

Posts: 385
Joined: 10/10/2019
From: Netherlands
Status: offline
jkgarner and KnightHawk75,
thanks for your time and answers, much appriciated.
with regards GJ

(in reply to KnightHawk75)
Post #: 5
RE: AssignedBase - 4/25/2021 10:01:53 AM   
jkgarner

 

Posts: 150
Joined: 4/30/2020
Status: offline
@KnightHawk,

I have been unable to create an Aircraft mid-flight. At the base, yes (as demonstrated). But any other combination I've tried fails to create.

In the following code, I create he aircraft at the base and then attempt to put it in the air.

ScenEdit_AddSide({name='USA'})
ScenEdit_AddUnit({side='USA', type='Facility', name='Elmendorf AFB/JBER', 
                  dbid=430, latitude='N61.15.05', longitude='W149.48.23'})
ScenEdit_AddUnit({side='USA', type='Facility', name='Randolph AFB/JBSA', 
                  dbid=430, latitude='N29.26.56', longitude='W098.26.56'})

--add aircraft to base directly...
ScenEdit_AddUnit({
    side='USA',
    type='Aircraft',
    name='Supply #1',
    dbid=485,
    base='Randolph AFB/JBSA',
    loadoutID = 3,
})

--create ferry mission
local mission = ScenEdit_AddMission('USA','Ferry Supplies to JBER','ferry',
                                    {destination='Elmendorf AFB/JBER'})
ScenEdit_SetMission('USA','Ferry Supplies to JBER', 
     {isActive=true, 
      ferryMission={FerryBehavior=1, 
                    FerryThrottleAircraft='Cruise', 
                    FlightSize=1, 
                    MinAircraftReq=1, 
                    UseFlightSize=true
     }})
--add aircraft to mission and set it in motion...
local ferryAC = ScenEdit_GetUnit({side='USA', name='Supply #1'})
if ferryAC ~= nil then
    ScenEdit_SetLoadout({UnitName='Supply #1', LoadoutID=3, TimeToReady_Minutes=0})
    ScenEdit_AssignUnitToMission(ferryAC.guid, mission.guid)
    ScenEdit_SetUnit({ side='USA',
                       name='Supply #1', 
                       latitude='N55.0.0', 
                       longitude='W125.0.0', 
                       throttle='Cruise', 
                       altitude=9000, 
                       heading=300,
                    })
end

I suspect I am missing something, but I could not ferret it out by looking at the documentation.

If you could kindly provide a small example of creating an aircraft mid-flight, I would appreciate it.

Thanks.

(in reply to Parel803)
Post #: 6
RE: AssignedBase - 4/25/2021 5:42:19 PM   
Parel803

 

Posts: 385
Joined: 10/10/2019
From: Netherlands
Status: offline
Good evening,
I realise I'm embryotic in the LUA and ask a lot. This is what I got and realizing there be a better way to do it. But for now it seems to do what I intended with you're help offcourse.

-- Ferry mission for Civilian Side
local Side = 'Civilian'
local TypeM= 'Ferry'
local FB = 1
local homebase1 = ScenEdit_GetUnit({name='EHAM AMS Amsterdam-Schiphol-AP', guid='veva-AF-EHAM'}); -- Deze al in scen
-- Add & Set Mission
ScenEdit_AddMission(Side, 'EHAM_EBBR', TypeM, {destination='veva-AF-EBBR'})
ScenEdit_SetMission(Side, 'EHAM_EBBR', {FerryBehavior=FB, FlightSize=1, UseFlightSize=false, FerryThrottleAircraft='Cruise', FerryAltitudeAircraft='20000 ft', use_refuel_unrep=1})

-- Add A/C
local CA1 = ScenEdit_AddUnit({side=Side, type='Aircraft', name='KLM1733 #3-5544', dbid=2544, loadoutid=9948, latitude='52.1677465587661', longitude='4.7211049207814', heading=190, speed=400, altitude= '10000 ft', GuiD='EHAM_EBBR_1', autodetectable='true'})
local CA2 = ScenEdit_AddUnit({side=Side, type='Aircraft', name='c/s2 #3-5545', dbid=2544, loadoutid=9948, latitude='51.5495815867527', longitude='4.6446381228578', heading=190, speed=400, altitude= '10000 ft', GuiD='EHAM_EBBR_2',autodetectable='true'})
local CA3 = ScenEdit_AddUnit({side=Side, type='Aircraft', name='c/s3 #3-5546', dbid=2544, loadoutid=9948, latitude='51.0962090288424', longitude='4.4282243956478', heading=180, speed=300, altitude= '12000 ft', GuiD='EHAM_EBBR_3', autodetectable='true'})

-- Set AF for A/C
CA1.base = homebase1;
CA2.base = homebase1;
CA3.base = homebase1;

-- A/C to mission
ScenEdit_AssignUnitToMission('KLM1733 #3-5544','EHAM_EBBR')
ScenEdit_AssignUnitToMission('c/s2 #3-5545','EHAM_EBBR')
ScenEdit_AssignUnitToMission('c/s3 #3-5546','EHAM_EBBR')

-- Ook eenheden op AF met X tijd van ready
ScenEdit_AddUnit({side=Side, type='Aircraft', name='c/s4 #3-5547', dbid=2544, loadoutid=9948, base='veva-AF-EHAM', Guid='EHAM_EBBR_4', })
ScenEdit_SetLoadout({side=Side, unitname='c/s4 #3-5547', loadoutid=0, timetoready_minutes=10})
ScenEdit_AssignUnitToMission('c/s4 #3-5547','EHAM_EBBR')

With regards GJ
ps the AF was already in

Next for me to try is to make a A/C after taking off 'autodetectable', based on the IFF #3

< Message edited by Parel803 -- 4/25/2021 6:38:51 PM >

(in reply to jkgarner)
Post #: 7
RE: AssignedBase - 4/26/2021 5:21:47 AM   
KnightHawk75

 

Posts: 984
Joined: 11/15/2018
Status: online
I'm not sure what the question is after post#7? Are you just asking is there a better way to do that code? I mean I could nit pick it but not significantly with only 3-4 aircraft involved, though I wonder about the custom guids but I assume there is a some reason\ actual need you're using them vs auto-generated ones.

(in reply to Parel803)
Post #: 8
RE: AssignedBase - 4/26/2021 7:01:25 PM   
jkgarner

 

Posts: 150
Joined: 4/30/2020
Status: offline
@KnightHawk,
I can not speak for Parel803 in why he uses custom guids. I generally let the system generate them at will am in favor of using side and name for all interactions with the system. The issue here is that there is no guarantee that they will be the same from run to run, in fact, one could almost assume they will not be the same from run to run. This does not present an issue with the vast majority of players or even scenario generators.

I have found, however, that if you already have a database of units with a unique id field, you can use the custom guid capability to force the guids to match your already identifying field. What does this gain you? Well, one could argue that it give you slightly faster access to the unit, but in my mind, it makes the code far less readable. Also debugging can be harder, as you must link the unique number to a name, anyway.

Not that this matters for most users of Command. Few have such a database.

(in reply to KnightHawk75)
Post #: 9
RE: AssignedBase - 4/27/2021 11:32:43 AM   
Parel803

 

Posts: 385
Joined: 10/10/2019
From: Netherlands
Status: offline
Thank you for you help and thoughts
with regards GJ

(in reply to jkgarner)
Post #: 10
RE: AssignedBase - 4/27/2021 11:14:36 PM   
KnightHawk75

 

Posts: 984
Joined: 11/15/2018
Status: online
@jkgarner. Of course the auto-guids may not be the same from run to run (especially not machine to machine), kind of the point. I've certainly have used custom guid's before, but only where there is no other viable choice or where the alternate choice adds complexity otherwise easily avoided with a custom guid. Again, I assume the user has his reasons, if not, I recommend avoiding custom-guids unless otherwise needed.

As for guid vs name vs side+name readability is up to each person, and the nature of what's being written.
I generally always use Guid-only where possible when I have it. This is for several reasons, most of all because it avoids the duplicate unit name problem, but also because it is faster in more complex scenes, and a little less code\param passing. The ambiguous name issue has come up enough over the years here in the forums causing problems that it's worth noting for those newer to things.

As for perf, it's not just that guid is checked first, it's the nature of the search that is performed. It depends on the function being called, but for example SE_GetUnit({guid=""}) in CMO does a ActiveUnits[guid] ref on the dictionary, where as name+side does a for each and string compare on every unitname on the side till first match is found. SetLoadout works similarly (first checking the unitname against guid\key get) but then falls back to do a foreach on every unit in the scene when guid\key is not found by direct index, AssignUnitToMission is the same. So I always avoid name+side when possible (it's not always) where performance is a concern, particularly say when doing something heavy in terms of number of calls in tighter time frames or larger loops, especially in larger scenes.


The simple sample in #4 where I actually use a string 'guid' vs obtaining it first... it's just a sample, its up to reader obviously how they obtain the unit(1), or guid in option (2), it wasn't meant to show 'use hardcoded customguid here', even if one technically can. For example if were to rewrite the above I might do something like as follows if custom guids were not actually needed, and since I already have the unit and mission guids from earlier calls I would use them in later calls, also makes minor changes for easier copy+pasta+change or converting to func little easier later, but as I mentioned it would just be nit picking\personnel perf.

-- Ferry mission for Civilian Side
local Side = 'Civilian';
local TypeM= 'Ferry';
local FB = 1;
local homebase = ScenEdit_GetUnit({name='EHAM AMS Amsterdam-Schiphol-AP', side=Side}); -- Deze al in scen
local missionname = "EHAM_EBBR";
local missiondest = "veva-AF-EBBR";
local u; --hold last united generated, reused.
-- Add & Set Mission
local m = ScenEdit_AddMission(Side, missionname, TypeM, {destination=missiondest});
ScenEdit_SetMission(Side, m.name, {FerryBehavior=FB, FlightSize=1, UseFlightSize=false, 
    FerryThrottleAircraft='Cruise',FerryAltitudeAircraft='20000 ft', use_refuel_unrep=1});
-- Add A/C,set base,set mission
u = ScenEdit_AddUnit({side=Side, type='Aircraft', name='KLM1733 #3-5544', dbid=2544, loadoutid=9948,
        latitude='52.1677465587661', longitude='4.7211049207814', heading=190, speed=400, altitude= '10000 ft',
        autodetectable='true'});
u.base = homebase;
ScenEdit_AssignUnitToMission(u.guid,m.guid); --we have the guids so use it.

u = ScenEdit_AddUnit({side=Side, type='Aircraft', name='c/s2 #3-5545', dbid=2544, loadoutid=9948,
        latitude='51.5495815867527', longitude='4.6446381228578', heading=190, speed=400, altitude='10000 ft',
        autodetectable='true'});
u.base = homebase;
ScenEdit_AssignUnitToMission(u.guid,m.guid);

u = ScenEdit_AddUnit({side=Side, type='Aircraft', name='c/s3 #3-5546', dbid=2544, loadoutid=9948,
        latitude='51.0962090288424', longitude='4.4282243956478', heading=180, speed=300, altitude= '12000 ft',
        autodetectable='true'});
u.base = homebase;
ScenEdit_AssignUnitToMission(u.guid,m.guid);

-- Ook eenheden op AF met X tijd van ready
u = ScenEdit_AddUnit({side=Side, type='Aircraft', name='c/s4 #3-5547', dbid=2544, loadoutid=9948, base='veva-AF-EHAM'});
ScenEdit_SetLoadout({unitname=u.guid, loadoutid=0, timetoready_minutes=10}); --have the guid so use it.
ScenEdit_AssignUnitToMission(u.guid,m.guid); --have the guid so use it.
u,m = nil,nil; --cause I'm a-nal like that.


< Message edited by KnightHawk75 -- 4/27/2021 11:15:07 PM >

(in reply to jkgarner)
Post #: 11
RE: AssignedBase - 4/28/2021 12:43:49 AM   
jkgarner

 

Posts: 150
Joined: 4/30/2020
Status: offline
Thanks for the info; the performance thing is something I need to look into.

How does performance compare between self generated guid vs custom guids?

I expect I will need to rework my Lua Library to rely on guids rather than side/name pairs.

But not right now... I have bigger fish to fry.



(in reply to KnightHawk75)
Post #: 12
RE: AssignedBase - 4/28/2021 7:10:34 AM   
Parel803

 

Posts: 385
Joined: 10/10/2019
From: Netherlands
Status: offline
thanks for your time and advices, I'll check it all out this evening.
with regards GJ

(in reply to jkgarner)
Post #: 13
RE: AssignedBase - 4/28/2021 5:15:20 PM   
KnightHawk75

 

Posts: 984
Joined: 11/15/2018
Status: online
quote:

how does performance compare between self generated guid vs custom guids?


It shouldn't matter much, I mean I've not literally tested custom vs auto when it comes to perf, but in theory it should act no different perfwise than auto generated guids for the most part, certainly when it comes to routines that do the dic[guid] key attempt first.

(in reply to jkgarner)
Post #: 14
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> AssignedBase Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

0.195