Jump to content

Despawn AI after parking


philstyle

Recommended Posts

Hi folks,

 

Is there a way to de-spawn AI aircraft after they park?

I note that they just sit on their parking spaces eternally until the mission ends. I'd like to be able to clear AI off once parked.

 

I also need to be able to do this per aircraft, rather than de-spawning an entire group at once.

 

Any help appreciated!

On YouTube: https://www.youtube.com/philstylenz

Storm of War WW2 server website: https://stormofwar.net/

 

Link to comment
Share on other sites

Scripting using S_EVENT_ENGINE_SHUTDOWN is probably easiest like they've said, but you can also use the in game trigger system to accomplish the same. It will just be more work probably.

 

https://wiki.hoggitworld.com/view/DCS_event_engine_shutdown

 

You could use a combination of in zone, altitude less than, and speed less than to detect when they stop on the ramp.

Link to comment
Share on other sites

Hi folks,

 

Is there a way to de-spawn AI aircraft after they park?

I note that they just sit on their parking spaces eternally until the mission ends. I'd like to be able to clear AI off once parked.

 

I also need to be able to do this per aircraft, rather than de-spawning an entire group at once.

 

Any help appreciated!

 

Hi phil,

 

I spent a bit of time trying to work this out. Well not specifically this but the outcome should work for you.

 

Initially i made trigger zones and was going to use a condition when they get back into the zone they would despawn and spawn the next group but they didn't always return to the same base.

 

My second effort was to have them trigger a flag above a certain speed (you can use any trigger to increase the flag value) and then i set a trigger for when their airspeed was less than taxi speed and the flag = 1 they deactivated. I needed the flag otherwise they would spawn in on an airfield and their speed was below taxi speed so they would instantly deactivate.

 

If you can send me a copy of your mission i can have a go at setting he first one up and then you can just copy it for the rest.

 

EDIT i just checked and you can only deactivate a group not a unit.


Edited by [Cobra]
Link to comment
Share on other sites

@johnv2pt0

 

If I remember correctly, the problem with using S_EVENT_ENGINE_SHUTDOWN is that it might trigger during flight (due to engine damage).

 

I'd use altitude and velocity checks instead, combined with a flag (which would be tied to S_EVENT_LAND)

 

However, if the OP can live with having each unit in a separate group, then there's no need for a scripted solution (although it would be quicker and cleaner, imho).

Link to comment
Share on other sites

Thanks for the feedback folks.

 

It looks like a scripted option is going to be the only solution here, for a number of reasons:

 

1. I want to continue to use more than one aircraft per A.I. group

2. I don't want the entire group despawning whilst some aicraft are still airborne

3. I don't want to use "engine shut down" in case it causes damaged-but-not-yet-destroyed aircraft to despawn

 

The alternative might just be to have time-based triggered group-de-activations . . maybe based on flags turning on once th rgouops sapwns in; and then de-activating the group when time since flag is say +90 minutes.

 

It's a real shame this isn't just a normal part of the AI behaviour. . .

On YouTube: https://www.youtube.com/philstylenz

Storm of War WW2 server website: https://stormofwar.net/

 

Link to comment
Share on other sites

Use S_EVENT_ENGINES_SHUTDOWN to get the trigger and then check that speed and altitude are below set parameters.. ie speed less then 1 and altitude less then 10 radar.

you could also use something like the M.O.O.S.E scripting stuff

i7 13700k, 64gb DDR5, Warthog HOTAS, HP Reverb G2 VR, win 11, RTX 3070

TGW Dedicated Server Admin, Australian PVE/PVP gameplay. (taskgroupwarrior.info/2020)

Link to comment
Share on other sites

1. I want to continue to use more than one aircraft per A.I. group

2. I don't want the entire group despawning whilst some aicraft are still airborne

3. I don't want to use "engine shut down" in case it causes damaged-but-not-yet-destroyed aircraft to despawn

 

 

Here, this MOOSE script should have you covered (you'll need to run Moose.lua at mission start for it to work with your mission):

 

 

local CleanupSet = SET_UNIT:New()

:FilterCategories("plane")

:FilterStart()

 

local function CleanupRun(CleanupUnit)

 

SCHEDULER:New( nil,

function()

 

local CleanupName = CleanupUnit:GetName()

local CleanupVelocity = CleanupUnit:GetVelocityKMH()

local CleanupAliveCheck = CleanupUnit:IsAlive()

 

if CleanupVelocity == 0 and CleanupAliveCheck == true

then

CleanupUnit:Destroy()

MESSAGE:New(CleanupName.." parking detected!\n"..CleanupName.." removed from airbase!",10):ToAll()

end

end, {}, 1, 5, nil, 600

)

end

 

CleanupSet:HandleEvent(EVENTS.Land)

 

function CleanupSet:OnEventLand(EventData)

 

local InitiatorObject = EventData.IniDCSUnit

local InitiatorName = EventData.IniDCSUnitName

 

MESSAGE:New(InitiatorName.." landed!"):ToAll()

 

CleanupSet:ForEachUnit(

function(CleanupUnit)

 

local CleanupObject = CleanupUnit:GetDCSObject()

 

if CleanupObject == InitiatorObject

then

timer.scheduleFunction( CleanupRun, CleanupUnit, timer.getTime() + 1 )

MESSAGE:New(InitiatorName.." cleanup scheduler running!\n"..InitiatorName.." will be removed after parking!",10):ToAll()

end

end

)

end

 

 

The way I've written it, the script will apply to ALL planes in the mission, but it can be made to target any units you want, really.

 

I've attached a MOOSE demo mission + the script file, so you can see it in action.

Aircraft Cleanup Test.miz

Aircraft cleanup after parking.lua

Link to comment
Share on other sites

Here, this MOOSE script should have you covered (you'll need to run Moose.lua at mission start for it to work with your mission):

 

 

local CleanupSet = SET_UNIT:New()

:FilterCategories("plane")

:FilterStart()

 

local function CleanupRun(CleanupUnit)

 

SCHEDULER:New( nil,

function()

 

local CleanupName = CleanupUnit:GetName()

local CleanupVelocity = CleanupUnit:GetVelocityKMH()

local CleanupAliveCheck = CleanupUnit:IsAlive()

 

if CleanupVelocity == 0 and CleanupAliveCheck == true

then

CleanupUnit:Destroy()

MESSAGE:New(CleanupName.." parking detected!\n"..CleanupName.." removed from airbase!",10):ToAll()

end

end, {}, 1, 5, nil, 600

)

end

 

CleanupSet:HandleEvent(EVENTS.Land)

 

function CleanupSet:OnEventLand(EventData)

 

local InitiatorObject = EventData.IniDCSUnit

local InitiatorName = EventData.IniDCSUnitName

 

MESSAGE:New(InitiatorName.." landed!"):ToAll()

 

CleanupSet:ForEachUnit(

function(CleanupUnit)

 

local CleanupObject = CleanupUnit:GetDCSObject()

 

if CleanupObject == InitiatorObject

then

timer.scheduleFunction( CleanupRun, CleanupUnit, timer.getTime() + 1 )

MESSAGE:New(InitiatorName.." cleanup scheduler running!\n"..InitiatorName.." will be removed after parking!",10):ToAll()

end

end

)

end

 

 

The way I've written it, the script will apply to ALL planes in the mission, but it can be made to target any units you want, really.

 

I've attached a MOOSE demo mission + the script file, so you can see it in action.

 

WOW!

Thanks!

I'll take a look at this in the next week or so hopefully.

On YouTube: https://www.youtube.com/philstylenz

Storm of War WW2 server website: https://stormofwar.net/

 

Link to comment
Share on other sites

Hi Hardcard,

 

 

your test mission works perfectly, and I was also able to swap out the AI aircraft for B17s and they also landed and despawned fantastically, just as I was hoping.

 

 

However, when I use the scripts on the Normandy map, with B17s landing at Chailey Airfield, they would not despawn once parked.

 

 

Perhaps if you have the WW2 assets and the Normady map I can send you the mission I am using. However, if you do not have those modules I shall have to try and work out the issue myself.

On YouTube: https://www.youtube.com/philstylenz

Storm of War WW2 server website: https://stormofwar.net/

 

Link to comment
Share on other sites

@philstyle

 

I don't have the WW2 assets nor the Normandy map.

 

However, if it worked for the B17s in the Caucasus map, it should also work in the Normandy map, I believe.

 

Question for you:

In the Normandy map (Chailey Airfield), how long does it take for the B17s to actually come to a stop after landing?

 

If it takes them more than 10 minutes, the script will need to be modified :doh:

 

Find this line:

 

 

end, {}, 1, 5, nil, 600

 

-- 600 is the number of seconds before the velocity check scheduler stops running (it starts running when the unit lands).

-- If it takes more than 10 minutes for the B17s to come to a stop at Chailey Airfield, simply increase the value to whatever you need, it should work

 

 

Also, as it's written, the script should only work for units that are already present in the mission when the script runs.

If you want it to work with late activated planes as well, it might need to be modified.

 

You can send me the mission details via PM, if you want.


Edited by Hardcard
Link to comment
Share on other sites

@philstyle

I don't have the WW2 assets nor the Normandy map.

However, if it worked for the B17s in the Caucasus map, it should also work in the Normandy map, I believe.

Question for you:

In the Normandy map (Chailey Airfield), how long does it take for the B17s to actually come to a stop after landing?

If it takes them more than 10 minutes, the script will need to be modified

Find this line:

 

 

end, {}, 1, 5, nil, 600

-- 600 is the number of seconds before the velocity check scheduler stops running (it starts running when the unit lands).

-- If it takes more than 10 minutes for the B17s to come to a stop at Chailey Airfield, simply increase the value to whatever you need, it should work

 

Also, as it's written, the script should only work for units that are already present in the mission when the script runs.

If you want it to work with late activated planes as well, it might need to be modified.

You can send me the mission details via PM, if you want.

 

 

 

Thanks for the reply.

So I am pretty sure that the time from landing to park is less than 10 minutes, however I cannot be certain so I'll check that tonight.

I alos plan to send one or two groups to other bases, in case it is a bug which is perculiar to Chailey (I wouldn't be suprised given the way that the Normandy map behaves some times...)

 

 

Some of the aircraft groups are definitely late activated. So this might explain them. However there is one formation which I have present at mission start (3x groups of 4). These are landing (despite an inordinate amount of time circluing around the airfield for some reason) and parking but not de-spawning.

So I suspect the script will need to be modified to account for the late-activated aircraft.

 

 

The mission runs for 6 hours, with around 15 to 20 AI groups activating throughout and conducting missions and retruning home to land.

On YouTube: https://www.youtube.com/philstylenz

Storm of War WW2 server website: https://stormofwar.net/

 

Link to comment
Share on other sites

Ok.

 

So the script doesn't use any kind of airfield information, it relies on unit categories, LAND events and velocity checks.

 

If there's a problem with any of these, the script won't work.

 

Regarding those 3x groups of 4, do they work in the Caucasus map?

 

 

Also, it would be great if you could share your dcs.log (C:\Users\YourUserName\Saved Games\DCS\Logs).

 

Just clear all its contents (leave it blank and save it), then perform a single run of your mission, until you start detecting problems with aircraft not being removed.

 

Then post your dcs.log here.

 

PS. Btw, when any of those problematic units land, do you at least receive the landing messages? If not, that probably means there's a problem with the LAND events (or the unit SET).

However, if you do receive the landing messages, either they take too long to come to a stop or there's a problem with their scheduled checks. It should be easy to fix.


Edited by Hardcard
Link to comment
Share on other sites

  • 1 year later...
  • 1 month later...

Hi Folks, Hi Hardcard - everyone a happy and healthy new year.

I´ve tried to modify Hardcards-Script to pimp up my Case1-Recovery Training Mission - where i let spawn several random traffic to make it more interesting. After a while the carrier is crowded up with parked ai-planes, which i want to despawn (destroy) by radio call. Where did i go wrong in my script below ?! 

 

local CleanupSet = SET_UNIT:New()
      :FilterCategories("plane")
      :FilterStart()


local function main()
timer.scheduleFunction(main, {}, timer.getTime() + 1)

if trigger.misc.getUserFlag('3') == 1 then

CleanupSet:ForEachUnit(

function(CleanupUnit)

local CleanupVelocity = CleanupUnit:GetVelocityKNOTS()
local CleanupAliveCheck = CleanupUnit:IsAlive()

if CleanupVelocity <= 20 and CleanupAliveCheck == true
then
CleanupUnit:Destroy()
trigger.action.setUserFlag('3', 0)
end

end
)
end
end
main()

 

Looking forward to your answer ... regards Monti.

 

 

Link to comment
Share on other sites

  • 1 year later...

@Hardcard I'm just getting into the DCS ME and trying to learn about all this Moose LUA stuff, and I was wondering if I could ask for your advice on that script you posted.

I put together an experimental mission in which I have a handful of groups that take off, fly around, land, get deleted, and respawn. I ran into a few problems that I think are logical timing issues but I'm a bit clueless as to what is happening behind the curtains with all these functions. 

If I let this sim run for an extended period of time where all these groups take off with very limited fuel, they seem to work well for the most part, but eventually one of two things will happen. Either a plane will end up sitting on the runway (likely not detected as landed), or the respawn script will respawn both planes and one or both will get removed again 1-5 seconds later. When this happens, it can happen 20-30 times in a row before it just stops happening and continues on without a problem. 

Do you suppose a better approach to that might be to just only look for planes that have been sitting at 0 speed for an extended period of time, regardless of landed condition? As someone who has little familiarity with lua, how could I approach this?

I was thinking at line 14 of your code:

   if CleanupVelocity == 0 and CleanupAliveCheck == true
    then
     CleanupUnit:Destroy()
     MESSAGE:New(CleanupName.." parking detected!\n"..CleanupName.." removed from airbase!",10):ToAll()
   end

maybe here instead of using OnEventLand and going straight for Destroy(), I could setup some kind of way of creating a time stamp for these met conditions of velocity and alive (so long as one doesn't already exist) and then later destroying it once a certain amount of time has passed?

I'm just not sure how to efficiently dig into this. I was suspecting that these problems I've been seeing are result of more than one aircraft landing before coming to a stop, but seems fine if it's just 2 at a time. If I make shorten the fuel on one group so that it lands before the other, the delete on respawn shifts to that first group. It makes me think it's a list issue of some sort rather than one of synchronization. If you don't mind, any advice on this would be greatly appreciated.

Link to comment
Share on other sites

  • 3 weeks later...

Weird the demo mission works for me but if I try to use it one of my missions it doesn't work 😞

I added a message to the script so that I knew it was running, so it definitely is.

I have some late activation AI air that come in on a trigger, they fly off and run their mission then come home and nothing happens. I dont receive the land events.  Does it matter which side the air is on this is for AI red air.

Anyone seen this or could help troubleshoot?


Edited by Chad Vader
Link to comment
Share on other sites

  • Recently Browsing   0 members

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