get units in area? (Full Version)

All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion



Message


Whicker -> get units in area? (8/28/2019 2:10:44 AM)

Is there an easy way to get what is inside of an area defined by some ref points?

I see that I can check if a unit is in an area, but I want to check the area and see what units are in it. Only thing I can think of is lopping thru all the units on a side and checking each one to see if it is in an area.

I'd like to see if there are more than x mobile facilities, or more than x tanks really.

this works per unit:
quote:


local u= SE_GetUnit({name='tank', guid='b87e998b-cca8-4e6d-beb0-8333cc3aeae6'})
print(u:inArea{"1","2","3"})--prints yes or no


but I want to do something more like:

quote:


local p = ScenEdit_GetReferencePoints({side="Crimson Commonwealth", area={"1","2","3"}})
print(p.unitsInArea)--no such thing




Whicker -> RE: get units in area? (8/28/2019 2:12:49 AM)

I guess I can see how this isn't possible - the game would have to do the same thing - loop thru all units to see what is in any given area of rps.

The units that I wanted to check were all in groups, so rather than loop thru all the units on the side I made a table of group names and then loop thru those to see if they are in the area. The goal is to pop up a message if none of the units are in the area so this is what I think works:

quote:


local t={'Group 3349','Group 3350','Group 3351','3rd Armored'}
for i = 1,#t do
local u = SE_GetUnit({name=t,side='Crimson Commonwealth'})
if u ~= nil then
unitsToCheck = u.group.unitlist
for i = 1, #unitsToCheck do
local uu = SE_GetUnit({guid=unitsToCheck})
if uu:inArea{"RP-4091","RP-4092","RP-4093","RP-4094"} then
--print(uu.name..' is it in the area? '..tostring(uu:inArea{"RP-4091","RP-4092","RP-4093","RP-4094"}))
return --there is a unit still in the area so exit
end
end
end--loop of unitlist
end--table of groups
ScenEdit_SetEvent('Sangster Recaptured', {IsActive=true})--if we get this far there are no units in the area
ScenEdit_SpecialMessage('playerside','Commander, <br><br>Our forces have cleared the area around Sangster of most major enemy units, we should have control of the Airport in the next hour.<br><br>(you must have ground forces occupying the base for 60 minutes)')




KnightHawk75 -> RE: get units in area? (9/19/2019 4:47:25 PM)

Maybe unrelated I think but if you ever need to a generic isInArea sort of check without having to have RP's or even navzones or wanting to create a unit etc.. I had the following that your post reminded me I meant to share a while back in case someone else ever needed it. It was part of some ridiculous enhancements I did with my own unit spawner (also never shared).


The use case (among others) was where I needed it\preferred it over creating an unit just to call :inArea. I found better performance and less leakage as I recall. Particularly in a dynamic waypoint generator to target, among other things during pathfinding check it needed to check was if a possible next location was inside a no-nav zone that applied to a particular\potentially newly generated units. Another use was simply allowing me to do an 'inarea()' type call on any point within a given polygon I wanted without having to actually have navzones\rp's defined in the editor, sort of private easier to manage zones of my own if you will for a specific case or two.

text file attached to avoid forum garbling it.




michaelm75au -> RE: get units in area? (9/20/2019 10:17:43 PM)

I haven't tried it, but couldn't a NOT UnitsInArea trigger do it for you, where the triggering type is any enemy unit???




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.6721191