EasyEB Posted April 4, 2016 Posted April 4, 2016 Greetings! I have a quick question, is it possible to have a flag set a value at a random time within a 30 (or whatever) minute time frame? Cheers!
dooom Posted April 4, 2016 Posted April 4, 2016 Random Countdown (from : http://en.wiki.eagle.ru/wiki/Mission_Editor:_Randomization ) Once > Time Less than 5 > Set Flag 1 Random Value from 50 to 100 Switched Condition >Time Since Flag 1 is 30 seconds > Flag 1 Decrease 1 Once > Flag 1 Equals 1 > Activate Group This method is based on setting an initial value and then counting down by 1 at a set rate until the value equals 1 to spawn a group. In this example the group will spawn somewhere between 25 and 50 minutes. It is highly flexible in that the random time it takes for the group to activate is easily defined. The "rate" in this example, the 2nd trigger, can be raised or lowered to drastically change the time it takes for the group to spawn. Changeing the 2nd trigger to the following will result in a random time between 4.1 and 8.3 minutes. Switched Condition >Time Since Flag 1 is 5 seconds > Flag 1 Decrease 1 ASUS Tuf Gaming Pro x570 / AMD Ryzen 7 5800X @ 3.8 / XFX Radeon 6900 XT / 64 GB DDR4 3200 "This was not in the Manual I did not read", cried the Noob" - BMBM, WWIIOL
FSFIan Posted April 4, 2016 Posted April 4, 2016 (edited) Here is a Lua solution that avoids having to use multiple triggers. You can execute it in a DO SCRIPT block at mission start, or at any other time. I included outText actions for illustration purposes. -- adjust these values to set the minimum and maximum delay time in seconds local minDelaySec = 2*60 local maxDelaySec = 30*60 local function doAction() -- this function will be executed a random amount of time after the current time -- for example, you can make it output some text: trigger.action.outText("action!", 0) -- or have it set a flag (the following sets flag 1 to the value 5): trigger.action.setUserFlag(1, 5) return nil -- do not reschedule end -- determine random delay and schedule execution of doAction() in the future local delaySec = math.random(minDelaySec, maxDelaySec) trigger.action.outText("scheduled delay "..tostring(delaySec).." seconds", 0) -- display the delay that has been decided on (you will probably want to delete this line before releasing the mission) timer.scheduleFunction(doAction, {}, timer.getTime() + delaySec) This is a good example for something that can be done with reasonable effort with the trigger system, but has a cleaner solution in Lua. The Lua solution also saves the effort of decreasing a variable once every second, so theoretically it has less of a performance impact, but the difference won't be measurable unless we are talking about an insane number of these randomly scheduled events. The biggest advantage of doing it in Lua is that all of the information (minimum and maximum delay time and the action that gets executed) is in one place, although you may want to remove all of the comments before pasting it into the small text field in the mission editor to keep things readable in there. Edited April 4, 2016 by [FSF]Ian 1 DCS-BIOS | How to export CMSP, RWR, etc. through MonitorSetup.lua
apolloace Posted April 5, 2016 Posted April 5, 2016 Ian;2733888']Here is a Lua solution that avoids having to use multiple triggers. You can execute it in a DO SCRIPT block at mission start, or at any other time. I included outText actions for illustration purposes. -- adjust these values to set the minimum and maximum delay time in seconds local minDelaySec = 2*60 local maxDelaySec = 30*60 local function doAction() -- this function will be executed a random amount of time after the current time -- for example, you can make it output some text: trigger.action.outText("action!", 0) -- or have it set a flag (the following sets flag 1 to the value 5): trigger.action.setUserFlag(1, 5) return nil -- do not reschedule end -- determine random delay and schedule execution of doAction() in the future local delaySec = math.random(minDelaySec, maxDelaySec) trigger.action.outText("scheduled delay "..tostring(delaySec).." seconds", 0) -- display the delay that has been decided on (you will probably want to delete this line before releasing the mission) timer.scheduleFunction(doAction, {}, timer.getTime() + delaySec) This is a good example for something that can be done with reasonable effort with the trigger system, but has a cleaner solution in Lua. The Lua solution also saves the effort of decreasing a variable once every second, so theoretically it has less of a performance impact, but the difference won't be measurable unless we are talking about an insane number of these randomly scheduled events. The biggest advantage of doing it in Lua is that all of the information (minimum and maximum delay time and the action that gets executed) is in one place, although you may want to remove all of the comments before pasting it into the small text field in the mission editor to keep things readable in there. Hi, [FSF]Ian This thread has been very helpful for me, :thumbup: but I have a question, since I am a complete novice in Lua. :noexpression: If I want to replace the "outText" line with something that activates a group, then what syntax or command should I use? :helpsmilie: Rig - I7-9700K/GIGABYTE Z390D/RTX-2080 SUPER/32-GB CORSAIR VENGEANCE RAM/1-TB SSD Mods - A10C / F18C / AV8B / Mig21 / Su33 / SC / F14B
FSFIan Posted April 5, 2016 Posted April 5, 2016 If I want to replace the "outText" line with something that activates a group, then what syntax or command should I use? :helpsmilie: I can't test right now, but the following should work: Group.getByName("Group Name"):activate() DCS-BIOS | How to export CMSP, RWR, etc. through MonitorSetup.lua
apolloace Posted April 6, 2016 Posted April 6, 2016 Thanks [FSF]Ian! Just tested the code & it works fine. :) Rig - I7-9700K/GIGABYTE Z390D/RTX-2080 SUPER/32-GB CORSAIR VENGEANCE RAM/1-TB SSD Mods - A10C / F18C / AV8B / Mig21 / Su33 / SC / F14B
Recommended Posts