Jump to content

I need a little help with a Moose script.


Knock-Knock

Recommended Posts

I dont know scripting, I dont script/program (tried many times but very programming illiterate sadly), so I find and scavenge your great work here on the forum. But Im stuck and really need a little more functionality to a Moose respawn script that I found on here, but Im unable to find or create exactly what I need.

 

do
Spawn_E3A = SPAWN:New("NATO E-3A Sentry")
Spawn_E3A:InitLimit( 1, 0 ):SpawnScheduled( 60, 0 )
Spawn_E3A:InitRepeatOnEngineShutDown()
end

 

This is what Im using, but I need for it to rely on a flag being true. So if for example Flag 1 is true, then the spawn/respawn sequence becomes active. If Flag 1 is false, then the spawn/respawn sequence is idle (plane wont spawn). Any help very appreciated.

- Jack of many DCS modules, master of none.

- Personal wishlist: F-15A, F-4S Phantom II, JAS 39A Gripen, SAAB 35 Draken, F-104 Starfighter, Panavia Tornado IDS.

 

| Windows 11 | i5-12400 | 64Gb DDR4 | RTX 3080 | 2x M.2 | 27" 1440p | Rift CV1 | Thrustmaster Warthog HOTAS | MFG Crosswind pedals |

Link to comment
Share on other sites

Learning the basics of Lua is easier than it seems, plus it'll unlock a whole new world of possibilities for you.

 

 

In this case, you need to write an if...else statement/check + the DCS method to get flag values.

 

Put it all together:

Spawn_E3A = SPAWN:New("NATO E-3A Sentry")
Spawn_E3A:InitLimit( 1, 0 )

if trigger.misc.getUserFlag("1") == 1 then [color="Blue"]-- [i][b]if[/b][/i] statement/check using [i][b]getUserFlag()[/b]. If flag 1 is true (meaning it's set to 1), the three lines below it will execute[/i][/color]
   
    Spawn_E3A:InitRepeatOnEngineShutDown()
    Spawn_E3A:SpawnScheduled( 60, 0 )  [color="blue"]-- This defines and starts the spawning scheduler[/color]
    Spawn_E3A:SpawnScheduleStart()  [color="blue"]-- This should restart the spawning scheduler, in case it has been stopped[/color]

else [color="Blue"]-- This is an [i][b]else[/b][/i] statement/check, which will execute the line below if the first statement/check isn't true (flag 1 isn't true)[/color]
    
    Spawn_E3A:SpawnScheduleStop() [color="blue"]-- This should stop the spawning scheduler[/color]
end

[color="Blue"]-- Note that this [i][b]if...else[/b][/i] statement/check should be placed inside a scheduler (in order to periodically check the state of flag 1)
-- But putting schedulers inside other schedulers will create unnecessary complications, I'd rather simplify the script by getting rid of the spawning scheduler and writing a custom one[/color]

[color="Blue"]-- Like this:[/color]

Spawn_E3A = SPAWN:New("NATO E-3A Sentry")
Spawn_E3A:InitLimit( 1, 0 )

local function FlagChecker()

  if trigger.misc.getUserFlag("1") == 1 then 
      
      Spawn_E3A:InitRepeatOnEngineShutDown()
      Spawn_E3A:Spawn()
      
      return timer.getTime() + 60
  end
end

timer.scheduleFunction(FlagChecker, nil, timer.getTime() + 1)

 

 

 

Lua tutorial for newbies --> https://www.tutorialspoint.com/lua/index.htm

 

Standard DCS scripting documentation --> https://wiki.hoggitworld.com/view/Simulator_Scripting_Engine_Documentation

 

MOOSE documentation --> https://flightcontrol-master.github.io/MOOSE_DOCS/Documentation/index.html


Edited by Hardcard
Link to comment
Share on other sites

Thank you Hardcard :thumbup:.

 

Seems it will only spawn, if the flag is on before the script is loaded. If I set the flag on after the script is loaded, no spawn. Also if I set the Flag on before, get a spawn, change the flag to off, it wont stop the respawning.

 

I guess I didnt explain that very well in my first post.

 

My attention is, that I want to switch given 'respawn' flights on and off as the mission progresses.

- Jack of many DCS modules, master of none.

- Personal wishlist: F-15A, F-4S Phantom II, JAS 39A Gripen, SAAB 35 Draken, F-104 Starfighter, Panavia Tornado IDS.

 

| Windows 11 | i5-12400 | 64Gb DDR4 | RTX 3080 | 2x M.2 | 27" 1440p | Rift CV1 | Thrustmaster Warthog HOTAS | MFG Crosswind pedals |

Link to comment
Share on other sites

Alternative, you can do:

 

MISSION START > no condition > Do Script File (load Moose library)

ONCE > your flag condition > flag 1 is true

ONCE > if flag 1 is true > do script (here insert your little moose script from your first post)

 

Hmm, but can I turn them off again, as in can I stop the script?

- Jack of many DCS modules, master of none.

- Personal wishlist: F-15A, F-4S Phantom II, JAS 39A Gripen, SAAB 35 Draken, F-104 Starfighter, Panavia Tornado IDS.

 

| Windows 11 | i5-12400 | 64Gb DDR4 | RTX 3080 | 2x M.2 | 27" 1440p | Rift CV1 | Thrustmaster Warthog HOTAS | MFG Crosswind pedals |

Link to comment
Share on other sites

Hmmm, depends what trigger your flag.

If you trigger by F10 comm menu, then you can do (using Hardcard's code):

 

A)

MISSION START >

no condition >

- Do Script File (load Moose library)

- radio item add: ACTIVATE / FLAG 1 / VALUE 1

- do script:

 
--this is needed so we can use it later
Spawn_E3A = SPAWN:New("NATO E-3A Sentry") 
Spawn_E3A:InitLimit( 1, 0 )

 

B)

SWITCHED CONDITION >

FLAG 1 = 1 >

- do script (start spawn):

   Spawn_E3A:InitRepeatOnEngineShutDown()
  Spawn_E3A:SpawnScheduled( 60, 0 ) 
  Spawn_E3A:SpawnScheduleStart()

- radio item remove: ACTIVATE

- FLAG 1 = false

- radio item add: DEACTIVATE / FLAG 1 / VALUE 2

 

C)

SWITCHED CONDITION >

FLAG 1 = 2 >

- do script (stop spawn):

  
Spawn_E3A:SpawnScheduleStop() 

- radio item remove: DEACTIVATE

- FLAG 1 = false

- radio item add: ACTIVATE / FLAG 1 / VALUE 1

 

Now let me explain:

 

A) - we load moose, then we define the spawn plane, so it can be used in all scripts. Then, we add to F10 comm menu the option to spawn (ACTIVATE). This will set Flag 1 to value 1

 

B) - if Flag 1 value is 1, then: the spawn schedule will start, the option to activate another plane will be removed from F10 menu, Flag 1 will be reseted to false (so it can be reactivated later)

 

Instead, we will add an option to stop the spawns (DEACTIVATE).

If we don't use DEACTIVATE, Moose will spawn a plane each 60 seconds. If we use it, then:

 

C) - it will stop the spawn and schedule, then it will remove DEACTIVATE option from F10 menu, reset again Flag 1, and add back ACTIVATE and the cycle will start again.

 

Using SWITCHED CONDITION trigger, we can use it how many times we want.

 

This can be achieved in many ways, but maybe is good for you to try learnig a bit from all: LUA, MOOSE and ME triggers :)

Link to comment
Share on other sites

Seems it will only spawn, if the flag is on before the script is loaded. If I set the flag on after the script is loaded, no spawn. Also if I set the Flag on before, get a spawn, change the flag to off, it wont stop the respawning.

 

Right, that's because I forgot to prepare the script properly for actual testing... also, I made a silly mistake in the scheduled function :doh:

 

Remember that the script will only work with flag 1 (as it's written) and that the flag checker (scheduled function) runs once a minute.

If you need the flag checker to run more often, change the value from 60 to a lower one.

 

As long as flag 1 is set to 1, spawning will be active, if flag 1 doesn't exist or isn't set to 1, no copies of NATO E-3A Sentry group should spawn the next time the flag checker runs.

 

 

Load this script using a ONCE trigger, no conditions (I've removed :InitRepeatOnEngineShutDown(), in case it's interfering. Also, that behaviour can be scripted in another way... but we'll get to that later):

 

Spawn_E3A = SPAWN:New("NATO E-3A Sentry")
Spawn_E3A:InitLimit( 1, 0 )

local function FlagChecker()

   if trigger.misc.getUserFlag("1") and trigger.misc.getUserFlag("1") == 1 then 
      
      Spawn_E3A:Spawn()
   end
   
   return timer.getTime() + 60 [color="Blue"]-- Number of seconds before the flag checker runs again[/color]
end

timer.scheduleFunction(FlagChecker, nil, timer.getTime() + 1)


Edited by Hardcard
Link to comment
Share on other sites

  • Recently Browsing   0 members

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