Jump to content

How to launch an action with the lua predicate checking an event occur?


guimcdo

Recommended Posts

Hello all,

 

For a tanker, I want to create a trigger, with a mist respawn action. To launch this action, I want to use the LUA Predicate (now it should be working) checking the tanker AI engine shutdown (S_EVENT_ENGINE_SHUTDOWN) event.

The lua predicate have to return "true" to launch the action.

 

I don't know how I can return a "true" when the event occur.

 

Any idea?

 

Thanks :pilotfly:

Link to comment
Share on other sites

Not exactly what you are looking for, but you might investigate MOOSE, with which the following script file should work:

 

 

Tanker = UnitFindByName( "Your ME Tanker" )

AnyVariable = false
Tanker:HandleEvent( EVENTS.EngineShutdown )

function Tanker:OnEventEngineShutdown( EventData )

local TankerIni = EVENTDATA.IniGroup
           
   if TankerIni == Tanker then
      AnyVariable = true
   end            
end

Link to comment
Share on other sites

Hello Habu,

 

Thanks for your feedback. About my request, I want use LUA Predicate fields on trigger condition column, and I think they are only able to interpret native DCS lua langage (not MIST & MOOSE).

 

I will try your code and give a feedback soon.

 

Thanks

Link to comment
Share on other sites

Any global variable is accessible in lau predicate, just realize it is running that check once a second.

 

 

Say if you have a global value set somewhere else on the engine shutdown you could use the following in lua predicate. So when the global value 'whatever' is true the predicate will evaluate as true.

 

if whatever == true then

return truen

end

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

Thanks for your reply Grimes,

 

Any global variable is accessible in lau predicate, just realize it is running that check once a second.

Do you means this system have a big ressource consumption (CPU, RAM...)? If yes, do you have a better way to do the same thing?

 

Currently, I use 2 standard conditions: speed < 1 kts AND Time > 120s to launch the respawn. That work fine but if there are traffic jam on the taxi or runway, the tanker can be arrested (speed < 1kts) while the time is more than 120 seconds. The engine shut down event looks like as better solution ;-)

 

About the code, I'm in progress to learn lua but I'm beginner, if you have an idea, I take it :music_whistling: I don't find lots of sample about lua predicate / events code. And an event return a ID, not a boolean value, I think I have to write something like: if event id=18 for tanker, then return true, end

 

Thanks again for your work on this game

 

PS: Black mesa; half life related location?

 

++

Link to comment
Share on other sites

About the code, I'm in progress to learn lua but I'm beginner, if you have an idea, I take it :music_whistling: I don't find lots of sample about lua predicate / events code. And an event return a ID, not a boolean value, I think I have to write something like: if event id=18 for tanker,

++

 

 

One of the big advantages of MOOSE is the Scheduler method, which allows the checking of a complicated set of conditions on a frequency set by the designer, maybe only once every 15 sec. for example, then stopping the Scheduler cycle under specified conditions. Saves a lot of CPU effort. MOOSE does come with a library of code and mission examples.

Link to comment
Share on other sites

Thanks for your reply Grimes,

 

Do you means this system have a big ressource consumption (CPU, RAM...)? If yes, do you have a better way to do the same thing?

 

Currently, I use 2 standard conditions: speed < 1 kts AND Time > 120s to launch the respawn. That work fine but if there are traffic jam on the taxi or runway, the tanker can be arrested (speed < 1kts) while the time is more than 120 seconds. The engine shut down event looks like as better solution ;-)

 

About the code, I'm in progress to learn lua but I'm beginner, if you have an idea, I take it :music_whistling: I don't find lots of sample about lua predicate / events code. And an event return a ID, not a boolean value, I think I have to write something like: if event id=18 for tanker, then return true, end

 

 

It is not exactly a resource intensive process to begin with. However that is simply how all the triggers work. Trigger conditions get checked at a rate of once a second, but it does depend on the rule in the first column. With the scripting engine you can make it go faster or slower depending on the needs. For example plenty of "air race" style scripts check the position of aircraft 100 times a second. Other checks just stuff can be much slower.

 

In this instance though I'd recommend only using the scripting engine. For example have one trigger set to run the code and either have a section of that code dedicated to respawning the group or use it to set a condition for another trigger with a lua predicate. Use an event handler to check for the engine shutdown event, if it is the unit you are looking for, then do the action.

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

It looks like so easy for you, I'm jealous :D

In this instance though I'd recommend only using the scripting engine. For example have one trigger set to run the code and either have a section of that code dedicated to respawning the group or use it to set a condition for another trigger with a lua predicate. Use an event handler to check for the engine shutdown event, if it is the unit you are looking for, then do the action.

So, I understand you advise me to create two trigger: one for the lua predicate, and another one for the mist respawn function? If I'm right, why do that? it's a issue source to use Mist and native DCS scripting in the same trigger?

 

About event management, I found some example to show event ID during the mission, but:

- I don't know yet how to link the unit with the event occur? I have to search

- I check DCS log file, and I think the event for the start up doesn't appear (eventID 17), is it normal?

 

Thanks for reading, the learning is a long way !!!

Link to comment
Share on other sites

  • Recently Browsing   0 members

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