Page 1 of 1

Assign new home base by LUA?

Posted: Thu May 04, 2017 7:52 pm
by chrispman
Hi,

I was sure I read somewhere that it is possible to assign a home base to an aircraft by LUA.

But the documenation says that it's readonly:
Unit
Represents a active unit.
...
base Unit The unit's assigned base. [READONLY]
...
So I can't change the home base in mid-flight, correct?

Thanks for your help!



RE: Assign new home base by LUA?

Posted: Fri May 05, 2017 1:20 am
by Rory Noonan
There is a way, I can't remember offhand and I'm not at my computer. Have a look at the Civ_AirTrafficNight script in Seven Days in October.

I'll post up the code here in 8 hours or so, provided IRL doesn't get in the way.

RE: Assign new home base by LUA?

Posted: Fri May 05, 2017 2:51 am
by michaelm75au
Lookup Command http://commandlua.github.io/beta/index. ... itToParent
Function is ScenEdit_HostUnitToParent()

RE: Assign new home base by LUA?

Posted: Fri May 05, 2017 5:39 am
by Rory Noonan
This works:
ScenEdit_SetUnit({guid=x.guid,base=destination.name,rtb=true})

Replace destination.name with the name of your desired new base, and delete or change the rtb value as appropriate.

HostUnitToParent will instantly teleport the units to the desired new base, the code above will simply change the homebase

RE: Assign new home base by LUA?

Posted: Fri May 05, 2017 5:44 am
by chrispman

Thanks guys, I will have a go over the weekend hopefully.


RE: Assign new home base by LUA?

Posted: Wed May 10, 2017 6:16 pm
by chrispman
I'm afraid that doesn't work for me, or I'm doing something wrong:



Image

RE: Assign new home base by LUA?

Posted: Wed May 10, 2017 9:55 pm
by mikmykWS
Ok will need to look further into this.

The base value is read only and host unit function does it but also teleports it home.

Mike




RE: Assign new home base by LUA?

Posted: Wed May 10, 2017 11:28 pm
by wgarlick
For my Doolittle Raid scenario, I had to delete the carrier via event then all the B25 planes automatically changed to a base in China as their new home base. May not be ideal if you have multiple bases.

RE: Assign new home base by LUA?

Posted: Thu May 11, 2017 8:09 am
by michaelm75au
Mmmm. Always thought you could re-base a unit. I think all the times this was used, was around basing new units, rather than re-basing existing ones.
Shouldn't be too difficult to do so..probably add an option in the HostUnitToParent() to just change the base and not move, or jump as it does now. I think the default behavior will be as it is now with option to just change it.

Changed around....Simpler solution

The property .base will be able to be set to the unit object of the new base. Plus if set to 'nil', it will choose the closest base that can host it. e.g.

Code: Select all

local unit = ScenEdit_GetUnit({name='SS 583 Harushio', guid='3a5f2a57-36e2-48f6-9352-00b819789a18'})
 unit.base = ScenEdit_GetUnit({name='Naval Station Yokosuka', guid='db7d4c0c-31e8-4563-8d43-9f2b467cf977'})
 unit.base = nil

RE: Assign new home base by LUA?

Posted: Fri May 12, 2017 12:58 pm
by chrispman

Thanks for looking into this!


RE: Assign new home base by LUA?

Posted: Sat Jun 10, 2017 7:58 am
by Hestia
Sorry for bothering you, Michael. I'm new to Lua and I'm still trying to get familiarized with the syntax and parameters.
I'm trying to accomplish the same thing with a ship, but the solution you wrote for commanderchrisp's scenario does not make any sense to me.
Can you elaborate a little on how the script should look like?

Thank you!

LE: oops! just noticed someone has the same issue and opened another thread. So, if I understand correctly, the ability so set a new base for a unit through Lua is a feature for the future, right?

RE: Assign new home base by LUA?

Posted: Sat Jun 10, 2017 8:18 am
by michaelm75au
Correct.