how to create the airbase by LUA

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
hanzawa1991
Posts: 74
Joined: Tue Apr 05, 2022 9:05 am

how to create the airbase by LUA

Post by hanzawa1991 »

I want to use LUA to add a military base (or copy a complete military base), then add planes to the base, and automatically set the planes to available status. I checked the LUA manual and there is a base parameter. I set it correctly, but although I can also add planes, it always reminds me to set the altitude. The altitude, latitude and longitude parameters should be based on the base. Why do you still need to remind me?
User avatar
blu3s
Posts: 1400
Joined: Fri Jul 08, 2022 9:45 am

Re: how to create the airbase by LUA

Post by blu3s »

If you get an error that you must enter an altitude, you are not adding aircraft correctly, or there is no capacity for more aircraft.
hanzawa1991
Posts: 74
Joined: Tue Apr 05, 2022 9:05 am

Re: how to create the airbase by LUA

Post by hanzawa1991 »

blu3s wrote: Fri Mar 17, 2023 7:20 am If you get an error that you must enter an altitude, you are not adding aircraft correctly, or there is no capacity for more aircraft.
Well, how do you correctly create an air force base with planes using LUA? Can you provide an example?
User avatar
blu3s
Posts: 1400
Joined: Fri Jul 08, 2022 9:45 am

Re: how to create the airbase by LUA

Post by blu3s »

Code: Select all

function RandomFloat(min,max,escala)
	if min ~= nil and max ~= nil and escala~=nil then
		return math.random(min*(10^escala),max*(10^escala))/(10^escala)
	end
		return nil
end

local BLUE_SIDE = "RED"
local position = {latitude = 35, longitude = 100}
local airfield = { [3] = 'Control Tower (Building)', [217] = 'A/C Tarmac Space (2x Large Aircraft)', [68] = 'A/C Hangar (2x Medium Aircraft)', [353] = 'Runway Access Point (Very Large Aircraft)', [41] = 'A/C Hangar (2x Large Aircraft)', [27] = 'A/C Hardened Aircraft Shelter (1x Large Aircraft)',[198]='Very Large Hangar', [1393] = 'AvGas (200k Liter Underground Tank)', [1423] = 'Runway-Grade Taxiway (2600m)', [322] = 'Ammo Bunker (Surface)' }
local c = ScenEdit_AddUnit({type='Facility',side=BLUE_SIDE, name = "12/30 8250 ft Runway (Very Large Aircraft)", dbid=35, latitude = position.latitude, longitude=position.longitude, autodetectable=false})
c.group="Blue AB"
for k,v in pairs(airfield) do
	
	if k==3 then
		local unit = ScenEdit_AddUnit({type='Facility',side=BLUE_SIDE, name = "Tower Control", dbid=k, latitude = position.latitude-0.001, longitude=position.longitude+0.0006, autodetectable=false})
		unit.group="Blue AB"
	elseif k == 41 then
		for i=1,16 do
			local unit = ScenEdit_AddUnit({type='Facility',side=BLUE_SIDE, name = v.."#"..i, dbid=k, latitude = position.latitude+RandomFloat(0.0003,0.0007,13), longitude=position.longitude-RandomFloat(-0.002,0.004,13)+i/10000, autodetectable=false})
			unit.group="Blue AB"
		end
	elseif k==217 then --TARMAC SPACE
		for i=1,24 do
			local unit = ScenEdit_AddUnit({type='Facility',side=BLUE_SIDE, name = v.."#"..i, dbid=k, latitude = position.latitude+RandomFloat(-0.0003,0.0003,13), longitude=position.longitude-0.0036+i/10000, autodetectable=false})
			unit.group="Blue AB"
		
		end
	elseif k==353 then
		for i=1,3 do
			local unit = ScenEdit_AddUnit({type='Facility',side=BLUE_SIDE, name = v.."#"..i, dbid=k, latitude = position.latitude+RandomFloat(-0.0003,0.0003,13), longitude=position.longitude-0.0016+i/10000, autodetectable=false})
			unit.group="Blue AB"

		end
	elseif k==1393 then
		for i=1,5 do
			local unit = ScenEdit_AddUnit({type='Facility',side=BLUE_SIDE, name = v.."#"..i, dbid=k, latitude = position.latitude+0.0007, longitude=position.longitude-RandomFloat(-0.0003,0.0003,13)+i/10000, autodetectable=false})
			unit.group="Blue AB"

		end
	elseif k==198 then
		for i=1,12 do
			local unit = ScenEdit_AddUnit({type='Facility',side=BLUE_SIDE, name = v.."#"..i, dbid=k, latitude = position.latitude-RandomFloat(0.00035,0.00045,13), longitude=position.longitude-RandomFloat(0.0003,0.0009,13)+i/10000, autodetectable=false})
			unit.group="Blue AB"
		end
	elseif k==1423 then
		local unit = ScenEdit_AddUnit({type='Facility',side=BLUE_SIDE, name = v, dbid=k, latitude = position.latitude, longitude=position.longitude-0.0006, autodetectable=false})
		unit.group="Blue AB"
	elseif k==322 then
		local unit = ScenEdit_AddUnit({type='Facility',side=BLUE_SIDE, name = v, dbid=k, latitude = position.latitude+0.003, longitude=position.longitude-0.0006, autodetectable=false})
		unit.group="Blue AB"
	end
end

local dbCAP =3896
local dbLoadout = 332
for i=1,24 do
	local unit = ScenEdit_AddUnit({type='Aircraft',side=BLUE_SIDE, name = "AIRCAP #"..i, dbid=dbCAP,loadoutid=dbLoadout,base="Blue AB"})
	if i > 12 then ScenEdit_SetUnit({guid=unit.guid, TimeToReady_Minutes=1440}) end
	ScenEdit_FillMagsForLoadout({unit='BLUE AB', loadoutid=dbLoadout, quantity=48})
end
hanzawa1991
Posts: 74
Joined: Tue Apr 05, 2022 9:05 am

Re: how to create the airbase by LUA

Post by hanzawa1991 »

blu3s wrote: Fri Mar 17, 2023 12:07 pm

Code: Select all

function RandomFloat(min,max,escala)
	if min ~= nil and max ~= nil and escala~=nil then
		return math.random(min*(10^escala),max*(10^escala))/(10^escala)
	end
		return nil
end

local BLUE_SIDE = "RED"
local position = {latitude = 35, longitude = 100}
local airfield = { [3] = 'Control Tower (Building)', [217] = 'A/C Tarmac Space (2x Large Aircraft)', [68] = 'A/C Hangar (2x Medium Aircraft)', [353] = 'Runway Access Point (Very Large Aircraft)', [41] = 'A/C Hangar (2x Large Aircraft)', [27] = 'A/C Hardened Aircraft Shelter (1x Large Aircraft)',[198]='Very Large Hangar', [1393] = 'AvGas (200k Liter Underground Tank)', [1423] = 'Runway-Grade Taxiway (2600m)', [322] = 'Ammo Bunker (Surface)' }
local c = ScenEdit_AddUnit({type='Facility',side=BLUE_SIDE, name = "12/30 8250 ft Runway (Very Large Aircraft)", dbid=35, latitude = position.latitude, longitude=position.longitude, autodetectable=false})
c.group="Blue AB"
for k,v in pairs(airfield) do
	
	if k==3 then
		local unit = ScenEdit_AddUnit({type='Facility',side=BLUE_SIDE, name = "Tower Control", dbid=k, latitude = position.latitude-0.001, longitude=position.longitude+0.0006, autodetectable=false})
		unit.group="Blue AB"
	elseif k == 41 then
		for i=1,16 do
			local unit = ScenEdit_AddUnit({type='Facility',side=BLUE_SIDE, name = v.."#"..i, dbid=k, latitude = position.latitude+RandomFloat(0.0003,0.0007,13), longitude=position.longitude-RandomFloat(-0.002,0.004,13)+i/10000, autodetectable=false})
			unit.group="Blue AB"
		end
	elseif k==217 then --TARMAC SPACE
		for i=1,24 do
			local unit = ScenEdit_AddUnit({type='Facility',side=BLUE_SIDE, name = v.."#"..i, dbid=k, latitude = position.latitude+RandomFloat(-0.0003,0.0003,13), longitude=position.longitude-0.0036+i/10000, autodetectable=false})
			unit.group="Blue AB"
		
		end
	elseif k==353 then
		for i=1,3 do
			local unit = ScenEdit_AddUnit({type='Facility',side=BLUE_SIDE, name = v.."#"..i, dbid=k, latitude = position.latitude+RandomFloat(-0.0003,0.0003,13), longitude=position.longitude-0.0016+i/10000, autodetectable=false})
			unit.group="Blue AB"

		end
	elseif k==1393 then
		for i=1,5 do
			local unit = ScenEdit_AddUnit({type='Facility',side=BLUE_SIDE, name = v.."#"..i, dbid=k, latitude = position.latitude+0.0007, longitude=position.longitude-RandomFloat(-0.0003,0.0003,13)+i/10000, autodetectable=false})
			unit.group="Blue AB"

		end
	elseif k==198 then
		for i=1,12 do
			local unit = ScenEdit_AddUnit({type='Facility',side=BLUE_SIDE, name = v.."#"..i, dbid=k, latitude = position.latitude-RandomFloat(0.00035,0.00045,13), longitude=position.longitude-RandomFloat(0.0003,0.0009,13)+i/10000, autodetectable=false})
			unit.group="Blue AB"
		end
	elseif k==1423 then
		local unit = ScenEdit_AddUnit({type='Facility',side=BLUE_SIDE, name = v, dbid=k, latitude = position.latitude, longitude=position.longitude-0.0006, autodetectable=false})
		unit.group="Blue AB"
	elseif k==322 then
		local unit = ScenEdit_AddUnit({type='Facility',side=BLUE_SIDE, name = v, dbid=k, latitude = position.latitude+0.003, longitude=position.longitude-0.0006, autodetectable=false})
		unit.group="Blue AB"
	end
end

local dbCAP =3896
local dbLoadout = 332
for i=1,24 do
	local unit = ScenEdit_AddUnit({type='Aircraft',side=BLUE_SIDE, name = "AIRCAP #"..i, dbid=dbCAP,loadoutid=dbLoadout,base="Blue AB"})
	if i > 12 then ScenEdit_SetUnit({guid=unit.guid, TimeToReady_Minutes=1440}) end
	ScenEdit_FillMagsForLoadout({unit='BLUE AB', loadoutid=dbLoadout, quantity=48})
end
Thx!!!
Post Reply

Return to “Lua Legion”