AKA_Clutter Posted June 25, 2022 Posted June 25, 2022 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 12700k @4.6 GHz, EVGA RTX 3080 FTW, Ultra 64 GB G.Skill DDR4 3600 RAM, Acer 27" flat screen, HP Reverb G2, TM Warthog HOTAS with Virpil warBRD base, MFG Rudder Pedals, Virpil TCS Rotor Base with AH-64Dcollective, TrackIR 5 Pro w/Vector Expansion, PointCTRL.
Grimes Posted June 25, 2022 Posted June 25, 2022 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 Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
AKA_Clutter Posted June 25, 2022 Author Posted June 25, 2022 Damn your good. So much simpler than what I had. Thanks very much. ---------------- AKA_Clutter Win 10 Pro, Intel i7 12700k @4.6 GHz, EVGA RTX 3080 FTW, Ultra 64 GB G.Skill DDR4 3600 RAM, Acer 27" flat screen, HP Reverb G2, TM Warthog HOTAS with Virpil warBRD base, MFG Rudder Pedals, Virpil TCS Rotor Base with AH-64Dcollective, TrackIR 5 Pro w/Vector Expansion, PointCTRL.
609_Relentov Posted June 26, 2022 Posted June 26, 2022 (edited) 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 June 26, 2022 by 609_Relentov
Recommended Posts