Jump to content

Repeating a lua script


AKA_Clutter

Recommended Posts

First, I am a lua/DCS scripting noob.

 

I want to use a script to issue messages to my squad during a multiplayer Liberation campaign mission.  The purpose is to let them know how much time has elapsed, and how much is left.  I can easily do this in the ME with ONCE triggers that uses the time more trigger.

As I want to do this for each mission, I would like to write a script to do this so I can just add the script rather than adding 7 triggers and the associated message each time.  I've got a script working but the only way I know to get it to check each time is to use the REPEAT trigger and then have it execute a DO SCRIPT command.

 

This seems pretty inefficient.  Is there a better way to do this?

TIA

Clutter

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

AKA_Clutter

 

Win 10 Pro, Intel i7 8700k @4.6 GHz, EVGA RTX 3080  FTW, Ultra 64 GB G.Skill DDR4 3600 RAM, Acer 27" flat screen, Oculus Rift S, HP Reverb G2, CH Fighterstick, Pro Throttle and Pro Rudder Pedals HOTAS, TM Warthog HOTAS, MFG Rudder Pedals, TrackIR 5 Pro w/Vector Expansion, PointCTRL.

Link to comment
Share on other sites

local totalTime = 14400
local interval = 1800
local function printTimeLeft()
   local timeRemain = totalTime - timer.getTime()
   trigger.action.outText(timeRemain/3600 .. " hours remain", 30)
end

local iter = totalTime/interval
for i = 1, iter do
   timer.scheduleFunction(printTimeLeft, {}, timer.getTime() + (i* iter))
end

Something like that. Just run it once because it reschedules the function to run however many times. In this example 8 total and every 30 minutes with a 4 hour run time.  You can also do some fun stuff with the message formatting to get it in a more readable format because you will likely see a message with several decimal places used which isn't all that useful. 

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

Damn your good.  So much simpler than what I had. Thanks very much.

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

AKA_Clutter

 

Win 10 Pro, Intel i7 8700k @4.6 GHz, EVGA RTX 3080  FTW, Ultra 64 GB G.Skill DDR4 3600 RAM, Acer 27" flat screen, Oculus Rift S, HP Reverb G2, CH Fighterstick, Pro Throttle and Pro Rudder Pedals HOTAS, TM Warthog HOTAS, MFG Rudder Pedals, TrackIR 5 Pro w/Vector Expansion, PointCTRL.

Link to comment
Share on other sites

Nice quick function.  However, Grimes, unless I’m miss-interpreting, wouldn’t you want the timer function to be:

timer.scheduleFunction(printTimeLeft, {}, timer.getTime() + (i* interval))

Otherwise the function is called with i * 8 instead of i * 1800?

 


Edited by 609_Relentov
Link to comment
Share on other sites

  • Recently Browsing   0 members

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