Jump to content

MOOSE: AI_BALANCER Spawning Groups


SARP

Recommended Posts

Hi there all from very noob here!

 


RU_PlanesClientSet = SET_CLIENT:New():FilterCountries( "RUSSIA" ):FilterCategories( "plane" ):FilterPrefixes( "279th" ):FilterStart()


RU_PlanesSpawn = SPAWN:New( "AI SU33" ):InitCleanUp( 20 )


RU_AI_Balancer = AI_BALANCER:New( RU_PlanesClientSet, RU_PlanesSpawn )

local PatrolZones = {}

function RU_AI_Balancer:OnAfterSpawned( SetGroup, From, Event, To, AIGroup )

 local PatrolZoneGroup = GROUP:FindByName( "RUPatrolZone" )
 local PatrolZone = ZONE_POLYGON:New( "RUPatrolZone", PatrolZoneGroup )


 PatrolZones[AIGroup] = AI_PATROL_ZONE:New( PatrolZone, 3000, 6000, 400, 600 )
 PatrolZones[AIGroup]:ManageFuel( 0.2, 60 )
 PatrolZones[AIGroup]:SetControllable( AIGroup )
 PatrolZones[AIGroup]:__Start( 5 )

end

 

Above set of code is the very same code as in MOOSE example missions.

 

The question is:

 

I have 4 client in "279th" Su33 Group and most of times they spawn on each other. Sometimes and somehow first one rescue himself and starts patrolling in defined patrol zone which is great.

 

As much as i have reached and read, I have tried:

 

RU_PlanesSpawn = SPAWN:New( "AI SU33" ):SpawnScheduled( 60, 0.5 ):InitCleanUp( 20 ):

 

or

 

RU_AI_Balancer = AI_BALANCER:New( RU_PlanesClientSet, RU_PlanesSpawn ):InitSpawnInterval( 60,120 )

 

but not a chance.

 

Obviously i am wrong somewhere and cant figure out with DCS 2.5.5 and latest MOOSE.


Edited by =SARP=

ASUS TUFZ270 MARK 1 / Intel i7-7700K @4.8Ghz / 32GB DDR4 @3000Mhz / Nvidia GTX 1060 6GB / 3x TS240GSSD20S SSD / Philips BDM4350 / TrackIR 5

Link to comment
Share on other sites

Could you please describe what you're trying to achieve?

 

Also, what's the problem, exactly? Are those AI aircraft spawning on top of each other and then blowing up?

 

I am just trying to spawn 4 client in same group by using MOOSE AI_BALANCER.

 

And yes, they are spawning on each other and blowing up.

ASUS TUFZ270 MARK 1 / Intel i7-7700K @4.8Ghz / 32GB DDR4 @3000Mhz / Nvidia GTX 1060 6GB / 3x TS240GSSD20S SSD / Philips BDM4350 / TrackIR 5

Link to comment
Share on other sites

As far as I know, the only way to spawn clients is by players "entering" the client slots, I don't think client aircraft can be spawned using scripts, that's only possible for AI aircraft (and statics, maybe).

 

 

If you want to have 4 clients available, simply place them on the ME map (either in the air, on the ramp, etc.) and then set their skill to "Client". They'll be available for players, and spawn when the players "enter" the slots.

 

 

Btw, the example code contains a syntax mistake:

 

[color="Blue"]-- The final colon shouldn't be there[/color]
RU_PlanesSpawn = SPAWN:New( "AI SU33" ):InitCleanUp( 20 )[color="Red"]:[/color]

[color="Blue"]-- Corrected line [/color]
RU_PlanesSpawn = SPAWN:New( "AI SU33" ):InitCleanUp( 20 )

 

 

Also, there's another mistake in the following snippet:

 

[color="Blue"]-- The last colon needs to be removed, also [i][b]:SpawnScheduled[/b][/i] and [i][b]:InitCleanUp[/b][/i] should be swapped (I think):[/color]

RU_PlanesSpawn = SPAWN:New( "AI SU33" )[color="red"][i]:SpawnScheduled( 60, 0.5 )[/i][/color][color="red"][i]:InitCleanUp( 20 )[/i][/color][color="Red"]:[/color]

[color="Blue"]-- Corrected line[/color]
RU_PlanesSpawn = SPAWN:New( "AI SU33" ):InitCleanUp( 20 ):SpawnScheduled( 60, 0.5 )


Edited by Hardcard
Link to comment
Share on other sites

Thank you indeed Hardcard

 

Colon is not the case, it was my copy-paste mistake while writing here and already i dont have this colon.

 

What i am trying to do is :

 

 

I think this should be more clear now. :)

 

and already tried:

 

-- The last colon needs to be removed, also :SpawnScheduled and :InitCleanUp should be swapped (I think):

RU_PlanesSpawn = SPAWN:New( "AI SU33" ):SpawnScheduled( 60, 0.5 ):InitCleanUp( 20 ):

-- Corrected line
RU_PlanesSpawn = SPAWN:New( "AI SU33" ):InitCleanUp( 20 ):SpawnScheduled( 60, 0.5 )

 

nothing changed :(

 

 

As far as i read, SpawnScheduled (#number, #variant ) wouldnt work with AI_BALANCER , because MOOSE already defines it as InitSpawnInterval ( #number, #number ) . And this is what i guess, hope or dont know :)


Edited by =SARP=

ASUS TUFZ270 MARK 1 / Intel i7-7700K @4.8Ghz / 32GB DDR4 @3000Mhz / Nvidia GTX 1060 6GB / 3x TS240GSSD20S SSD / Philips BDM4350 / TrackIR 5

Link to comment
Share on other sites

 

and already tried:

 

-- The last colon needs to be removed, also :SpawnScheduled and :InitCleanUp should be swapped (I think):

RU_PlanesSpawn = SPAWN:New( "AI SU33" ):SpawnScheduled( 60, 0.5 ):InitCleanUp( 20 ):

-- Corrected line
RU_PlanesSpawn = SPAWN:New( "AI SU33" ):InitCleanUp( 20 ):SpawnScheduled( 60, 0.5 )

 

nothing changed :(

 

Regardless, always place :SpawnScheduled or :Spawn at the end of the SPAWN object declaration, in order to avoid conflicts with other methods.

 

I'll take a look at the video now

Link to comment
Share on other sites

Regardless, always place :SpawnScheduled or :Spawn at the end of the SPAWN object declaration, in order to avoid conflicts with other methods.

 

I'll take a look at the video now

 

and meantime, i will try your :Spawn suggestion.

 

 

=====================

 

Tried your suggestion and adding :Spawn at the end breaks the script.

 

Only one plane spawned and did not move to the patrol zone and returned base


Edited by =SARP=

ASUS TUFZ270 MARK 1 / Intel i7-7700K @4.8Ghz / 32GB DDR4 @3000Mhz / Nvidia GTX 1060 6GB / 3x TS240GSSD20S SSD / Philips BDM4350 / TrackIR 5

Link to comment
Share on other sites

I'm still watching the AI BALANCER series, sorry.

 

 

Anyway, I guess I didn't express myself properly, I wasn't telling you to try :Spawn, I was just saying that whenever you need to spawn a SPAWN object, leave :SpawnScheduled or :Spawn for the very end, that's all.

 

 

Be back in a few minutes.

Link to comment
Share on other sites

ohhh.. got it :thumbup:

 

meantime i am searching, reading and trying...

 

thank you for your time

ASUS TUFZ270 MARK 1 / Intel i7-7700K @4.8Ghz / 32GB DDR4 @3000Mhz / Nvidia GTX 1060 6GB / 3x TS240GSSD20S SSD / Philips BDM4350 / TrackIR 5

Link to comment
Share on other sites

Well thats true.

 

This is PvP mission that AI would take place for empty slots and patrol in defined zone and finally return base if SLOT is taken by PLAYER.

 

In that sense, MOOSE AI_BALANCER seems like a good idea to me.

ASUS TUFZ270 MARK 1 / Intel i7-7700K @4.8Ghz / 32GB DDR4 @3000Mhz / Nvidia GTX 1060 6GB / 3x TS240GSSD20S SSD / Philips BDM4350 / TrackIR 5

Link to comment
Share on other sites

Ok, AI_BALANCER makes sense in that situation.

 

I'll have a look tomorrow, but I recommend that you join the MOOSE Discord channel and have a look at the #ai-aibalancer section (check the comment history).

 

If you don't find an answer in the comment history, then just ask there, chances are someone will be able to help.

 

PS: I just noticed that you're using a client set for the AI_BALANCER. Keep in mind that client sets work with unit names, not with group names.

This means that, for instance, if you want to use "279th" as prefix, it must be placed before the unit name of each client, not before their group name


Edited by Hardcard
Link to comment
Share on other sites

MOOSE Discord channel is a good idea.

 

Each unit name already starts with "279th" prefix.

 

BTW, thank you for your help and time again.

ASUS TUFZ270 MARK 1 / Intel i7-7700K @4.8Ghz / 32GB DDR4 @3000Mhz / Nvidia GTX 1060 6GB / 3x TS240GSSD20S SSD / Philips BDM4350 / TrackIR 5

Link to comment
Share on other sites

After many hours of testing, I've concluded that AI_BALANCER isn't working as it should.

 

Like you said, all AI aircraft spawn on a single spot, being destroyed in the process, also, :InitCleanUp() seems to remove freshly spawned AI aircraft even when they're active (ie moving).

 

This is why I seldom use MOOSE "automation", it breaks sometimes (due to DCS updates or whatever), also, I prefer to rely on code I can understand and mess with ^^.

 

So, basically, I ended up writing my own ai balancer script (seems to work quite well, although it's far from perfect. Haven't tested it in a multiplayer environment, though).

 

 

Test Mission + Script file attached.

 

 

Here's how it works:

 

- A scheduler will perform all the magic every minute (the timer can be set to any value you want, ofc)

 

- Four Su33 clients are available at Novorossiysk airbase

 

- If none of these Su33 clients are active at mission start, four copies of a late activated AI Su33 will spawn (I managed to make them spawn on different slots using :SpawnAtAirbase)

 

If one Su33 client is active at mission start, three copies of a late activated AI Su33 will spawn

 

If two Su33 clients are active at mission start, two copies of a late activated AI Su33 will spawn

 

If three Su33 clients are active at mission start, one copy of a late activated AI Su33 will spawn

 

If all four Su33 clients are active at mission start, the late activated AI Su33 won't spawn (well, it shouldn't)

 

 

- These AI Su33s are programmed to CAP over Gelendzhik airbase. It's a placeholder task, of course, you can give the late activated AI Su33 any task you want

 

- The script will count the number of active AI Su33s as well as the number of active Su33 clients, then use these values to figure out how many AI Su33s need to be spawned (if any)

 

- If the number of active AI Su33s doesn't match the number of inactive Su33 clients, the AI Su33s will RTB (there's an altitude check in place, to prevent the RTB trigger from activating while the AI Su33s are still on the ground)

 

- I've also included a cleanup routine, the AI Su33s will be removed from the map after engine shutdown (there's an additional speed check, to make sure that they aren't removed if their engines stop while flying)

 

- After all the AI Su33s have been removed from the map (or destroyed), the script will automatically spawn extra AI Su33 copies, just enough to make up for inactive Su33 clients.

 

- The maximum number of active AI Su33s allowed at any one time is capped to 4.

 

- The AI Su33s have 100 spawns available (this spawn value can be set to any number you want, ofc)

 

 

I haven't tested any of this with the Su33s spawning on the Kuznetsov, btw, it might not work.

 

 

 

Here's the raw script:

 

local Loop = true

 

local AI_Su33_Spawn = SPAWN:New( "AI_Su33_Group" ):InitLimit(4,100)

 

 

local function Spawner()

 

AI_Su33_Spawn:SpawnAtAirbase(AIRBASE:FindByName("Novorossiysk"), SPAWN.Takeoff.Cold)

 

end

 

local function Permanent_Scheduler(Loop, time)

 

local Su33_ClientSet = SET_CLIENT:New():FilterActive(Active):FilterPrefixes("Su33_"):FilterStart()

 

local Su33_AI_UnitSet = SET_UNIT:New():FilterActive(Active):FilterPrefixes("AI_Su33"):FilterStart()

 

Su33_AI_UnitSet:HandleEvent(EVENTS.EngineShutdown)

 

function Su33_AI_UnitSet:OnEventEngineShutdown(EventData)

 

if Su33_AI_UnitSet:FindUnit(EventData.IniUnit:GetName()) ~= nil and EventData.IniUnit:GetVelocityKMH() == 0 then

 

EventData.IniUnit:Destroy()

 

end

end

 

local AI_Spawn_Difference = 4 - Su33_ClientSet:Count()

 

trigger.action.outText("AI_Spawn_Difference = "..AI_Spawn_Difference,10)

 

if Su33_AI_UnitSet:Count() == 0 then

 

if AI_Spawn_Difference == 4 then

 

Spawner()

Spawner()

Spawner()

Spawner()

 

elseif AI_Spawn_Difference == 3 then

 

Spawner()

Spawner()

Spawner()

 

elseif AI_Spawn_Difference == 2 then

 

Spawner()

Spawner()

 

elseif AI_Spawn_Difference == 1 then

 

Spawner()

 

end

end

 

if AI_Spawn_Difference ~= Su33_AI_UnitSet:Count() then

 

Su33_AI_UnitSet:ForEachUnit(

function(AI_Unit)

 

if AI_Unit:GetAltitude() > 500 then

 

AI_Unit:GetGroup():ClearTasks()

end

end

)

end

 

trigger.action.outText("Number of active clients = "..Su33_ClientSet:Count().."\nNumber of active AI planes= "..Su33_AI_UnitSet:Count(), 10)

 

if Loop == true then

return time + 55

end

end

 

timer.scheduleFunction(Permanent_Scheduler, Loop, timer.getTime() + 5)

AI BALANCER Test.miz

Homemade AI_BALANCER Test.lua


Edited by Hardcard
Link to comment
Share on other sites

Are you serious? :)))

 

Thank you very very much indeed :) i dont know what to say more for your return.

 

I will definately try

ASUS TUFZ270 MARK 1 / Intel i7-7700K @4.8Ghz / 32GB DDR4 @3000Mhz / Nvidia GTX 1060 6GB / 3x TS240GSSD20S SSD / Philips BDM4350 / TrackIR 5

Link to comment
Share on other sites

  • Recently Browsing   0 members

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