Assign new home base by LUA?

Post bug reports and ask for game support here.

Moderator: MOD_Command

Post Reply
chrispman
Posts: 162
Joined: Sun Mar 28, 2010 2:29 pm

Assign new home base by LUA?

Post 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!


Rory Noonan
Posts: 2418
Joined: Thu Dec 18, 2014 1:53 am
Location: Brooklyn, NY

RE: Assign new home base by LUA?

Post 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.
Image
User avatar
michaelm75au
Posts: 12457
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: Assign new home base by LUA?

Post by michaelm75au »

Lookup Command http://commandlua.github.io/beta/index. ... itToParent
Function is ScenEdit_HostUnitToParent()
Michael
Rory Noonan
Posts: 2418
Joined: Thu Dec 18, 2014 1:53 am
Location: Brooklyn, NY

RE: Assign new home base by LUA?

Post 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
Image
chrispman
Posts: 162
Joined: Sun Mar 28, 2010 2:29 pm

RE: Assign new home base by LUA?

Post by chrispman »


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

chrispman
Posts: 162
Joined: Sun Mar 28, 2010 2:29 pm

RE: Assign new home base by LUA?

Post by chrispman »

I'm afraid that doesn't work for me, or I'm doing something wrong:



Image
Attachments
ReBase.jpg
ReBase.jpg (648.11 KiB) Viewed 144 times
mikmykWS
Posts: 7185
Joined: Tue Mar 22, 2005 4:34 pm

RE: Assign new home base by LUA?

Post 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



wgarlick
Posts: 1
Joined: Sun Dec 04, 2016 12:57 pm

RE: Assign new home base by LUA?

Post 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.
User avatar
michaelm75au
Posts: 12457
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: Assign new home base by LUA?

Post 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
Michael
chrispman
Posts: 162
Joined: Sun Mar 28, 2010 2:29 pm

RE: Assign new home base by LUA?

Post by chrispman »


Thanks for looking into this!

User avatar
Hestia
Posts: 22
Joined: Tue Feb 28, 2017 10:11 am

RE: Assign new home base by LUA?

Post 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?
User avatar
michaelm75au
Posts: 12457
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: Assign new home base by LUA?

Post by michaelm75au »

Correct.
Michael
Post Reply

Return to “Tech Support”