Jump to content

MOOSE - Mission Object Oriented Scripting Framework


Recommended Posts

Delta99,

Yes, I am calling the AI_A2A_GCICAP function with the trigger "do script" action.

 

I load the moose.lau file at mission start, then create radio options if a fighter client is selected. Based on the radio option selected, I use a trigger to do a script to set the variable. I am setting this as a global variable and then running another trigger to call the GCICAP function.

 

You would probably need to load the mission file in DCS to see the triggers (6 in total)

Link to comment
Share on other sites

Hey,

 

Again, a (maybe) silly question ;)

 

Within a scheduled spawn-trigger I try to run a specific function for Groups which are being spawned with it.

The following is the code

 

            RussianConvoyNorth1 = SPAWN:New( "Warg" ):InitLimit( 40, 5 ):SpawnScheduled( 180, 0 )
           :OnSpawnGroup(
             function(MooseGroup)
             BASE:E("Spawn!")
                   for UnitId, UnitData in pairs( MooseGroup:GetUnits() ) do
                     local UnitAction = UnitData -- Wrapper.Unit#UNIT
                       BASE:E(UnitAction.GetName())
                   end
             end)

 

But my problem is, that I get the following error:

 

00164.118 INFO    SCRIPTING: Error in timer function: [string "C:\Users\Julian\AppData\Local\Temp\DCS\/~mis00003C62"]:8987: attempt to index local 'self' (a nil value)
00164.118 INFO    SCRIPTING: stack traceback:
[string "C:\Users\Julian\AppData\Local\Temp\DCS\/~mis00003C62"]:2536: in function <[string "C:\Users\Julian\AppData\Local\Temp\DCS\/~mis00003C62"]:2533>
[string "C:\Users\Julian\AppData\Local\Temp\DCS\/~mis00003C62"]:8987: in function 'GetName'
[string "C:\Users\Julian\AppData\Local\Temp\DCS\/~mis00007272"]:66: in function <[string "C:\Users\Julian\AppData\Local\Temp\DCS\/~mis00007272"]:62>
(tail call): ?
[C]: in function 'xpcall'
[string "C:\Users\Julian\AppData\Local\Temp\DCS\/~mis00003C62"]:2565: in function <[string "C:\Users\Julian\AppData\Local\Temp\DCS\/~mis00003C62"]:2531>

 

I also tried to use "UnitAction.GetName()" as I get with the auto-completion, but same error....what do I do wrong here?

A bit difficult to understand the documentation in combination with the limited debugging possibilities...

 

Thanks!

kreisch

Link to comment
Share on other sites

Just a quick response. Try putting the OnSpawnGroup() before SpawnScheduled().

 

Hey,

 

Again, a (maybe) silly question ;)

 

Within a scheduled spawn-trigger I try to run a specific function for Groups which are being spawned with it.

The following is the code

 

            RussianConvoyNorth1 = SPAWN:New( "Warg" ):InitLimit( 40, 5 ):SpawnScheduled( 180, 0 )
           :OnSpawnGroup(
             function(MooseGroup)
             BASE:E("Spawn!")
                   for UnitId, UnitData in pairs( MooseGroup:GetUnits() ) do
                     local UnitAction = UnitData -- Wrapper.Unit#UNIT
                       BASE:E(UnitAction.GetName())
                   end
             end)

 

But my problem is, that I get the following error:

 

00164.118 INFO    SCRIPTING: Error in timer function: [string "C:\Users\Julian\AppData\Local\Temp\DCS\/~mis00003C62"]:8987: attempt to index local 'self' (a nil value)
00164.118 INFO    SCRIPTING: stack traceback:
[string "C:\Users\Julian\AppData\Local\Temp\DCS\/~mis00003C62"]:2536: in function <[string "C:\Users\Julian\AppData\Local\Temp\DCS\/~mis00003C62"]:2533>
[string "C:\Users\Julian\AppData\Local\Temp\DCS\/~mis00003C62"]:8987: in function 'GetName'
[string "C:\Users\Julian\AppData\Local\Temp\DCS\/~mis00007272"]:66: in function <[string "C:\Users\Julian\AppData\Local\Temp\DCS\/~mis00007272"]:62>
(tail call): ?
[C]: in function 'xpcall'
[string "C:\Users\Julian\AppData\Local\Temp\DCS\/~mis00003C62"]:2565: in function <[string "C:\Users\Julian\AppData\Local\Temp\DCS\/~mis00003C62"]:2531>

 

I also tried to use "UnitAction.GetName()" as I get with the auto-completion, but same error....what do I do wrong here?

A bit difficult to understand the documentation in combination with the limited debugging possibilities...

 

Thanks!

kreisch

Link to comment
Share on other sites

Seems to me like some examples and docs are not consistent. I think the proper way is to pass the first 3 parameters as lists rather than strings even if a single element.

 

However, when I tried your mission I did not get any errors but I didn't fly towards the zones either.

 

But try this:

GCICAP_Red = AI_A2A_GCICAP:New({"EWR Red"}, {AirTgtType}, {"Cap Red1", "Cap Red2"}, 2, nil, nil, nil, 6)

 

Delta99,

Yes, I am calling the AI_A2A_GCICAP function with the trigger "do script" action.

 

I load the moose.lau file at mission start, then create radio options if a fighter client is selected. Based on the radio option selected, I use a trigger to do a script to set the variable. I am setting this as a global variable and then running another trigger to call the GCICAP function.

 

You would probably need to load the mission file in DCS to see the triggers (6 in total)

Link to comment
Share on other sites

Seems to me like some examples and docs are not consistent. I think the proper way is to pass the first 3 parameters as lists rather than strings even if a single element.

 

However, when I tried your mission I did not get any errors but I didn't fly towards the zones either.

 

But try this:

 

 

Thanks Delta99. I am now truly stumped.

 

It does not seem to matter whether I pass the parameters as lists or strings. Neither would crash but they would also not generate the CAP flight. What I found is that if I use the exact same AI_A2A_GCICAP function call and hard code the strings in the "Mission Start" trigger, it will generate a cap flight. However, if I take the exact same code and try to execute it as a result of a custom radio option selection, nothing happens. I can tell the trigger fires by passing a message to the screen. The function however does not generate any CAP flight. :helpsmilie:

Link to comment
Share on other sites

Strange although it might be something odd with the scope of the trigger code with Moose or anything for that matter.

 

What you might want to do is convert the trigger into plain Moose mission script. You can easily create menu options with Moose to do what you are doing in the ME as well to launch the way you want to. That will probably be the ticket.

 

Thanks Delta99. I am now truly stumped.

 

It does not seem to matter whether I pass the parameters as lists or strings. Neither would crash but they would also not generate the CAP flight. What I found is that if I use the exact same AI_A2A_GCICAP function call and hard code the strings in the "Mission Start" trigger, it will generate a cap flight. However, if I take the exact same code and try to execute it as a result of a custom radio option selection, nothing happens. I can tell the trigger fires by passing a message to the screen. The function however does not generate any CAP flight. :helpsmilie:

Link to comment
Share on other sites

Strange although it might be something odd with the scope of the trigger code with Moose or anything for that matter.

 

What you might want to do is convert the trigger into plain Moose mission script. You can easily create menu options with Moose to do what you are doing in the ME as well to launch the way you want to. That will probably be the ticket.

 

Might be pushing the upper limits of my coding capabilities... Do you happen to have a sample script or example of using Moose framework to create a radio option?

Link to comment
Share on other sites

Hey guys,

 

And my quest continues :D

 

So, now I have almost reached what I want.

 

The following is my code:

 

Messenger = SCHEDULER:New(nil, 
function()
--if not Poticlear then
   if  RussianTroopsPoti:AnyCompletelyInZone(PotiZone) then
   BASE:E("Spawn Triggered")
           --Poticlear = true
           RussianConvoyNorth1 = SPAWN:New( "Warg" )

             :InitLimit( 40, 5 ):SpawnScheduled( 180, 0 )
                         :OnSpawnGroup(
             function(MooseGroup)
             BASE:E("Spawn!")
             local pivot = 0
                   for UnitId, UnitData in pairs( MooseGroup:GetUnits() ) do
                     local UnitAction = UnitData -- Wrapper.Unit#UNIT

                       --BASE:E(UnitAction:GetName())
                       BASE:E(UnitAction:GetTypeName())
                         if pivot % 2 == 0 then
                             AddDismounts(UnitAction:GetName(), "ZU-23")
                           else
                             AddDismounts(UnitAction:GetName(), "Rifle")
                           end
                         pivot = pivot + 1
                   end
             end)

   end
end,
{} ,20 ,10)

 

This basically spawns the group "warg" every 180 seconds, when "RussianTroopsPoti" arrived in "PotiZone".

To reduce load of the server I reduced the interval the scheduler is requested.

 

Each new spawned group shall get the command "AddDismounts(UnitAction:GetName(), "ZU-23")" ONCE (I also switch between ZU-23 and a usual rifle squad but this is not my point here).

 

The problem is, that the command is run EVERY time my scheduler fires, so it is run every 10 seconds leading to a server exploding in spawnen hundreds of troops :D

 

I thought the "OnSpawnGroup()" Method would only be fired once- when the group spawns.

 

Do you see my error?

 

BR,

kreisch

Link to comment
Share on other sites

Hey guys,

 

And my quest continues :D

 

So, now I have almost reached what I want.

 

The following is my code:

 

Messenger = SCHEDULER:New(nil, 
function()
--if not Poticlear then
   if  RussianTroopsPoti:AnyCompletelyInZone(PotiZone) then
   BASE:E("Spawn Triggered")
           --Poticlear = true
           RussianConvoyNorth1 = SPAWN:New( "Warg" )

             :InitLimit( 40, 5 ):SpawnScheduled( 180, 0 )
                         :OnSpawnGroup(
             function(MooseGroup)
             BASE:E("Spawn!")
             local pivot = 0
                   for UnitId, UnitData in pairs( MooseGroup:GetUnits() ) do
                     local UnitAction = UnitData -- Wrapper.Unit#UNIT

                       --BASE:E(UnitAction:GetName())
                       BASE:E(UnitAction:GetTypeName())
                         if pivot % 2 == 0 then
                             AddDismounts(UnitAction:GetName(), "ZU-23")
                           else
                             AddDismounts(UnitAction:GetName(), "Rifle")
                           end
                         pivot = pivot + 1
                   end
             end)

   end
end,
{} ,20 ,10)

This basically spawns the group "warg" every 180 seconds, when "RussianTroopsPoti" arrived in "PotiZone".

To reduce load of the server I reduced the interval the scheduler is requested.

 

Each new spawned group shall get the command "AddDismounts(UnitAction:GetName(), "ZU-23")" ONCE (I also switch between ZU-23 and a usual rifle squad but this is not my point here).

 

The problem is, that the command is run EVERY time my scheduler fires, so it is run every 10 seconds leading to a server exploding in spawnen hundreds of troops :D

 

I thought the "OnSpawnGroup()" Method would only be fired once- when the group spawns.

 

Do you see my error?

 

BR,

kreisch

 

 

Your last Line of code says :"Do this every 10 seconds for 20 Times.

 

You should have a look at the SCHEDULE method!?

 

Regards

My Rig: Windows 11 Pro, Intel i7-13700k@5.4GHz, 64GB DDR5 5200 RAM, Gigabyte Z790 AORUS Elite AX, 1TB Samsung EVO 970, RTX4080, Thrustmaster HOTAS WARTHOG + Saitek Pro Flight Pedals, LG 32" 4K 60FPS, ACER 30" 4K 60FPS GSync Display, HP Reverb G2 V2

Link to comment
Share on other sites

Your last Line of code says :"Do this every 10 seconds for 20 Times.

 

You should have a look at the SCHEDULE method!?

 

Regards

 

Uh...yes and no.

 

Let me explain.

 

I know that my trigger is repeated several times.

Still, why is the "OnSpawn" method repeated in situations when the group IS NOT spawned? This is not as I would expect.

 

The reason I use the outer scheduler is, that I want to check if a specific zone is clear of units or not.

Only if the condition is as wished, I want the scheduler to start his spawning task, and additionally, each group that spawns shall do a specific functionalitiy.

So my question is, why is this method called in situations when the group is not spawned and only the outer scheduler fires?

 

br,

kreisch

Link to comment
Share on other sites

Something is strange in your code. Why are putting a timer function into a timer function? Also you are redefining RussianConvoyNorth1 every 20 second if PotiZone is empty.

 

My guess is that the strange behavior of OnSpawnGroup is that you are re respawning, RussianConvoyNorth1 every 20 sec.


Edited by Wingthor
Link to comment
Share on other sites

Right,but any 20 sec. if zone is empty you redefining

RussianConvoyNorth1.

 

What you wanna do is to make a zone template outside scheduler, like:

 

RussianConvoyNorth1Template = SPAWN:New( "Warg" ):InitLimit( 40, 5 )
:OnSpawnGroup(
   function(MooseGroup)
     BASE:E("Spawn!")
     local pivot = 0
     for UnitId, UnitData in pairs( MooseGroup:GetUnits() ) do
       local UnitAction = UnitData -- Wrapper.Unit#UNIT
       --BASE:E(UnitAction:GetName())
       BASE:E(UnitAction:GetTypeName())
       if pivot % 2 == 0 then
         AddDismounts(UnitAction:GetName(), "ZU-23")
       else
         AddDismounts(UnitAction:GetName(), "Rifle")
       end
       pivot = pivot + 1
     end
   end)

Messenger = SCHEDULER:New(nil, 
function()
--if not Poticlear then
   if  RussianTroopsPoti:AnyCompletelyInZone(PotiZone) then
     BASE:E("Spawn Triggered")
     RussianConvoyNorth1Template:SpawnScheduled( 180, 0 )
   end
end,
{} ,20 ,10)

(NOT TEST CODE)

And call the Spawn from within time scheduler. However

SpawnScheduled( 180, 0 ) 

is a scheduler by it self and will spawn a new group each 3 minute.

However I am not 100% confident about what you want.

 

Will this "Warg" group spawn inside PotiZone?


Edited by Wingthor
  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

A quick question about syntax. When I Spawn in Zone, like here:

 

BlueSpawn3 = SPAWN

:New( "Blue Strike 1" )

:InitLimit( 4, 10 )

:SpawnInZone( BluelaunchZone, true )

 

How do I add that the spawning should be scheduled? I wrote:

 

BlueSpawn3 = SPAWN

:New( "Blue Strike 1" )

:InitLimit( 4, 10 )

:SpawnInZone( BluelaunchZone, true )

:Scheduled( 300, 0)

 

But that doesn't seem to be the correct syntax?

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

A quick question about syntax. When I Spawn in Zone, like here:

 

BlueSpawn3 = SPAWN

:New( "Blue Strike 1" )

:InitLimit( 4, 10 )

:SpawnInZone( BluelaunchZone, true )

 

How do I add that the spawning should be scheduled? I wrote:

 

BlueSpawn3 = SPAWN

:New( "Blue Strike 1" )

:InitLimit( 4, 10 )

:SpawnInZone( BluelaunchZone, true )

:Scheduled( 300, 0)

 

But that doesn't seem to be the correct syntax?

Should be :SpawnScheduled( interval, randomizationfactor ) if I'm not mistaken.

 

So ... :SpawnScheduled ( 300, 0.5 ) will spawn the group in a random interval between 150 to 450 seconds.

Shagrat

 

- Flying Sims since 1984 -:pilotfly:

Win 10 | i5 10600K@4.1GHz | 64GB | GeForce RTX 3090 - Asus VG34VQL1B  | TrackIR5 | Simshaker & Jetseat | VPForce Rhino Base & VIRPIL T50 CM2 Stick on 200mm curved extension | VIRPIL T50 CM2 Throttle | VPC Rotor TCS Plus/Apache64 Grip | MFG Crosswind Rudder Pedals | WW Top Gun MIP | a hand made AHCP | 2x Elgato StreamDeck (Buttons galore)

Link to comment
Share on other sites

A quick question about syntax. When I Spawn in Zone, like here:

 

BlueSpawn3 = SPAWN

:New( "Blue Strike 1" )

:InitLimit( 4, 10 )

:SpawnInZone( BluelaunchZone, true )

 

How do I add that the spawning should be scheduled? I wrote:

 

BlueSpawn3 = SPAWN

:New( "Blue Strike 1" )

:InitLimit( 4, 10 )

:SpawnInZone( BluelaunchZone, true )

 

 

 

But that doesn't seem to be the correct syntax?

 

SpawInZone will execute the spawn. Same with SpawnScheduled. Look for all the commands prefixed with Init. These will defined the Spawn Settings. If you look at Moose docs, you will find InitRandomizeZones which takes a table of Zones as argument. By give a table with only one Zone I guess will achieve what your want by use SpawnScedueld.

 

So if you have BluelaunchZone (A Zone defined in Mission Editor (ME)) you use

 

BluelaunchZone = ZONE:New("Bluelaunch") -- What ever its called in ME
SpawnArray = {BluelaunchZone}

BlueSpawn3 = SPAWN
:New( "Blue Strike 1" )
:InitLimit( 4, 10 )
:InitRandomizeZones(SpawnArray)
:SpawnScheduled(10, 0.20) -- Will spawn a new group each 10 sec, with 20% variation, Limit is 4 

Hope this works for you :)

 

Also you can have a look here

 

Regards

  • Like 1
Link to comment
Share on other sites

First off... I'm a MOOSE for Dummies subscriber, Dummie being the key word. Really, all this scripting is new to me, but hey why not. So, for a week or two, I've had nothing, NOTHING but trouble getting this to work. Went through all the setup vids and example stuff step by step (numerous times). Every now and then it would work, like the AI_A2A_GCICAP demonstration mission, sort of (on 2.2... not so much 1.5.) In fact, about the only time anything ever ran without an error, is when I loaded everythingl (.miz / .lua) from the MOOSE_MISSIONS repository

 

So, having deleted and reinstalled all the latest stuff (LDT 1.4.1) and MOOSE 2.2.6/Moose_Missions, and having religiously followed all the setup vids... here's what happens. I slowly go through setup and build the simple Spawn mission (like in the vid). I hit "Fly" to run the mission and get two errors... the one below and another talking about SPAWN being a nil value. Then the mission starts (a Heli is supposed to spawn and fly around and land) nothing... nothing happens. Why is EVENT and SPAWN "nil values"?

 

[string

'C:\Users\xxx\AppData\Local\Temp\/DCS~mis000000920']:4: attempt to index 'EVENT' (a nil value) slack traceback:

[C]: ?

[string

'C:\users\xxx\AppData\Local\Temp\DCS\/~mis000000920']:4: in main chunk

 

AM I screwing something simple here? I mean, this is not a huge complicated script.

Link to comment
Share on other sites

[string

'C:\Users\xxx\AppData\Local\Temp\/DCS~mis000000920']:4: attempt to index 'EVENT' (a nil value) slack traceback:

[C]: ?

[string

'C:\users\xxx\AppData\Local\Temp\DCS\/~mis000000920']:4: in main chunk

 

AM I screwing something simple here? I mean, this is not a huge complicated script.

 

Its hard to say based on this info. I wonder if you can share your troubled code with us, especially line 4 in your script is of interests. :)

Link to comment
Share on other sites

The first thing you should make sure you do is check your DCS.log file to make sure that Moose is actually loading. I bet you are missing something simple in the setup. In the log file you will see where Moose is initialized and also an indication of the version. Post that here.

 

First off... I'm a MOOSE for Dummies subscriber, Dummie being the key word. Really, all this scripting is new to me, but hey why not. So, for a week or two, I've had nothing, NOTHING but trouble getting this to work. Went through all the setup vids and example stuff step by step (numerous times). Every now and then it would work, like the AI_A2A_GCICAP demonstration mission, sort of (on 2.2... not so much 1.5.) In fact, about the only time anything ever ran without an error, is when I loaded everythingl (.miz / .lua) from the MOOSE_MISSIONS repository

 

So, having deleted and reinstalled all the latest stuff (LDT 1.4.1) and MOOSE 2.2.6/Moose_Missions, and having religiously followed all the setup vids... here's what happens. I slowly go through setup and build the simple Spawn mission (like in the vid). I hit "Fly" to run the mission and get two errors... the one below and another talking about SPAWN being a nil value. Then the mission starts (a Heli is supposed to spawn and fly around and land) nothing... nothing happens. Why is EVENT and SPAWN "nil values"?

 

[string

'C:\Users\xxx\AppData\Local\Temp\/DCS~mis000000920']:4: attempt to index 'EVENT' (a nil value) slack traceback:

[C]: ?

[string

'C:\users\xxx\AppData\Local\Temp\DCS\/~mis000000920']:4: in main chunk

 

AM I screwing something simple here? I mean, this is not a huge complicated script.

Link to comment
Share on other sites

The first thing you should make sure you do is check your DCS.log file to make sure that Moose is actually loading. I bet you are missing something simple in the setup. In the log file you will see where Moose is initialized and also an indication of the version. Post that here.

 

Awesome, thanks. It wasn't loading... although I kinda figured that. So, I tried the straight moose.lua downloaded from the releases tab on Github. That worked, sheesh.

 

But why? Had been using the one from the source zip (as in the setup demonstration vid), as well as the one from the master. I don't get it why they would not work. The most confusing issue I was having was "sometimes" the others worked and sometimes not... I never could nail anything down with all the inconsistency. Still worried I have something wrong on the LDT side of things.


Edited by Mikkall
Link to comment
Share on other sites

Awesome, thanks. It wasn't loading... although I kinda figured that. So, I tried the straight moose.lua downloaded from the releases tab on Github. That worked, sheesh.

 

But why? Had been using the one from the source zip (as in the setup demonstration vid), as well as the one from the master. I don't get it why they would not work. The most confusing issue I was having was "sometimes" the others worked and sometimes not... I never could nail anything down with all the inconsistency. Still worried I have something wrong on the LDT side of things.

 

You really don't need the LDT setup if you just want to use the framework and have fun. Download the base MOOSE lua (there's one that someone pared down to minimum size for faster loading), download the script examples and download Notepad++ to edit .lua files, enjoy yourself. Sven and his compatriots have a hell of a tool there but Sven's "setup" is geared more towards experienced developers.

Win 10 | i7 4770 @ 3.5GHz | 32GB DDR3 | 6 GB GTX1060

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...