Mangrove Jack Posted January 25, 2020 Share Posted January 25, 2020 (edited) I am seeking script help from those experience people. I am 1st to say I don't know much but am trying to learn. I have MP mission (half finished) based from carrier and it will random spawn JTAC and subsequent random spawn units. It works at this point based on part of coalition in zone. I can leave like it is but that does not teach me anything on scripting. So after much reading and great posts from Grimes and others I have managed to couple together some code in a test mission that seems to work to a degree but still feel room for improvement. I am counting client planes and counting blue planes (really only interested in client planes) in zone and setting 2 flags to the counts. It works but only after adding 'Part of Coalition in Zone' to condition which I don't understand. In particular is this code correct? --for count of players in zone local count = 0 local blueunits = mist.makeUnitTable({'[blue][plane]'}) local zone_names = trigger.misc.getZone('Staging Zone') -- get the trigger zone local inZone = {} -- table of units inside the zone local function check() for i = 1, #blueunits do -- iterate through the units if Unit.getByName(blueunits[i]) then -- if returned local u = Unit.getByName(blueunits[i]) if mist.utils.get2DDist(u:getPosition().p, zone.point) < zone.radius then -- if it is in the zone if not inZone[u:getName()] then -- if it wasn't there before inZone[u:getName()] = true -- add it to zone list end else -- if not in zone if inZone[u:getName()] then -- if was previously in zone inZone[u:getName()] = nil -- clear from list end end end end end count = count + 1 trigger.action.setUserFlag(200, count) trigger.action.outText( 'Flag 200: ' .. trigger.misc.getUserFlag ( '200' ), 10 ) mist.scheduleFunction(check, {}, timer.getTime()+6, 6, timer.getTime()+ 300) Is it possible/better to change spawn based on the 2 flags being equal and setting another flag true? I tried that but I got error code on that Any help and suggestions/improvements appreciatedIterate units Staging Zone .miz Edited January 25, 2020 by Mangrove Jack Intel i7-7700@3.6GHz 16GB NVIDIA GeForce GTX1060 6GB Link to comment Share on other sites More sharing options...
Mangrove Jack Posted January 27, 2020 Author Share Posted January 27, 2020 Still struggling with this. The "count of players in zone" to me is not working and it seems to me to be related with the local count. Is it not possible to do a count of units in the way I am trying and then setting flag to equal count value? Intel i7-7700@3.6GHz 16GB NVIDIA GeForce GTX1060 6GB Link to comment Share on other sites More sharing options...
Hardcard Posted January 27, 2020 Share Posted January 27, 2020 (edited) Not many people around these parts use MIST, see if Grimes can come to the rescue (as usual :D). If you're new to scripting, though, I wouldn't recommend starting with MIST, since it requires advanced Lua knowledge and documentation is rather scarce. I think it's easier to start with standard DCS code, then maybe toy around with MOOSE, since they're better documented. In any case, here are my two cents (I've never used MIST, mind you): local blueunits = mist.makeUnitTable({'[blue][plane]'})[color="blue"] -- If this set doesn't include all blue planes / doesn't get updated over time, it'll be problematic[/color] local zone_name = trigger.misc.getZone('Staging Zone') local inZone = {} local function check() count = 0 [color="Blue"]-- Make this variable global and put it inside the check function, so it'll be reset every time the scheduler runs[/color] for i = 1, #blueunits do if Unit.getByName(blueunits[i]) then local u = Unit.getByName(blueunits[i]) if mist.utils.get2DDist(u:getPosition().p, zone_name.point) < zone_name.radius then [color="blue"]-- I modified the statement to include Staging Zone's coords and radius[/color] count = count + 1 [color="blue"]-- count will increase by 1 for every blue plane found in zone... assuming I'm interpreting the code correctly[/color] if not inZone[u:getName()] then inZone[u:getName()] = true end else if inZone[u:getName()] then inZone[u:getName()] = nil end end end end trigger.action.setUserFlag('200', count) [color="blue"]-- With this line, flag 200 should be given a numerical value equal to the number of blue planes found within the zone[/color] trigger.action.outText( 'Flag 200: ' .. trigger.misc.getUserFlag ( '200' ), 10 ) end mist.scheduleFunction(check, {}, timer.getTime()+6, 6, timer.getTime()+ 300) [color="blue"]-- I'm assuming this scheduler will run every 5 minutes? [/color] Edited January 27, 2020 by Hardcard [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
Mangrove Jack Posted January 29, 2020 Author Share Posted January 29, 2020 Not many people around these parts use MIST, see if Grimes can come to the rescue (as usual :D). If you're new to scripting, though, I wouldn't recommend starting with MIST, since it requires advanced Lua knowledge and documentation is rather scarce. I think it's easier to start with standard DCS code, then maybe toy around with MOOSE, since they're better documented. Thanks for comment and feedback Hardcard. I have looked at others but will again. Initial look at MOOSE felt a bit daunting. But will look at both again. Meanwhile I will work with what you have suggested. I would also like to stop the function with a flag rather than let it run too long. I assume that is added at end? something like: if trigger.action.getUserFlag(5000)= true then mist.removeFunction(check) end Cheers Intel i7-7700@3.6GHz 16GB NVIDIA GeForce GTX1060 6GB Link to comment Share on other sites More sharing options...
Hardcard Posted January 29, 2020 Share Posted January 29, 2020 (edited) I would also like to stop the function with a flag rather than let it run too long. I assume that is added at end? something like: if trigger.[color="Red"]action[/color].getUserFlag([color="DarkOrange"]5000[/color]) [color="Red"]=[/color] [color="DarkOrange"]true[/color] then mist.removeFunction(check) end No idea of how removeFunction() works, like I said, I've never used MIST. However, the correct syntax would be: if trigger.[color="Green"]misc[/color].getUserFlag([color="Green"]'[/color]5000[color="green"]'[/color]) [color="Green"]==[/color] [color="Green"]1[/color] then mist.removeFunction(check) end Also, here's a way of stopping a standard DCS scheduler with a flag activation: local function Scheduler() [color="Blue"]-- Do stuff[/color] if trigger.misc.getUserFlag('5000') ~= 1 then return timer.getTime() + 10 [color="blue"]-- As long as flag 5000 either doesn't exist or isn't true (doesn't have a value of 1), the scheduler will keep running[/color] end end timer.scheduleFunction(Scheduler, nil, timer.getTime() + 1) Edited January 29, 2020 by Hardcard [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
Mangrove Jack Posted January 29, 2020 Author Share Posted January 29, 2020 Hardcard thanks for your valuable input. Your suggested code in post #3 is counting blue planes as need. So thanks very much. I tried to get the stop flag to end function but could not get it to work. Hopefully Grimes may be able to comment of that if he sees this. Cheers Intel i7-7700@3.6GHz 16GB NVIDIA GeForce GTX1060 6GB Link to comment Share on other sites More sharing options...
Hardcard Posted January 30, 2020 Share Posted January 30, 2020 (edited) I tried to get the stop flag to end function but could not get it to work. Hopefully Grimes may be able to comment of that if he sees this. ...or you could use a standard DCS scheduler and stop it with a flag activation, as shown in #5 :D local blueunits = mist.makeUnitTable({'[blue][plane]'}) local zone_name = trigger.misc.getZone('Staging Zone') local inZone = {} local function check() count = 0 for i = 1, #blueunits do if Unit.getByName(blueunits[i]) then local u = Unit.getByName(blueunits[i]) if mist.utils.get2DDist(u:getPosition().p, zone_name.point) < zone_name.radius then count = count + 1 if not inZone[u:getName()] then inZone[u:getName()] = true end else if inZone[u:getName()] then inZone[u:getName()] = nil end end end end trigger.action.setUserFlag('200', count) trigger.action.outText( 'Flag 200: ' .. trigger.misc.getUserFlag ( '200' ), 10 ) if trigger.misc.getUserFlag('5000') ~= 1 then return timer.getTime() + 300 [color="Blue"]-- As long as flag 5000 either doesn't exist or isn't true (doesn't have a value of 1), the scheduler will keep running every 5 minutes[/color] end end timer.scheduleFunction(check, nil, timer.getTime() + 6) Edited January 30, 2020 by Hardcard [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
Mangrove Jack Posted January 30, 2020 Author Share Posted January 30, 2020 ...or you could use a standard DCS scheduler and stop it with a flag activation, as shown in #5 :D I certainly appreciate that. I did try but because this is all new I did not understand to replace the previous scheduleFunction with your timer hense - no work.:doh: It now works that I got that into my head. Also took your advise and been looking at Moose vids and docs for the last few hours to see ware that takes me. Thanks again Hardcard Intel i7-7700@3.6GHz 16GB NVIDIA GeForce GTX1060 6GB Link to comment Share on other sites More sharing options...
Recommended Posts