Jump to content

Set route to group spawned by moose


Go to solution Solved by Darcaem,

Recommended Posts

Hi

I've been trying to allow myseld to dynamically generate flights from specific airbases to the zone where I need them. I've been able to spawn ground units and set their destination passing the coordinates from a user created marked, but I have failed to do so for air units.

My goal is to create one or more markers on the F10 map in-game, and use those coordinates to create a route to be followed by a moose spanwed flight. As an mvp I'm trying to create a simple CAP flight that spawns in Ovda (SinaI) and flies to Ramon Airbase.

The flight is spawned as

BLUE_CAP_ISRAEL:SpawnAtAirbase(AIRBASE:FindByName(AIRBASE.Sinai.Ovda), SPAWN.Takeoff.Runway)

And it is previously defined on the same lua file as

BLUE_CAP_ISRAEL = SPAWN
					:New("Blue CAP F15E")
					:InitLimit(8, 16)
					:OnSpawnGroup(
					function(SpawnGroup)
						trigger.action.outText("111111",15)		
						local group = Group.getByName(SpawnGroup.GroupName)
						local initPoint = AIRBASE:FindByName(AIRBASE.Sinai.Ovda):GetZone():GetVec2()
						local targetPoint = AIRBASE:FindByName(AIRBASE.Sinai.Ramon_Airbase):GetZone():GetVec2()
						
						trigger.action.outText("222222222",15)
						local mission = {
							["id"] = "Mission",
							["params"] = {
								["route"] = {
									["points"] = {
										[1] = {
											["alt"] = 807,
											["action"] = "Turning Point",
											["alt_type"] = "BARO",
											["speed"] = 550,
											["task"] = {
												[1] = {
													["enabled"] = true,
													["auto"] = true,
													["id"] = "WrappedAction",
													["number"] = 1,
													["params"] = {
														["action"] = {
															["id"] = "EPLRS",
															["params"] = {
																["value"] = true,
																["groupId"] = 1
															}
														}
													}
												},
												[2] = {
													["enabled"] = true,
													["auto"] = false,
													["id"] = "WrappedAction",
													["number"] = 2,
													["params"] = {
														["action"] = {
															["id"] = "Option",
															["params"] = {
																["variantIndex"] = 1,
																["name"] = 5,
																["formationIndex"] = 6,
																["value"] = 393217
															}
														}
													}
												},
												[3] = {
													["enabled"] = true,
													["auto"] = false,
													["id"] = "EngageTargets",
													["number"] = 3,
													["params"] = {
														["targetTypes"] = {
															[1] = "Air",
														}, -- end of ["targetTypes"]
														["priority"] = 0,
														["value"] = "Air;",
														["noTargetTypes"] = {
															[1] = "Cruise missiles",
															[2] = "Antiship Missiles",
															[3] = "AA Missiles",
															[4] = "AG Missiles",
															[5] = "SA Missiles"
														},
														["maxDistEnabled"] = true,
														["maxDist"] = EngagementDistance,
													}
												},
												[4] = {
													["enabled"] = true,
													["auto"] = false,
													["id"] = "WrappedAction",
													["number"] = 4,
													["params"] = {
														["action"] = {
															["id"] = "Option",
															["params"] = {
																["value"] = 3,
																["name"] = 1
															}
														}
													}
												},
												[5] = {
													["number"] = 5,
													["auto"] = false,
													["id"] = "WrappedAction",
													["enabled"] = true,
													["params"] = {
														["action"] = {
															["id"] = "Option",
															["params"] = {
																["value"] = 264241152,
																["name"] = 10
															}
														}
													}
												},
												[6] = {
													["enabled"] = true,
													["auto"] = false,
													["id"] = "WrappedAction",
													["number"] = 6,
													["params"] = {
														["action"] = {
															["id"] = "Option",
															["params"] = {
																["value"] = true,
																["name"] = 19
															}
														}
													}
												},
												[7] = {
													["enabled"] = true,
													["auto"] = false,
													["id"] = "WrappedAction",
													["number"] = 7,
													["params"] = {
														["action"] = 	{
															["id"] = "Option",
															["params"] = {
																["value"] = true,
																["name"] = 6
															}
														}
													}
												},
											},
											["type"] = "Turning Point",
											["ETA"] = 0,
											["ETA_locked"] = true,
											["y"] = initPoint.y,
											["x"] = initPoint.x,
											["formation_template"] = "",
											["speed_locked"] = true,
										},
										[2] = {
											["alt"] = 35000,
											["action"] = "Turning Point",
											["alt_type"] = "BARO",
											["speed"] = 550,
											["task"] = {
												["id"] = "ComboTask",
												["params"] = {
													["tasks"] = {}
												}
											},
											["type"] = "Turning Point",
											["ETA"] = 1744.9128539618,
											["ETA_locked"] = false,
											["y"] = targetPoint.y,
											["x"] = targetPoint.x,
											["formation_template"] = "",
											["speed_locked"] = true,
										}, -- end of [6]
									}
								}
							}
						}
						trigger.action.outText("33333333",15)
						group:SetTask(mission)	
						
						trigger.action.outText("Mission CAP launched",15)
						
					end
				)

 

The F15Es are spawned correctly by the mission is not attached to them. As you can see, I've set some "logs" to see were exactly it fails. It prints until the "3333" message, so my guess is (which is kind of obvious 😅) I'm doing something wrong while defining the mission json.

Any idea?

 

EDIT: I have no idea at all about how to create the mission object. That definition's code inside the OnSpawnGroup method I used is copied from Operation Scarlet Dawn (https://www.digitalcombatsimulator.com/en/files/3313323/ ) by Surrexen. If you could point me in the right direction to some documentation, that would be perfect too 🙂


Edited by Darcaem
Link to comment
Share on other sites

I've been able to achieve my goal of setting custom markers with the Moose's OPS FLIGHTGROUP AddWaypoint method (https://flightcontrol-master.github.io/MOOSE_DOCS_DEVELOP/Documentation/Ops.FlightGroup.html##(FLIGHTGROUP).AddWaypoint) which is not included on the last release published on Github

local flightgroup=FLIGHTGROUP:New("Blue CAP F15E")
flightgroup:Activate()
local wp1=flightgroup:AddWaypoint(ACTIVE_POSITION, 550, nil, 35000)

I can create several markers on the F10 map, store them on a Coordinates array, and create as many waypoints as markers in a loop 🤗

 

The thing now is, the FLIGHTGROUP:New() method needs a group's name with late activation and it "consumes" it. So I can only spawn one flight per late activation group. I would like to be able to spawn as many flight as I like during my playtime, not needing to declare each one of them previously on ME. To be able to spawn as more than one flight from the same template, I've tried:

BLUE_CAP_ISRAEL = SPAWN
	:New("Blue CAP F15E")
	:InitLimit(8, 16)
	:OnSpawnGroup(
		function(SpawnGroup)
			local flightgroup=FLIGHTGROUP:New(SpawnGroup.GroupName)
			flightgroup:Activate()
			local wp1=flightgroup:AddWaypoint(ACTIVE_POSITION, 550, nil, 35000)
		end
	)
function requestBlueCAP()
	BLUE_CAP_ISRAEL:SpawnAtAirbase(AIRBASE:FindByName(AIRBASE.Sinai.Ovda), SPAWN.Takeoff.Runway)
end

but it does not work. The flight is spawned but the flightgroup;AddWaypoint method fails


Edited by Darcaem
Link to comment
Share on other sites

  • Solution

Solved!! 🥳

I find my mistake, I only needed to cast the coordinates to Core.Point#COORDINATE. This seems to work so far, it allows me to spawn several flights and set their route during my mission depending on what I need

BLUE_CAP_ISRAEL = SPAWN
	:New("Blue CAP F15E")
	:InitLimit(8, 16)
	:OnSpawnGroup(
		function(SpawnGroup)
			local position = COORDINATE:New(ACTIVE_POSITION.x, ACTIVE_POSITION.y, ACTIVE_POSITION.z)
			local flightgroup=FLIGHTGROUP:New(SpawnGroup)
			flightgroup:Activate()
			local wp1=flightgroup:AddWaypoint(position, 550, nil, 35000)	-- This must be switched for a loop
		end
)

And from the radio menu I can call

BLUE_CAP_ISRAEL:SpawnAtAirbase(AIRBASE:FindByName(AIRBASE.Sinai.Ovda), SPAWN.Takeoff.Runway)

In my simple tests it works. I create a marker, capture its coordinates on an event and then spawn a flight which is directed to that position. Now let's hope it will still work during an actual mission with enemies and air defenses, or if the AI decides to scrap its orders and do random stuff, as usual 😛

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...