Jump to content

MOOSE Framework - SPAWN class


FlightControl

Recommended Posts

Hello all,

 

For those interested, there are mission design training videos available how to use SPAWN class in MOOSE, the Mission Object Oriënted Scripting Environment.

 

The first video walks you through the basics of the SPAWN class, the different functions, a couple of scenarios where the SPAWN class is used, and how to use the SPAWN class in your missions and lua code.

 

[ame]https://www.youtube.com/watch?v=iCaombuK45w[/ame]

 

The second video goes a bit in-depth. It explains how to spawn groups from units, within a zone, randomize the routes, make visible ground troops arrays (like 150 units nicely parked next to each other :-), template randomization, scheduled spawning etc.

 

[ame]

[/ame]

 

I'll use this threat to discuss questions about spawning groups... If you have questions, please post them here.

 

Also, any functional "requirements" or ideas are welcome to enhance the SPAWN class.

 

kind regards,

 

Sven


Edited by FlightControl

[TABLE][sIGPIC][/sIGPIC]|

[/TABLE]

Link to comment
Share on other sites

  • 2 months later...

So, now that I have time, find here a little lecture on the object oriented way how to spawn units...

 

 

 

Those who don't know what we mean with spawning: dcs world allows to create new groups on the fly during the execution of a mission, this in multi player and in single player...

 

When u use MOOSE, you'll use the SPAWN class to spawn new groups dynamically...

 

Let's get a bit deeper in the syntax, while following this explanation. Imagine in the ME, you have an empty mission.

 

Deploy a plane in your mission and give it a group name "Plane", you can also give it a unit name "Plane".

 

Set the Plane late activated.

 

Within your mission script file, write the following:

 


local SpawnPlane = SPAWN:New( "SpawnPlane" )

 

This statement prepares an object called SpawnPlane within your lua environment that you can use to spawn new planes... You can now use the object to spawn a plane like this:

 


local GroupPlane = SpawnPlane:Spawn()

 

The method of object SpawnPlane returns a GROUP class object, which represents the Group of the plane that you just spawned. From here on, you can use the methods of GroupPlane to take further actions or tasks with that Group. Within your running simulator, the new group that has been created has the name SpawnPlane#001.

 

 

 

 

 

 

 

...

 

 

 

 

 

 

 

Sent from mTalk on Windows 10 mobile

[TABLE][sIGPIC][/sIGPIC]|

[/TABLE]

Link to comment
Share on other sites

Next lecture...

 

 

 

Now that we have a SpawnPlane class, you can 'initialize' the object to do some fancy things:

 

1. Limit the amount of units that can be simultaneously alive, and register the maximum amount of groups in the stock... Use the Limit function for this.

 

2. Respawn the group automatically when it has landed... For this you use the Repeat... Methods. There is one for repeating after engine shutdown, and one immediately when it lands.

 

3. You can build visible arrays of units (battalions) before spawning. The Array method is used for that.

 

4. You can randomize the waypoints of each group spawned, so that no group spawned follows the same route. Use the RandomizeRoute method for this...

 

5. You can randomize the group templates (= groups with different unit types), so that way new group spawned will generate a new group type...

 

 

 

There are different SPAWN methods available:

 

Groups can be spawned at different times and methods:

 

SPAWN.Spawn: Spawn one new group based on the last spawned index.

 

SPAWN.ReSpawn: Re-spawn a group based on a given index.

 

SPAWN.SpawnScheduled: Spawn groups at scheduled but randomized intervals. You can use SPAWN.SpawnScheduleStart and SPAWN.SpawnScheduleStop to start and stop the schedule respectively.

 

SPAWN.SpawnFromVec3: Spawn a new group from a Vec3 coordinate. (The group will can be spawned at a point in the air).

 

SPAWN.SpawnFromVec2: Spawn a new group from a Vec2 coordinate. (The group will be spawned at land height ).

 

SPAWN.SpawnFromStatic: Spawn a new group from a structure, taking the position of a STATIC.

 

SPAWN.SpawnFromUnit: Spawn a new group taking the position of a UNIT.

 

SPAWN.SpawnInZone: Spawn a new group in a ZONE.

 

Note that SPAWN.Spawn and SPAWN.ReSpawn return a GROUP#GROUP.New object, that contains a reference to the DCSGroup object. You can use the GROUP object to do further actions with the DCSGroup.

 

 

 

These functions can be combined, like in the following examples:

 

 

 


-- Tests Batumi: Scheduled Spawning

-- --------------------------------

-- Unlimited spawning of groups, scheduled every 30 seconds ...

Spawn_Plane_Scheduled = SPAWN:New( "Spawn Plane Scheduled" ):SpawnScheduled( 30, 0.4 )

Spawn_Helicopter_Scheduled = SPAWN:New( "Spawn Helicopter Scheduled" ):SpawnScheduled( 30, 1 )

Spawn_Ship_Scheduled = SPAWN:New( "Spawn Ship Scheduled" ):SpawnScheduled( 30, 0.5 )

Spawn_Vehicle_Scheduled = SPAWN:New( "Spawn Vehicle Scheduled" ):SpawnScheduled( 30, 0.5 )



-- Tests Tbilisi: Limited Spawning and repeat

-- ------------------------------------------

-- Spawing one group, and respawning the same group when it lands ...

Spawn_Plane_Limited_Repeat = SPAWN:New( "Spawn Plane Limited Repeat" ):Limit( 1, 1 ):InitRepeat():Spawn()

Spawn_Plane_Limited_RepeatOnLanding = SPAWN:New( "Spawn Plane Limited RepeatOnLanding" ):Limit( 1, 1 ):InitRepeatOnLanding():Spawn()

Spawn_Plane_Limited_RepeatOnEngineShutDown = SPAWN:New( "Spawn Plane Limited RepeatOnEngineShutDown" ):Limit( 1, 1 ):InitRepeatOnEngineShutDown():Spawn()

Spawn_Helicopter_Limited_Repeat = SPAWN:New( "Spawn Helicopter Limited Repeat" ):Limit( 1, 1 ):InitRepeat():Spawn()

Spawn_Helicopter_Limited_RepeatOnLanding = SPAWN:New( "Spawn Helicopter Limited RepeatOnLanding" ):Limit( 1, 1 ):InitRepeatOnLanding():Spawn()

Spawn_Helicopter_Limited_RepeatOnEngineShutDown = SPAWN:New( "Spawn Helicopter Limited RepeatOnEngineShutDown" ):Limit( 1, 1 ):InitRepeatOnEngineShutDown():Spawn()





-- Tests Soganlug

-- --------------

-- Limited spawning of groups, scheduled every 30 seconds ...

Spawn_Plane_Limited_Scheduled = SPAWN:New( "Spawn Plane Limited Scheduled" ):Limit( 2, 10 ):SpawnScheduled( 30, 0 )

Spawn_Helicopter_Limited_Scheduled = SPAWN:New( "Spawn Helicopter Limited Scheduled" ):Limit( 2, 10 ):SpawnScheduled( 30, 0 )

Spawn_Ground_Limited_Scheduled = SPAWN:New( "Spawn Vehicle Limited Scheduled" ):Limit( 1, 20 ):SpawnScheduled( 90, 0 )



-- Tests Sukhumi

-- -------------

-- Limited spawning of groups, scheduled every seconds with route randomization.

Spawn_Plane_Limited_Scheduled_RandomizeRoute = SPAWN:New( "Spawn Plane Limited Scheduled RandomizeRoute" ):Limit( 5, 10 ):RandomizeRoute( 1, 1, 4000 ):SpawnScheduled( 2, 0 )

Spawn_Helicopter_Limited_Scheduled_RandomizeRoute = SPAWN:New( "Spawn Helicopter Limited Scheduled RandomizeRoute" ):Limit( 5, 10 ):RandomizeRoute( 1, 1, 4000 ):SpawnScheduled( 2, 0 )

Spawn_Vehicle_Limited_Scheduled_RandomizeRoute = SPAWN:New( "Spawn Vehicle Limited Scheduled RandomizeRoute" ):Limit( 10, 10 ):RandomizeRoute( 1, 1, 1000 ):SpawnScheduled( 1, 0 )





-- Tests Kutaisi

-- -------------

-- Tests the CleanUp functionality.

-- Limited spawning of groups, scheduled every 10 seconds, who are engaging into combat. Some helicopters may crash land on the ground.

-- Observe when helicopters land but are not dead and are out of the danger zone, that they get removed after a while (+/- 180 seconds) and ReSpawn.

Spawn_Helicopter_Scheduled_CleanUp = SPAWN:New( "Spawn Helicopter Scheduled CleanUp" ):Limit( 3, 100 ):RandomizeRoute( 1, 1, 1000 ):CleanUp( 60 ):SpawnScheduled( 10, 0 )

Spawn_Vehicle_Scheduled_CleanUp = SPAWN:New( "Spawn Vehicle Scheduled CleanUp" ):Limit( 3, 100 ):RandomizeRoute( 1, 1, 1000 ):SpawnScheduled( 10, 0 )



-- Maykop

-- ------

-- Creates arrays of groups ready to be spawned and dynamic spawning of groups from another group.



-- SpawnTestVisible creates an array of 200 groups, every 20 groups with 20 meters space in between, and will activate a group of the array every 10 seconds with a 0.2 time randomization.

SpawnTestVisible = SPAWN:New( "Spawn Vehicle Visible Scheduled" ):Limit( 200, 200 ):Array( 59, 20, 30, 30 ):SpawnScheduled( 10, 0.2 )



-- Spawn_Templates_Visible contains different templates...

Spawn_Templates_Visible = { "Spawn Vehicle Visible Template A",

                      "Spawn Vehicle Visible Template B",

                      "Spawn Vehicle Visible Template C",

                      "Spawn Vehicle Visible Template D",

                      "Spawn Vehicle Visible Template E",

                      "Spawn Vehicle Visible Template F",

                      "Spawn Vehicle Visible Template G",

                      "Spawn Vehicle Visible Template H",

                      "Spawn Vehicle Visible Template I",

                      "Spawn Vehicle Visible Template J"

}



-- Spawn_Vehicle_Visible_RandomizeTemplate_Scheduled creates an array of 40 vehicle groups, spread out by 20 groups each, with an 8 meter distance, 

--   and chooses for each group from the templates specified in Spawn_Templates_Visible.



Spawn_Vehicle_Visible_RandomizeTemplate_Scheduled = SPAWN:New( "Spawn Vehicle Visible RandomizeTemplate Scheduled" ):Limit( 80, 80 )

 

 

 

 

 

Ask this is documented here:

 

http://flightcontrol-master.github.io/MOOSE/Moose%20Training/Documentation/Spawn.html

 

 

 

Cheers,

 

Fc

 

Sent from mTalk on Windows 10 mobile

[TABLE][sIGPIC][/sIGPIC]|

[/TABLE]

Link to comment
Share on other sites

  • 9 months later...
  • 1 year later...
How to spawn something in radius around the player or a specific unit?

And not a zone....

 

This is terrible code because at the time I had NO clue about VECs etc. So its messy as can be but works. In any event you should be able to take what I have here and figure out something that works for you.

 

Ignore some of the stuff that doesn't apply obviously. And instead of playerUnit just use the group you want to spawn around. I'm using a Min and Max distance, and Min and Max altitude to randomly spawn between.

 

  local playerPos = POINT_VEC3:NewFromVec3(playerUnit:GetVec3())
 local randHeight = math.random(altitude["Min"][sideToSpawn], altitude["Max"][sideToSpawn])
 D99DebugTrace("randHeight: " .. randHeight)
 local randPosVec2 = playerPos:GetRandomVec2InRadius(UTILS.NMToMeters(spawnDistance["Max"][sideToSpawn]), UTILS.NMToMeters(spawnDistance["Min"][sideToSpawn]))
 local randPos = POINT_VEC3:NewFromVec2(randPosVec2)
 
 -- NOTE: The randHeight in previous call here doesn't seem to be working so lets use SetY instead
 -- FIXME: Not sure this is really setting the altitude properly
 local randPosVec2Height = land.getHeight(randPosVec2)
 D99DebugTrace(UTILS.MetersToFeet(randPosVec2Height))
 randPos:SetY(randPosVec2Height + UTILS.FeetToMeters(randHeight))
 D99DebugTrace(land.getHeight(randPos))
 D99DebugTrace(randPos)
 
 -- newAliasSpawn = SPAWN:NewWithAlias(templateRandom[tempRandGroup], groupAlias):OnSpawnGroup(setREDRoute, playerPos, randPos)
 groupToSpawn[spawnIndex] = SPAWN:NewWithAlias(templateRandom[tempRandGroup], groupAlias):OnSpawnGroup(setREDRoute, playerPos, randPos):SpawnFromVec3(randPos)
 

Link to comment
Share on other sites

  • 3 months later...

Hi,

As usual, thanks for all the work involved in MOOSE.

I'm pretty noob with its use but I've already used for some tasks.

Now, I would like to use the InitKeepUnitNames() function to be sure the name of a ground spawned unit always have the same name, to later use the DCS Mission Editor native function GROUP DEAD.

 

By default each new group spawned by MOOSE has the Suffix #001, #002 and so on in case of multiple spawn.

 

For the actual logic of my mission only once group alive at time is possible to spawn, so, should be fine to force the name without any suffix to use GROUP DEAD.

 

I try:

Spawn_Red_Counter_Attack_1 = SPAWN:New( "RedSochiCounterAttack" ):InitKeepUnitNames()
Spawn_Red_Counter_Group_1 = Spawn_Red_Counter_Attack_1:Spawn()

or single line style:

Spawn_Red_Counter_Attack_1 = SPAWN:New( "RedSochiCounterAttack" ):InitKeepUnitNames():Spawn()

 

But my units is always spawned as RedSochiCounterAttack#001, where is my error?

 

 

EDIT:

 

Tiredness made me forget the coding rudiments, omitting the parameter

 

Spawn_Red_Counter_Attack_1 = SPAWN:New( "RedSochiCounterAttack" ):InitKeepUnitNames( true ):Spawn()

 

But I also notice that it's talk about "unit name", it's not working for Group?

There is an analogue method for group name?

 

 

Thanks


Edited by Maverick87Shaka

FlighRIG => CPU: RyZen 5900x | RAM: 64GB Corsair 3000Mhz | GPU: nVIDIA RTX 4090 FE | OS Storage: SSD NVMe Samsung 850 Pro 512GB, DCS Storage: SSD NVMe Sabrent 1TB | Device: Multipurpose-UFC, VirPil T-50, TM WARTHOG Throttle, TrackHat, MFD Cougar with screen.

Our Servers => [ITA] Banshee | Krasnodar - PvE | PersianConquest PvE Live Map&Stats | Syria Liberation PvE Conquest

Support us on twitch subscribing with amazon prime account linked, it's free!

Link to comment
Share on other sites

Now, I would like to use the InitKeepUnitNames() function to be sure the name of a ground spawned unit always have the same name, to later use the DCS Mission Editor native function GROUP DEAD.

 

For the actual logic of my mission only once group alive at time is possible to spawn, so, should be fine to force the name without any suffix to use GROUP DEAD.

 

Why do you need to use GROUP DEAD, exactly?

Also, can't you achieve the same goal using MOOSE scripts only?

Link to comment
Share on other sites

Why do you need to use GROUP DEAD, exactly?

Also, can't you achieve the same goal using MOOSE scripts only?

 

Yes, I finally moved the logic out of Mission Editor and put all in the moose script:

 

Spawn_Red_Counter_Attack_1 = SPAWN:New( "RedSochiCounterAttack" )
Spawn_Red_Counter_Group_1 = Spawn_Red_Counter_Attack_1:Spawn()

if Spawn_Red_Counter_Group_1:IsAlive() == nil then
 trigger.setUserFlag( 1121, true )
end

 

And it's work! When the group dead the flag 1121 is set ON.

 

Thanks for suggestion :thumbup:

FlighRIG => CPU: RyZen 5900x | RAM: 64GB Corsair 3000Mhz | GPU: nVIDIA RTX 4090 FE | OS Storage: SSD NVMe Samsung 850 Pro 512GB, DCS Storage: SSD NVMe Sabrent 1TB | Device: Multipurpose-UFC, VirPil T-50, TM WARTHOG Throttle, TrackHat, MFD Cougar with screen.

Our Servers => [ITA] Banshee | Krasnodar - PvE | PersianConquest PvE Live Map&Stats | Syria Liberation PvE Conquest

Support us on twitch subscribing with amazon prime account linked, it's free!

Link to comment
Share on other sites

  • 1 month later...

Uhm,

I'm now facing another problem using moose to spawn this ground unit.

I would like to set up a couple of helicopter that follow the brand new spawned ground convoy.

With the Mission Editor you can set task for escort a ground group, but it's looking for specific group name, and of course it's not finding the group name since has the counter #001 etc. appended to the end of the name.

 

There is a way to change the escort task target with the name given by the MOOSE?

 

Thanks

FlighRIG => CPU: RyZen 5900x | RAM: 64GB Corsair 3000Mhz | GPU: nVIDIA RTX 4090 FE | OS Storage: SSD NVMe Samsung 850 Pro 512GB, DCS Storage: SSD NVMe Sabrent 1TB | Device: Multipurpose-UFC, VirPil T-50, TM WARTHOG Throttle, TrackHat, MFD Cougar with screen.

Our Servers => [ITA] Banshee | Krasnodar - PvE | PersianConquest PvE Live Map&Stats | Syria Liberation PvE Conquest

Support us on twitch subscribing with amazon prime account linked, it's free!

Link to comment
Share on other sites

  • 2 months later...

Can anyone explain to me the route randomisation? Is the first number the number of the first waypoint randomised, the second number the waypoint where randomisation ends, and the third the radius of randomisation? If so ehst foes (1, 1, 1000) do? I see similar to this with equal firdt two numbers. Confused!

Link to comment
Share on other sites

Can anyone explain to me the route randomisation? Is the first number the number of the first waypoint randomised, the second number the waypoint where randomisation ends, and the third the radius of randomisation? If so ehst foes (1, 1, 1000) do? I see similar to this with equal firdt two numbers. Confused!

 

What specific method are you talking about? If it is like other Route waypoint numbers. The first number is typically the first waypoint from the START and the 2nd one is the number of waypoints from the END. So (1, 1) would mean first and last waypoint. (2,2) would be the 2nd waypoint to the 2nd last waypoint.

 

But it depends exactly what method you are talking about.

Link to comment
Share on other sites

Any idea why when I include the limit function nothing spawn? Without it FLIGHT1 repeatedly spawns every 30 seconds, as expected. I want just two to spawn and if one dies another spawns to take its place.

 

flight1 = SPAWN:New(FLIGHT1):Limit(2,10):SpawnScheduled(30,0)

flight1:spawn()

Link to comment
Share on other sites

Any idea why when I include the limit function nothing spawn? Without it FLIGHT1 repeatedly spawns every 30 seconds, as expected. I want just two to spawn and if one dies another spawns to take its place.

 

flight1 = SPAWN:New(FLIGHT1):Limit(2,10):SpawnScheduled(30,0)

flight1:spawn()

 

 

 

This works

 

local flight1=SPAWN:New("FLIGHT1"):InitLimit( 2, 10):SpawnScheduled(30,0)

flight1:InitRepeatOnLanding()

flight1:Spawn()

 

 

but for some reason this spawns three units not 2.

Link to comment
Share on other sites

@markbond

 

I might be mistaken, but I believe that :SpawnScheduled(30,0) will spawn groups on its own.

If you combine it with flight1:Spawn(), then that'll trigger another spawn.

 

You might have a situation in which several spawn triggers are running at the same time, messing with each other.

 

If I were you, I'd get rid of :SpawnScheduled(30,0).

If you want to spawn new groups, do it "manually" ( use flight1:Spawn() ), that has always worked for me.

 

Also, spawning individual units from a group might not be possible. As far as I know, this method only works for groups as a whole. You could always use single unit "groups", that would work.

 

Finally, perhaps you'll find :OnSpawnGroup() useful (you could use it to program new spawns when the group dies, lands, etc.)


Edited by Hardcard
Link to comment
Share on other sites

This works

 

local flight1=SPAWN:New("FLIGHT1"):InitLimit( 2, 10):SpawnScheduled(30,0)

flight1:InitRepeatOnLanding()

flight1:Spawn()

 

 

but for some reason this spawns three units not 2.

 

This should be written like so otherwise you'll likely get some very odd behaviour:

 

local flight1=SPAWN:New("FLIGHT1"):InitLimit( 2, 10):InitRepeatOnLanding():SpawnScheduled(30,0)

 

Initially your error was that you had Limit() instead of InitLimit().

 

This would have shown up in an error most likely in your dcs.log file. Whenever something isn't working have a look there for errors.

Link to comment
Share on other sites

  • 1 year later...
  • Recently Browsing   0 members

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