Page 1 of 1
Reassign aircraft to different base then takeoff
Posted: Sun Dec 13, 2020 12:20 pm
by PastBehavin
What is the correct LUA script to use to reassign an aircraft or group of Aircraft to a different base than they takeoff from?
Trying the following format doesn't change the assigned base
ScenEdit_SetUnit({unitname= "AIRCRAFT NAME", side= "Blue", base="Anderson"})
I've also replaced the base name with the 'guid' string to no avail.
RE: Reassign aircraft to different base then takeoff
Posted: Sun Dec 13, 2020 3:00 pm
by boogabooga
I believe that the base needs to be input as a "Unit" type, not a string, so you need to nest another "{}" with the relevant characteristics.
Try:
Code: Select all
ScenEdit_SetUnit({unitname= "AIRCRAFT NAME", side= "Blue", base= {unitname="Anderson", side= "Blue"} })
RE: Reassign aircraft to different base then takeoff
Posted: Sun Dec 13, 2020 5:32 pm
by PastBehavin
Thanks, that makes some sense and will try it
RE: Reassign aircraft to different base then takeoff
Posted: Tue Dec 15, 2020 7:46 am
by KnightHawk75
ORIGINAL: PastBehavin
What is the correct LUA script to use to reassign an aircraft or group of Aircraft to a different base than they takeoff from?
Trying the following format doesn't change the assigned base
ScenEdit_SetUnit({unitname= "AIRCRAFT NAME", side= "Blue", base="Anderson"})
I've also replaced the base name with the 'guid' string to no avail.
You can do it just as you are trying, my guess is you have typo\case-sensitivity issue or you have ambiguous names on side "Blue". As for using a guid for base=, that's a documentation error| or long-standing-bug atm.
How to change a units base:
If it's airborne.
2 ways:
1. Get the airbase in question, then assign that wrapper to the aircraft's unitwrapper .base property.
Code: Select all
local myairport = SE_GetUnit({name='Red_AirBaseGroup2', guid='4FH7PU-0HM504GOL2OE2'});
local myunit = SE_GetUnit({name='Stinger #2', guid='4FH7PU-0HM504GKUQND7'})
print('original base guid:' .. tostring(myunit.base.guid) .. ' originalbase name: ' .. tostring(myunit.base.name))
myunit.base = myairport;
print('new base guid:' .. tostring(myunit.base.guid) .. ' new name: ' .. tostring(myunit.base.name))
2. Use SetUnit spelling out the correct unit to operate on and the case-sensitive base name.
Code: Select all
--cleanest example
SE_SetUnit({guid='4FH7PU-0HM504GKUQND7',base="Red_AirBaseGroup2"});
-- next best, making SURE side and unitname match EXACTLY, and that you do not have ambiguous unit names.
-- What does that mean? It means two or more units on the same side with the same exact names
-- which can make lookup fails because it doesn't know which one you intended.
SE_SetUnit({side='Red',unitname='Stinger #2',base='Red_AirBaseGroup2'});
If you want to insert the unit into another base (because it's on the ground already), or even if it's actively flying do the following.
Code: Select all
--SourceUnitGuid first, DestinationGuid second.
--The following inserts "Stinger #2" from above examples into Red_AirBaseGroup2 from above REGARDLESS of if it's in the air or not.
ScenEdit_HostUnitToParent({HostedUnitNameOrID = "4FH7PU-0HM504GKUQND7", SelectedHostNameOrID = "4FH7PU-0HM504GOL2OE2"});
What's the error you're getting? Is it descriptive or is it like object ref not set to value?
RE: Reassign aircraft to different base then takeoff
Posted: Tue Dec 15, 2020 8:03 am
by PastBehavin
Knighthawk75
Thanks so much for the very thorough answer and especially the ability tp reassign while airborne. I stiill have a ways to go on the learning curve and this is extremely helpful
Regards
Bill
RE: Reassign aircraft to different base then takeoff
Posted: Tue Dec 15, 2020 10:12 am
by KnightHawk75
ORIGINAL: PastBehavin
Knighthawk75
Thanks so much for the very thorough answer and especially the ability tp reassign while airborne. I stiill have a ways to go on the learning curve and this is extremely helpful
Regards
Bill
Cool, did you get it working or are you still having an problem with the name\side method?
If you're getting a non-descriptive error like "object not set to instance of object" vs an actual human sort of error, that's usually when the name is wrong but the side is right, for whatever reason it throws a null argument exception at the end of checking\comparing against all unit names when it's not found, I think they got a line of code in there somewhere that probably assumes the lookup found the unit, but when it doesn't it bombs.
BTW the reason I mention preferring {guid="xxxxxx"} where you can, besides avoiding the naming conflict issue, it's faster since the name lookup runs through every object in the game looking for name match before the side match, and also checks if the 'name' matches a 'guid' (which is kinda of nice) but it's potentially 2x the number of compare operations, not a big deal when dealing with a couple hundred units, but when you have 4k it can make a difference. [:)] Anyway hopefully you got it sorted - mainly just posting this for future reference for others.
RE: Reassign aircraft to different base then takeoff
Posted: Tue Dec 15, 2020 10:26 am
by PastBehavin
Yes, I did get it sorted out, thanks for the help!. Also your comment on utilizing the guid # vs. name makes sense but not something I ever would have thought of. Speeding up the game is always important.