Jump to content

Recommended Posts

Posted

I would like to find a way to dynamically spawn in an AI aircraft and have it attack a specific point on the ground with cluster munitions.  I don’t want to interact with the F10 map as this is meant to be 100% hands-free for VR optimization.  I have VERY limited LUA experience, but am familiar with programming concepts back from the Jurassic period when I received my business degree.

When writing LUA, I usually try and find code that I can plagiarize and morph into my needs.  I am currently playing around with CIRIBOB’s CSAR script and adding to it.

Here’s what I’d like to do from the cockpit of a helo.

1)      From the F10 Radio option select an option to “Call in CAS”

2)      Determine x,y,z position of helo

3)      Drop red smoke on coordinates

4)      Spawn an AI F4 in the general vicinity of the coordinates (maybe 20 miles away)

5)      Instruct the AI plane to attack the coordinates using cluster munitions

I think I can do #1-#3 on my own.  I could probably also figure out #4 with some brute force trial and error.  I don’t know how to accomplish #5 or if its even possible to do via scripting.  Can anyone help nudge me in the right direction here?

I don’t have anything coded yet because I’d like to understand how/if #5 operates.

Thanks for the help!!

System Specs:

Spoiler

📻Callsign:Kandy  💻Processor:13th Gen Intel(R) Core(TM) i9-13900K - 🧠RAM: 64GB - 🎥Video Card: NVIDIA RTX 4090 - 🥽 Display: Pimax 8kx VR Headset - 🕹️Accessories:  VKB Gunfighter III MCG Ultimate, VKB STECS Standard, Thrustmaster TPR Pedals, Simshaker JetPad, Predator HOTAS Mounts, 3D Printed Flight Button Box 

📹 Video Capture Software:  Open Broadcaster Software (OBS), 🎞️ Video Editing Software:  PowerDirector 365

Into The Jungle Apache Campaign - Griffins  Kiowa Campaign - Assassins  Thrustmaster TWCS Mod

 

Posted (edited)

You could use MOOSE to spawn a group and then create a CAS or strike mission.

1.- You need to add moose script on start

2.- On ME you need to create the AI aircraft with the loadout you want and set it as late activation (you don't need to add waypoints, the mission is created by moose)

3.- How do you want to trigger the spawn? You could trigger it when the client enters a zone, or whatever you want, just call the spawn method

 

SPAWN_AI = SPAWN	-- https://flightcontrol-master.github.io/MOOSE_DOCS/Documentation/Core.Spawn.html
	:New("name of the late activation group")
	:OnSpawnGroup(function(SpawnGroup)
		local zoneCAS = ZONE_RADIUS:New(
			"Zone marker", 	-- internal name of the zone
			{x = details.targetPos.x, y = details.targetPos.z},	-- Vec2: the center of the zone, you could use the target's coordinates	
			radius, 		-- I believe it is in meters, but not 100% sure
			false
		)
		local fg = FLIGHTGROUP:New(SpawnGroup)
		local mission=AUFTRAG:NewCAS(		-- https://flightcontrol-master.github.io/MOOSE_DOCS_DEVELOP/Documentation/Ops.Auftrag.html##(AUFTRAG).NewCAS
			zoneCAS,
			altitude, 
			speed,  
			zoneCAS:GetCoordinate(0), 
			90, 
			20, 
			{"Helicopters", "Ground Units", "Light armed ships"}
		)
		fg:AddMission(mission)
	end)

function spawnAI()
	SPAWN_AI:SpawnAtParkingSpot(data["airbase"], data["spots"], SPAWN.Takeoff.Hot)	-- Change this to your liking, you can spawn it on some specific coordinates on the air, on an airfield or in my case I choose the specific spot I want it to spawn https://flightcontrol-master.github.io/MOOSE_DOCS/Documentation/Core.Spawn.html##(SPAWN).SpawnAtAirbase
end

 

When the spawnAI() method is called it will spawn a new instance of the late activation group you created on ME, and after it has spawn the onSpawnGroup function is called. In there, you can use moose to create a CAS mission sent to a specific area, you can customize the CAS zone. Or you could use the strike mission, also using the Auftrag class from moose.

 

This is just a quick copy-paste from one on my libraries, but I hope is understandable enough for you to test it (moose documentation is good enough :P)

 

EDIT: if you do want to create a smoke marker, moose also has built-in methods for it https://flightcontrol-master.github.io/MOOSE_DOCS/Documentation/Core.Point.html##(COORDINATE).Smoke, you would need to create a COORDINATE, just with COODINATE:New(x,y,z), first

Edited by Darcaem
Posted

Thanks! I'll give it a go.  Appreciate the code snippet.

System Specs:

Spoiler

📻Callsign:Kandy  💻Processor:13th Gen Intel(R) Core(TM) i9-13900K - 🧠RAM: 64GB - 🎥Video Card: NVIDIA RTX 4090 - 🥽 Display: Pimax 8kx VR Headset - 🕹️Accessories:  VKB Gunfighter III MCG Ultimate, VKB STECS Standard, Thrustmaster TPR Pedals, Simshaker JetPad, Predator HOTAS Mounts, 3D Printed Flight Button Box 

📹 Video Capture Software:  Open Broadcaster Software (OBS), 🎞️ Video Editing Software:  PowerDirector 365

Into The Jungle Apache Campaign - Griffins  Kiowa Campaign - Assassins  Thrustmaster TWCS Mod

 

Posted (edited)
On 11/7/2024 at 4:42 PM, Mistermann said:

I would like to find a way to dynamically spawn in an AI aircraft and have it attack a specific point on the ground with cluster munitions.  I don’t want to interact with the F10 map as this is meant to be 100% hands-free for VR optimization.  I have VERY limited LUA experience

That's a really cool project, and I think that it is manageable - although you do run the risk of becoming addicted to mission scripting like I have. So, think twice, and if you are sure that you want to roll the dice on that devilish stuff, read on 🙂

Now before I pontificate on some minute details, I'll take a step back because I think that for later projects, it may help to fully develop an idea before you put the effort into it to implement it. In this case, we'll just power on because it's a great challenge, and no matter what the outcome, your mission scripting skills will have become so much better.

That being said, some initial thoughts/questions

- what are you trying to achieve? It seems to me that you are implementing a solution in search of a problem.

Now, putting down smoke at the player's current location, triggered by a communications command is a good challenge. And having a unit spawn and attack an arbitrarily defined point is another, separate challenge. 

Together, though, in DCS mission terms they do not fit well. So a player puts down a smoke signal at their position to allow other units to attack that location. Fine, let's say we did that. How does this look in-game? A player would have to fly over some enemy-infested location to mark that spot. Overflying enemies is a no-no unless you are suicidal. So even if you fully develop the entire thing (mark spot, spawn AI and engage spot) the game mechanics won't be fun.

Implementing it, on the other hand, will be fun so, let's proceed.

Getting the player's position

This can be done, and you already seem to have a good idea of this, by using the communications menu and retrieving the group that issued the command. Note here that for this to work (because DCS currently does not provide better API) you need single-unit player groups. But it is entirely doable. Retrieve the unit from the single-unit player group, get the unit's location, and you know where the smoke is to be dropped.

Dropping smoke

Since you have the location where to put the smoke from the player unit (its x, y, and z coordinates), use the x and z to position the smoke on the map (yeah, a 3D point uses X and Z for map locations. Bad API, but that's DCS for you). To place the smoke, invoke the appropriate API method trigger.action.smoke() -- however, there will be a problem if you directly pass the player unit's location: the smoke erupts at the same altitude as the player unit, so you'll first need to get the height of the map at that location. Use land.getHeight() for this (and get the x, y, and z issues in DCS hammered home in the progress of solving this)

So we now can mark a player's current location using communications. 

Now you want to spawn an aircraft in the vicinity and attack that point. 

Again, before we go down that route, a brief reflection: why do you want to do that? What is the objective? If you simply want to code this challenge, A-OK, we'll do that. If all you want is rain down destruction on and near the point that the player marked, there are much better ways to do that: simply simulate artillery shells impacting some time later by blowing stuff up at random locations around the smoke using multiple trigger.action.explosion() that will damage anything that's sitting there. So no need to spawn aircraft and whatnot.

But let's return to spawning units and have them attack a location

Spawning AI

Welcome to one of the most tedious tasks in mission scripting.  First order of business: determine where. Since we want to keep it simple, we simply use the player's location and move the spawn location 20km (= 20'000 units) up - the spawn location is the player units location as retrieved, and we subtract 20000 from the z coordinate. In a game environment, you'd do some cooler stuff, for example picking a random spot on a 20km circle around the player's location. I'll skip trivial math here. So we have the spawn location.

Now, to spawn a unit, you invoke coalition.addGroup() -- you always add groups, not single units. Most of the params are simple. And then there is that groupData monster. If you think that you know tedious, you haven't met the groupData table. You can spent your entire hair trying to figure out how that works. Don't - unless you want to end up looking like me. There's a simpler way: use mission editor to place a flight like the one that you are looking for, and equip it with the weapons, and make it attack a point on the ground. Save the mission, open it with zip, then load the mission file. Note that the mission file is also Lua. Spend a couple of hours to absorb how a mission is structured, then find the definition for the single flight that you built. There's some more tediousness involved, but what all this boils down to is that you simply copy the group definition, and paste it into your script. Yeah, stupid as that, and it works and saves you oodles of time. 

Then, from your script, you simply modify the spawn location, and target location (= player's smoke location). Which brings me to the last point: how do you tell an AI aircraft where to attack and with what? If you take the copy/past approach from a working mission made with Mission Editor, you kill two birds with one stone. Telling units what to do involves one of the worst thought-out and most user-hating schemes that you'll come across in a long time: DCS's task data. It's even worse than groupData, and if you add a task at spawning, it becomes part of the spawning groupData (hence I prefer ripping the data straight from the mission). If you inspect the crazy data structure from a group, look at the route data. It contains the task. Shortly after your brain starts melting, you'll recognize that the locations in one of the task can be adapted to match the target location, and that all you need to do is to change the route and target points to the spawn target location (provided that the route only has two points: spawn and attack). So all you need to know is take the entire data block that you copy/pasted from your 'code research' mission, and change some "X=" and "Z=", and you are done. Anti-climatic, I know, but "the journey is the reward"

After you implement all this, you find that a) it's a great feeling to have DCS bow to your mission scripting prowess and b) that this particular mission mechanic is crap for players. So you immediately have a great new challenge: build onto this to make it fun. Your mission creation skills will soar, as will having fun with DCS.

Below please find a mission where I faced a similar challenge. I whimped out going the 'ground explosion' route instead of calling in AI. And I found my own way of marking the ground with smoke other than overflying it (players need to check in with arty first, and then shoot a WP round into the ground near the targets, then call in to arty command to shell the smoke location. Works, but no splashy AI flights)

Good luck and have fun coding!

 

 

demo - Willie Nillie.miz

Edited by cfrag
  • Like 1
  • Thanks 1
Posted

Cfrag - you never cease to amaze me, sir.  Thank you for the detailed and thoughtful response - and miz!

Here are some comments back from me.

2 hours ago, cfrag said:

That's a really cool project, and I think that it is manageable - although you do run the risk of becoming addicted to mission scripting like I have. So, think twice, and if you are sure that you want to roll the dice on that devilish stuff, read on 🙂

Now before I pontificate on some minute details, I'll take a step back because I think that for later projects, it may help to fully develop an idea before you put the effort into it to implement it. In this case, we'll just power on because it's a great challenge, and no matter what the outcome, your mission scripting skills will have become so much better.

Oh, I hear you.  I formally received a Computer Science degree and started my career as a "consultant" which was a lofty term for "coder" back in the day.  I haven't programmed for my job in more than 25 years.  Trying to decipher, copy, tweak and test LUA code is slow and arduous for this semi-old timer.  I use your debugger for a lot of this 😉.  

A little more background on what I am trying to pull off here.

I have a multiplayer dynamic mission that serves as a playground for me and my buddies.  We mostly fly Helos on this map, but sprinkle in some fixed wing as well.  This mission heavily features Tobi and 8Ball's Cayuse.  We use the Marianas map as our stand-in for a Vietnam setting.  Here's a recent video from my wingman @Devil 505 that showcases the mission.

I recently added Ciribob's CSAR script to the mission which added a pretty cool SAR element to our play.  I added some random spawned ejecting pilots along with voiceovers that ensure we've got some downed pilots to pickup.  Its been a neat experience.

One thing we thought might be cool to add is the ability to call in a CAS mission at our position.  The downed pilots often come down over very contested land.  This makes the CSAR very exciting for us, but without some CAS can become overwhelming.  Often none of us wants to hop out of our helo and do CAS ourselves, so this is where the idea was born.

I was thinking we could take a menu option that says "CAS on my location" that triggers a period appropriate fixed wing asset to spawn in on the map that comes in and provides some aerial firepower for us. This is where my 1-5 back of the napkin steps come from in the OP.

2 hours ago, cfrag said:

Getting the player's position

This can be done, and you already seem to have a good idea of this, by using the communications menu and retrieving the group that issued the command. Note here that for this to work (because DCS currently does not provide better API) you need single-unit player groups. But it is entirely doable. Retrieve the unit from the single-unit player group, get the unit's location, and you know where the smoke is to be dropped.

Dropping smoke

Since you have the location where to put the smoke from the player unit (its x, y, and z coordinates), use the x and z to position the smoke on the map (yeah, a 3D point uses X and Z for map locations. Bad API, but that's DCS for you). To place the smoke, invoke the appropriate API method trigger.action.smoke() -- however, there will be a problem if you directly pass the player unit's location: the smoke erupts at the same altitude as the player unit, so you'll first need to get the height of the map at that location. Use land.getHeight() for this (and get the x, y, and z issues in DCS hammered home in the progress of solving this)

So we now can mark a player's current location using communications. 

Yessir.  The z-axis would have tripped me up for sure on this one.  Making everyone their own group also makes sense and I've been used to doing this back when Pretense was being supported.  I dove into that monster script to add some things and recall single unit groups were a requirement for it as well.   

 

2 hours ago, cfrag said:

Again, before we go down that route, a brief reflection: why do you want to do that? What is the objective? If you simply want to code this challenge, A-OK, we'll do that. If all you want is rain down destruction on and near the point that the player marked, there are much better ways to do that: simply simulate artillery shells impacting some time later by blowing stuff up at random locations around the smoke using multiple trigger.action.explosion() that will damage anything that's sitting there. So no need to spawn aircraft and whatnot.

Oh, I hear you on this.  I could easily just blow stuff up and call it a day.  I often do that in my missions to add what I call Hollywood FX to regular explosions.  Adding smoke/fire on those explosions provides much needed character to the battlefield.  BUT ... my guys are all about experiencing this as authentically as possible.  We want to see an aircraft come in, take fire, possibly evade and go around and eventually put down some ordinance.  If it hits targets, great.  If it misses and makes more passes, awesome.  If it gets shot down and the pilot ejects ... bonus CSAR!  Hope that helps frame up the "why" on this one.

 

2 hours ago, cfrag said:

Spawning AI

Welcome to one of the most tedious tasks in mission scripting.  First order of business: determine where. Since we want to keep it simple, we simply use the player's location and move the spawn location 20km (= 20'000 units) up - the spawn location is the player units location as retrieved, and we subtract 20000 from the z coordinate. In a game environment, you'd do some cooler stuff, for example picking a random spot on a 20km circle around the player's location. I'll skip trivial math here. So we have the spawn location.

Now, to spawn a unit, you invoke coalition.addGroup() -- you always add groups, not single units. Most of the params are simple. And then there is that groupData monster. If you think that you know tedious, you haven't met the groupData table. You can spent your entire hair trying to figure out how that works. Don't - unless you want to end up looking like me. There's a simpler way: use mission editor to place a flight like the one that you are looking for, and equip it with the weapons, and make it attack a point on the ground. Save the mission, open it with zip, then load the mission file. Note that the mission file is also Lua. Spend a couple of hours to absorb how a mission is structured, then find the definition for the single flight that you built. There's some more tediousness involved, but what all this boils down to is that you simply copy the group definition, and paste it into your script. Yeah, stupid as that, and it works and saves you oodles of time. 

Then, from your script, you simply modify the spawn location, and target location (= player's smoke location). Which brings me to the last point: how do you tell an AI aircraft where to attack and with what? If you take the copy/past approach from a working mission made with Mission Editor, you kill two birds with one stone. Telling units what to do involves one of the worst thought-out and most user-hating schemes that you'll come across in a long time: DCS's task data. It's even worse than groupData, and if you add a task at spawning, it becomes part of the spawning groupData (hence I prefer ripping the data straight from the mission). If you inspect the crazy data structure from a group, look at the route data. It contains the task. Shortly after your brain starts melting, you'll recognize that the locations in one of the task can be adapted to match the target location, and that all you need to do is to change the route and target points to the spawn target location (provided that the route only has two points: spawn and attack). So all you need to know is take the entire data block that you copy/pasted from your 'code research' mission, and change some "X=" and "Z=", and you are done. Anti-climatic, I know, but "the journey is the reward"

Seriously, Cfrag - you are the best!!  The service you provide this community is unreal.  I honestly believe most of us around these parts share a very similar combat sim passion and could each sit together over an adult beverage or two and be instant friends sharing common passions.  Like brothers from different mothers!  Anyway...

I cobbled together some thoughts and have a hacked together template right now that leverages MOOSE, MIST and some old code I wrote plagiarized years ago to spawn late activated units.  I made the exercise as trivial as possible by limiting as many variables as possible just to prove I could do it.

So, I've been able to 

1) Spawn in an F4 with CAS loadout

2) Using MOOSE gave it a patrol zone (in ME, not dynamic)

3) Using MOOSE gave it a command to CAS on a fixed zone (in ME, not dynamic)

This currently works and was a small victory for me.  Granted I am more or less "assembling" code, not creating it.  Its not pretty, nor efficient ... but delivering the result I am going for.

2 hours ago, cfrag said:

After you implement all this, you find that a) it's a great feeling to have DCS bow to your mission scripting prowess and b) that this particular mission mechanic is crap for players. So you immediately have a great new challenge: build onto this to make it fun. Your mission creation skills will soar, as will having fun with DCS.

Below please find a mission where I faced a similar challenge. I whimped out going the 'ground explosion' route instead of calling in AI. And I found my own way of marking the ground with smoke other than overflying it (players need to check in with arty first, and then shoot a WP round into the ground near the targets, then call in to arty command to shell the smoke location. Works, but no splashy AI flights)

Thanks for the miz.  Downloading it right now and will check it out.

 

System Specs:

Spoiler

📻Callsign:Kandy  💻Processor:13th Gen Intel(R) Core(TM) i9-13900K - 🧠RAM: 64GB - 🎥Video Card: NVIDIA RTX 4090 - 🥽 Display: Pimax 8kx VR Headset - 🕹️Accessories:  VKB Gunfighter III MCG Ultimate, VKB STECS Standard, Thrustmaster TPR Pedals, Simshaker JetPad, Predator HOTAS Mounts, 3D Printed Flight Button Box 

📹 Video Capture Software:  Open Broadcaster Software (OBS), 🎞️ Video Editing Software:  PowerDirector 365

Into The Jungle Apache Campaign - Griffins  Kiowa Campaign - Assassins  Thrustmaster TWCS Mod

 

  • Recently Browsing   0 members

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