tolis97d Posted November 16, 2021 Posted November 16, 2021 (edited) hello i am trying to create zone capturing system using mist mist.flagFunc.units_in_zones{ units = {'[blue][vehicle]'}, zones = {'Zone1'}, flag = 7, req_num = 4, } essentially i want a zone to be captured when at least 4 units are present in the zone.The zone should become neutral when less than 4 units are present.Currently with the above code the script only runs once(4 units are entering a zone,flag 7 becomes true and a message is shown but when the conditions are no longer met flag 7 doesnt become false and the appropriate message is not shown) finally i would like this to be functional for multiple swithes of the ownership of a zone. Edited November 16, 2021 by tolis97d
dark_wood Posted November 16, 2021 Posted November 16, 2021 Try this: function checkMyZone() --output a text to see that function is called each minute trigger.action.outText('function was called', 1) --if flag 7 is false, do the check if trigger.action.getUserFlag(7) == 0 then mist.flagFunc.units_in_zones{ units = {'[blue][vehicle]'}, zones = {'Zone1'}, flag = 7, req_num = 4, } trigger.action.outText('Flag 7 is true', 5) else --flag 7 is true, reset it trigger.action.setUserFlag(7, false) trigger.action.outText('Flag 7 was reset', 5) end end do --start function after 10 seconds, then call it again after 1 minute, end it after 1 hour mist.scheduleFunction(checkMyZone, {}, timer.getTime() + 10, 60, timer.getTime() + 3600) end Basically, you need to call your function at a period of time (1 minute in this case - feel free to change it as desired), then check your flag 7 status, if is false, do your code, if is true reset it so it can be checked again after 1 minute. Hope it helps
cfrag Posted November 16, 2021 Posted November 16, 2021 Sorry for not being helpful (I don't know how to do that in Mist) - from doing something similar I want to warn you that your conditions for setting neutral/capture are incomplete. You need to subtract the number of red units in the same zone, or you could theoretically capture a zone with 4 blue units while there are 100 red ones in the same zone.
tolis97d Posted November 16, 2021 Author Posted November 16, 2021 (edited) doesnt seem to work Edited November 16, 2021 by tolis97d
dark_wood Posted November 16, 2021 Posted November 16, 2021 I need more details here, have you wait it at least 70 seconds from mission start? Cause it starting after 10 seconds and repeat after 60, so let it run for 2-3 minutes Second, did you see the 'function was called' message? We need to be sure the function checkMyZone() is called. Make sure that you first call MIST library, then your script: MISSION START > no condition > do LUA file (load MIST library lua file here) ONCE > Time more 5 seconds > do LUA file (load here your LUA file) Finally, let us know if you see any errors when you run the mission.
dark_wood Posted November 16, 2021 Posted November 16, 2021 Also, be aware that i only showed you how to repeat the function and reset the flag, the capture zone is a whole different story...
toutenglisse Posted November 16, 2021 Posted November 16, 2021 1 hour ago, tolis97d said: ...but when the conditions are no longer met flag 7 doesnt become false and the appropriate message is not shown... You need to use the option "toggle" with boolean value. ("toggle is an optional variable that if present will switch the flag value to false when the required conditions are not met. If not specified toggle defaults to false.") @dark_wood - only run the "units in zones" function one time - it will be checked every second if no other "interval" option is specified. It is only your part of function that checks flag value that needs to be ran with the interval you want. If not then you run as many additional "units in zones" functions as minutes are passing. Also you can use a "stop flag" option to stop the function when you don't need it anymore.
dark_wood Posted November 16, 2021 Posted November 16, 2021 @toutenglisse, well, I prefer the schedule function approach, but yes, he can do something like: mist.flagFunc.units_in_zones{ units = {'[blue][vehicle]'}, zones = {'Zone1'}, flag = 7, req_num = 4, interval = 60, toggle = true }
toutenglisse Posted November 16, 2021 Posted November 16, 2021 33 minutes ago, dark_wood said: @toutenglisse, well, I prefer the schedule function approach... @Grimes explained here what I want to tell you, but much better : https://forums.eagle.ru/topic/268695-need-help-with-assessing-a-unit-from-a-table/?do=findComment&comment=4634890
dark_wood Posted November 16, 2021 Posted November 16, 2021 25 minutes ago, toutenglisse said: @Grimes explained here what I want to tell you, but much better : Great info man, thanks, always is something new to learn. Probably I use a lot schedule function and you know, bad habits dies hard
tolis97d Posted November 16, 2021 Author Posted November 16, 2021 dark_wood the last one seems to be working! thanks a lot! will do some more tests.. maybe its better to talk through the ED or hoggit discord?
dark_wood Posted November 16, 2021 Posted November 16, 2021 Hi @tolis97d - i'm glad it worked, write here if you still have questions/issues. 1
Recommended Posts