Dangerzone Posted June 15, 2021 Posted June 15, 2021 (edited) I'm wanting to activate all units that are in a zone (that are set to late activation). The problem I'm facing (trying to use Moose) is that SETGROUP:ForEachGroupAnyInZone (And similar functions) only work on ALIVE units, thus ignoring the actual units I want to activate. This is what I was trying to achieve, but is obviously the wrong way to go about it. Any hints would be greatly appreciated! activategroups = SET_GROUP:New():FilterCoalitions("red"):FilterStart() activategroups:ForEachGroupAnyInZone( lzone, function( GroupObject ) GroupObject:Activate() -- Is only getting already active units end ) Is there a ForEach option that will get inactive units as well (but not dead), or should I be trying to do this a different way? Thanks in Advance! Edited June 15, 2021 by Dangerzone
Dangerzone Posted June 27, 2021 Author Posted June 27, 2021 (edited) For any who come across this thread wondering if I've been successful - I've been my head against wall after wall for half a month now trying to get this to work in various ways and haven't been able to find any. I've found that even if I could get a list of deactivated units - if I call mygroup:IsInZone to find if it's in the zone - it still fails because it considers any units deactivated as not being in any zones. As a disclaimer - keep in mind that I'm new to lua and Moose - so there may be a way - but I haven't been able to find it, so after 2 weeks I'm giving up and I'm retiring myself to creating a table of every single unit in the mission manually and what zones they're going to be in so I can refer to that. It's a very clumsy and manual method - but I can't see any other way of doing it. Basically like: MyGroups = { {unitgroup = 'redforarmour1', zone = 'zoneA'}, {unitgroup = 'redforarmour2', zone = 'zoneA'}, {unitgroup = 'redforarmour3', zone = 'zoneB'}, -- ... and repeat a few hundred times and hope I don't miss any, or assign to the wrong zone } It's going to be a pain to maintain with every single change needing to be reflected in the table - plus opens for so much human error, but I simply can't find any automated way of getting a list of units tagged as "lateactivate" inside a particular zone that aren't dead but haven't been activated yet. If anyone comes across a way of getting a list of not-yet-activated units in a zone in the future - please consider posting a solution here, as it would be greatly appreciated. Edited June 27, 2021 by Dangerzone
toutenglisse Posted June 27, 2021 Posted June 27, 2021 10 hours ago, Dangerzone said: ... If anyone comes across a way of getting a list of not-yet-activated units in a zone in the future - please consider posting a solution here, as it would be greatly appreciated. Your late-activation units are necessarelly static inside the zone you put them in, in mission editor. You should not handle them by presence in zone, but you should just name them with the zonename as prefixe, and activate them using that (your subject is in zoneA : make a table of all enemy units, and for each entry if the unit's name is starting by "zonea" you activate it) ?
Gambit21 Posted June 27, 2021 Posted June 27, 2021 I might be missing something - but this seems fairly simple just in the editor itself never-mind scripting - however I’m not exactly clear on what you’re trying to pull off. Assuming a static zone, and known units in that zone...seems like simple editor logic to me. Again, I might be missing something.
Dangerzone Posted June 28, 2021 Author Posted June 28, 2021 (edited) Thanks but I’m trying to have a genetic function to handle this where I don’t have to specify the individual names of each groups. What I want to do is create a generic function I can call with one line ie ActivateUnitsInZone(zonename, coalition ) … and all units placed in that zone that aren’t active will be activated for that zone. I like to reduce things to the lowest level. I’m happy to write a long function if it means I can reuse it over and over again for different zones with a single line of code for different parts of the map, or even different missions. I’ve tried Moose but it’s functions exclude non activated units from “SET” commands. from what I can tell, it’s either not possible or it’s beyond my reach. Edited June 29, 2021 by Dangerzone
dark_wood Posted June 29, 2021 Posted June 29, 2021 Try with MIST: https://wiki.hoggitworld.com/view/MIST_getUnitsInZones This function will build a table with all units from a zone(s) - then just loop the table and activate them: trigger.action.activateGroup(Group.getByName('yourGroupNameFromTable')) https://wiki.hoggitworld.com/view/DCS_func_activateGroup 1
Dangerzone Posted July 1, 2021 Author Posted July 1, 2021 On 6/29/2021 at 4:34 PM, dark_wood said: Try with MIST: https://wiki.hoggitworld.com/view/MIST_getUnitsInZones This function will build a table with all units from a zone(s) - then just loop the table and activate them: trigger.action.activateGroup(Group.getByName('yourGroupNameFromTable')) https://wiki.hoggitworld.com/view/DCS_func_activateGroup Thanks Darkwood. I didn't think of using mist, and that was a fantastic suggestion which would have achieved exactly what I am looking for! However I have tried this but it seems that Mist and Moose may be conflicting with each other. u = mist.getUnitsInZones(mist.makeUnitTable({'[all]'}), {'testzone'}) results in: INFO SCRIPTING: MOOSE error in MENU COMMAND function: [string "g:\mission\mist.lua"]:2652: attempt to call method 'isActive' (a nil value) INFO SCRIPTING: stack traceback: [string "g:\mission\Moose.lua"]:11310: in function 'isActive' [string "g:\mission\mist.lua"]:2652: in function 'getUnitsInZones' [string "g:\mission\testscript.lua"]:5: in main chunk [string "g:\mission\initiator.lua"]:71: in function <[string "g:\mission\initiator.lua"]:70> (tail call): ? [C]: in function 'xpcall' [string "g:\mission\Moose.lua"]:11321: in function <[string "g:\mission\Moose.lua"]:11317> I have no idea why it's a MOOSE error when I'm trying to use mist (which I thought was independent from Moose but yet could run along side moose without interfering). Additionally - the reference to 'isActive' in mist looks as though this may also have the same issue as Moose - in that it will only return already activated units. I guess this isn't the case. Sadly - my missions rely heavily on Moose, so it's looking like I'm hitting another dead end.
dark_wood Posted July 1, 2021 Posted July 1, 2021 Hmm, is really bad luck with that conflict Maybe this will work: activategroups = SET_GROUP:New():FilterCoalitions("red"):FilterStart() activategroups:ForEachGroupAnyInZone( lzone, function( GroupObject ) if not GroupObject:IsActive() then GroupObject:Activate() end end )
Dangerzone Posted July 1, 2021 Author Posted July 1, 2021 24 minutes ago, dark_wood said: Hmm, is really bad luck with that conflict Maybe this will work: activategroups = SET_GROUP:New():FilterCoalitions("red"):FilterStart() activategroups:ForEachGroupAnyInZone( lzone, function( GroupObject ) if not GroupObject:IsActive() then GroupObject:Activate() end end ) Thanks Darkwood for the suggestion. Your code looks just like mine in my original post (except i wasn't as elegant and just went straight for the activate... so great minds think alike) Unfortunately the set does not include 'late activated' units which is where I got stumped originally. It seems to only work with 'Alive' units - which it counts activated units as not-alive.
dark_wood Posted July 1, 2021 Posted July 1, 2021 "Your code looks just like mine in my original post" - yes, it is yours with my added if condition Well then, i don't now what to say, maybe doublecheck if you use the last MOOSE version?
Dangerzone Posted July 2, 2021 Author Posted July 2, 2021 15 hours ago, dark_wood said: "Your code looks just like mine in my original post" - yes, it is yours with my added if condition Well then, i don't now what to say, maybe doublecheck if you use the last MOOSE version? Thanks so much for showing interest and trying to help me with this. I've been trying this for a while - and have been updating my Moose script - it always works the same way - ignores late activated units. I think that is by design. The moose script even says this in the first comment line. I'm assuming **alive** means alive AND active, which is why I've considered this isn't an option and have been looking for other options: From the moose.lua file: --- Iterate the DATABASE and call an iterator function for each **alive** GROUP, providing the GROUP and optional parameters. -- @param #DATABASE self -- @param #function IteratorFunction The function that will be called for each object in the database. The function needs to accept a GROUP parameter. -- @return #DATABASE self function DATABASE:ForEachGroup( IteratorFunction, FinalizeFunction, ... ) self:F2( arg ) self:ForEach( IteratorFunction, FinalizeFunction, arg, self.GROUPS ) return self end Attached is an example mission to demonstrate what's going on if you're interested to see what I'm doing. I have 2 units. One active and another late active. After a few seconds the lateactivate unit should activate as well (using your script). I've added in messages to show every unit that it detects. With the message showing up in the mission you can see it only detects the group already activated and ignores the non-active one. It seems to me that moose simply doesn't have the ability to detect units that are not active using ForEachGroup including the Zone options. That's why I gave up in the end and I'm doing it all manually -every single group added into a table manually each time. I would love to know if I'm wrong and there's a better option - but I don't feel as bad now that someone else had the same idea as me - makes me think I'm not as stupid as I though I was. Once again, thanks for taking so much time to show an interest. testzone.miz
dark_wood Posted July 2, 2021 Posted July 2, 2021 Ok, it is tricky, indeed. I have tried your mission file and code, and come to a solution which doesn't make me very happy, but maybe you can raffinate it (I'm more with MIST than MOOSE). Attached you will find the mission modified and the Lua code. What i did: first, i check if group is active or not. If not, i activate it. Then, i check if is in zone - if yes that is it, is ok. If not - deactivate it (or destroy it, as you wish) Just open the miz file in ME and move late activation group outside the zone, you will see that is first activated, then one second later is removed - I had to use delayed function, not working without. So, not an elegant solution, but hope it helps you test.zip 1
toutenglisse Posted July 3, 2021 Posted July 3, 2021 (edited) On 7/2/2021 at 2:08 AM, Dangerzone said: ... I would love to know if I'm wrong and there's a better option... You can get position of a late-activation group, so this should work : EDIT : I put it into your testzone example. I added 3 other groups (1 inside and 2 outside of zone, just to test) and used mist to compare distance to zone center with zone radius. testzone-mist.miz Edited July 4, 2021 by toutenglisse example attached 1
Dangerzone Posted July 4, 2021 Author Posted July 4, 2021 (edited) On 7/3/2021 at 3:01 AM, dark_wood said: Ok, it is tricky, indeed. I have tried your mission file and code, and come to a solution which doesn't make me very happy, but maybe you can raffinate it (I'm more with MIST than MOOSE). Attached you will find the mission modified and the Lua code. What i did: first, i check if group is active or not. If not, i activate it. Then, i check if is in zone - if yes that is it, is ok. If not - deactivate it (or destroy it, as you wish) Just open the miz file in ME and move late activation group outside the zone, you will see that is first activated, then one second later is removed - I had to use delayed function, not working without. So, not an elegant solution, but hope it helps you test.zip 1.09 MB · 1 download Thanks Darkwood. I appreciate all your effort in helping! 13 hours ago, toutenglisse said: You can get position of a late-activation group, so this should work : EDIT : I put it into your testzone example. I added 3 other groups (1 inside and 2 outside of zone, just to test) and used mist to compare distance to zone center with zone radius. testzone-mist.miz 58.7 kB · 0 downloads Thanks toutenglisse. It looks like Darkwood was on the right track - ignore Moose and use Mist! I see your example will only work with circular zones and not polygone - but that's OK at this stage - I can live with that for now - it's far better than creating and maintaining tables. Thank you very much! Edited July 4, 2021 by Dangerzone 1
toutenglisse Posted July 4, 2021 Posted July 4, 2021 8 minutes ago, Dangerzone said: ... I see your example will only work with circular zones and not polygone ... Yes only circular zone in my first example, but you can use polygonal zones using the waypoints of a late-activation vehicle (so probably a neutral coalition one, to not mess up with others) and use another mist function. Here is an example. testzone-mist-poly.miz 1
Dangerzone Posted July 4, 2021 Author Posted July 4, 2021 45 minutes ago, toutenglisse said: Yes only circular zone in my first example, but you can use polygonal zones using the waypoints of a late-activation vehicle (so probably a neutral coalition one, to not mess up with others) and use another mist function. Here is an example. testzone-mist-poly.miz 59.29 kB · 1 download That's great - thank you!
Mayo Posted November 3, 2024 Posted November 3, 2024 I'm resurrecting this topic because it's close to what Im trying to achieve. However Im super new to lua. It's my first attempt. My goal to to activate units in a 10km radius around certain aircraft (player clients). And deactivating the units again when the players are at a range again. I want this because I want a large scale battle, with minimum performance loss. This is what I made with the example above: (I know the syntax is wrong, so I would like to know how I do need to do it) local zone = trigger.misc.getZone('testzone') for i, gp in pairs(coalition.getGroups(1,2)) do local GroupPoint = mist.getLeadPos(Group.getName(gp)) if mist.utils.get2DDist(GroupPoint, zone.point) < zone.radius then gp:activate() end if mist.utils.get2DDist(GroupPoint, zone.point) < zone.radius then setGroupAIOn(gp) end if mist.utils.get2DDist(GroupPoint, zone.point) > zone.radius then setGroupAIOff(gp) end end
Dangerzone Posted November 4, 2024 Author Posted November 4, 2024 12 hours ago, Mayo said: I want this because I want a large scale battle, with minimum performance loss. That's exactly what I was looking for. After many years I've given up on the idea. I don't think DCS is the platform, nor will ever be the platform for this. But I'm certainly happy to entertain the idea. My first question is how are you planning on using zones to accomplish this? Are you going to have zones around every group, or a moving zone around the player? If so - would it be better to avoid zones altogether and just calculate the distacne between 2 groups?
Mayo Posted November 23, 2024 Posted November 23, 2024 On 11/4/2024 at 7:38 AM, Dangerzone said: That's exactly what I was looking for. After many years I've given up on the idea. I don't think DCS is the platform, nor will ever be the platform for this. But I'm certainly happy to entertain the idea. My first question is how are you planning on using zones to accomplish this? Are you going to have zones around every group, or a moving zone around the player? If so - would it be better to avoid zones altogether and just calculate the distacne between 2 groups? I was thinking of having an area around each player/client.
Recommended Posts