Jump to content

[Moose] Auto generated Cap no event catched


Recommended Posts

Posted

Hi everyone !

 

Still in the big learning curve of Moose, I was trying to do this "autonomous" behaviour :

 

I have a group of one Mirage2K named "BlueMirage2KSirriCAP"

 

1 - When spawning, the group automatically starts a CAP in a zone I prepared

2 - If the Mirage2K die, I want a message sent to the blue coalition and the CAP is stopped

3 - If the Mirage2K lands (because of damage, fuel or any other reason), the CAP is stopped, a message is sent to the blue coalition and after 2 minutes a new Mirage2K spawns (hence activating a new CAP)

 

BlueMirage2KSirriCAPSpawner = SPAWN:New("BlueMirage2KSirriCAP"):OnSpawnGroup(
 function(SpawnGroup)
   AISirriCap:SetControllable(SpawnGroup)
   
   AISirriCap:Start()
   
   SpawnGroup:HandleEvent(EVENTS.Dead)
   SpawnGroup:HandleEvent(EVENTS.EngineShutdown)
   
   function SpawnGroup:OnEventDead(EventData)
     MessageToBlue("The Mirage has been shot down. You're the only one left alive to defend the base.", 15)
     AISirriCap:Stop()
   end
   
   function SpawnGroup:OnEngineShutDown(EventData)
     MessageToBlue("The Mirage2K is rearming/refuelling, ETA 2 minutes", 15)
     AISirriCap:Stop()
     
     BlueMirage2KSirriCAPSpawner:ScheduleOnce(120,
       function()
         BlueMirage2KSirriCAPSpawner:Spawn()
       end
     )
   end
 end
)
BlueMirage2KSirriCAPSpawner:Spawn()

 

The initial CAP is starting perfectly but I don't know why the events "Dead" or "EngineShutDown" are not triggering my respective functions to handle them. I'm pretty sure this has to be because of the function inside function but I don't see what I am doing wrong.

 

So if anyone knows why, I'm pretty interested :thumbup:

 

Thank you for all given answer !

I'm french (nobody's perfect :smilewink:) so don't be too hard with my english :thumbup:

 

FC3 | A-10C | Mirage 2000C | F/A-18 | KA-50 | UH-1H | Mi-8 | Combined Arms

Posted (edited)

 

BlueMirage2KSirriCAPSpawner = SPAWN:New("BlueMirage2KSirriCAP"):OnSpawnGroup(
 function(SpawnGroup)
   AISirriCap:SetControllable(SpawnGroup)
   
   AISirriCap:Start()
   
   SpawnGroup:HandleEvent(EVENTS.Dead)
   SpawnGroup:HandleEvent(EVENTS.EngineShutdown)
   
   function SpawnGroup:OnEventDead(EventData)
     MessageToBlue("The Mirage has been shot down. You're the only one left alive to defend the base.", 15)
     AISirriCap:Stop()
   end
   
   function SpawnGroup:OnEngineShutDown(EventData)
     MessageToBlue("The Mirage2K is rearming/refuelling, ETA 2 minutes", 15)
     AISirriCap:Stop()
     
     BlueMirage2KSirriCAPSpawner:ScheduleOnce(120,
       function()
         BlueMirage2KSirriCAPSpawner:Spawn()
       end
     )
   end
 end
)
BlueMirage2KSirriCAPSpawner:Spawn()

 

The initial CAP is starting perfectly but I don't know why the events "Dead" or "EngineShutDown" are not triggering my respective functions to handle them. I'm pretty sure this has to be because of the function inside function but I don't see what I am doing wrong.

 

Look for DCS scripting engine / MOOSE errors in dcs.log, you might find clues there. (If I had to bet, I'd say that you're getting nil call errors when trying to handle those events).

 

At first glance, I see that AISirriCap isn't declared anywhere in the snippet. If you have declared AISirriCap somewhere else, include it in your snippet as well, for clarity.

 

Also, I'm not convinced that you can use SpawnGroup the way you did (might be wrong about that, though).

 

In any case, I wouldn't use events as triggers if I were you (some of them tend to cause problems), I'd use schedulers + checks instead.

 

For instance, instead of :OnEventDead, you could use:

 

 

 

 

SCHEDULER:New( nil,

function()

 

SpawnGroup = SET_GROUP:New()

:FilterPrefixes("Late activated group prefix in ME")

:FilterStart()

 

DeadMessageFlag = USERFLAG:New("Dead flag")

SpawnGroupCount = SpawnGroup:Count()

 

if SpawnGroupCount >= 1 --Late activated group(s) alive--

then

AISirriCap:Start() --AISirriCap needs to be declared--

DeadMessageFlag:Set(0)

 

elseif SpawnGroupCount < 1 and DeadMessageFlag:Is(0) --Late activated group(s) dead--

then

MessageToBlue("The Mirage has been shot down. You're the only one left alive to defend the base.", 15)

AISirriCap:Stop() --AISirriCap needs to be declared--

DeadMessageFlag:Set(1)

end

end, {}, 1, 10

)

 

 

Edited by Hardcard
Posted

I'll check again (because I'm not home right now) but as far as I remember I didn't have any error in the logs (I always work on a mission with instantaneous logs, eclipse and dcs editor).

 

And I'll do some tests on the event catching outside of a function. My code may not raise exception but maybe my events subscriptions are not living enough...

I'm french (nobody's perfect :smilewink:) so don't be too hard with my english :thumbup:

 

FC3 | A-10C | Mirage 2000C | F/A-18 | KA-50 | UH-1H | Mi-8 | Combined Arms

Posted (edited)

And I'll do some tests on the event catching outside of a function. My code may not raise exception but maybe my events subscriptions are not living enough...

 

Sounds like a good idea, but keep in mind that some MOOSE event catching methods are known to cause problems (according to my own experiments and replies I got over the MOOSE Discord channel a few months ago).

Of course, there's always the possibility that I might have used some of them incorrectly and that the replies I got over the MOOSE Discord channel were inaccurate.

 

Black listed (These never worked for me):

 

:OnEventPlayerEnterUnit(EventData)

 

:OnEventPlayerLeaveUnit(EventData)

 

:OnEventBirth(EventData)

 

:OnEventRefueling(EventData)

 

:OnEventPilotDead(EventData)

 

:OnEventEjection(EventData)

 

:OnEventDead(EventData)

 

:OnEventEngineStartup(EventData)

 

:OnEventEngineShutdown(EventData)

 

 

 

White listed (These have worked for me):

 

:OnEventShootingEnd()

 

:OnEventRefuelingStop(EventData)

 

:OnEventTakeoff(EventData)

 

 

 

As for the rest, I've either never tested them or simply don't recall the results. :doh:

 

Also, I recall that :UnHandleEvent(Event) caused a MOOSE error (which I reported). Haven't tested it lately, though.

 

It would be great to get input from the "MOOSE grownups" on this one. :helpsmilie:

Edited by Hardcard
Posted

I managed to make the OnEngineShutDown work. But I would be sad if the OnEventDead would not work (I need it !)

 

I'll test a load of them and keep you posted !

 

See ya !

I'm french (nobody's perfect :smilewink:) so don't be too hard with my english :thumbup:

 

FC3 | A-10C | Mirage 2000C | F/A-18 | KA-50 | UH-1H | Mi-8 | Combined Arms

  • Recently Browsing   0 members

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