Page 1 of 1
get units in area?
Posted: Tue Aug 27, 2019 11:10 pm
by Whicker
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:
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:
local p = ScenEdit_GetReferencePoints({side="Crimson Commonwealth", area={"1","2","3"}})
print(p.unitsInArea)--no such thing
RE: get units in area?
Posted: Tue Aug 27, 2019 11:12 pm
by Whicker
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:
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)')
RE: get units in area?
Posted: Thu Sep 19, 2019 1:47 pm
by KnightHawk75
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.
RE: get units in area?
Posted: Fri Sep 20, 2019 7:17 pm
by michaelm75au
I haven't tried it, but couldn't a NOT UnitsInArea trigger do it for you, where the triggering type is any enemy unit???