Is there a way to iterate through the list of units still inside of the area?

Moderators: michaelm75au, angster, RoryAndersonCDT, MOD_Command

Thanks Knighthawk! I'll check it out and see how it works.ORIGINAL: KnightHawk75
If you're looking for an alternative scanning method, that may not lag like that (test and see I'd be interested in results), see the script I provided for vettim89 here, I've used it with checking couple hundred once per minute, but not thousands of units so don't know if it lags.
fb.asp?m=4797380
ORIGINAL: TitaniumTrout
Thanks Knighthawk! I'll check it out and see how it works.ORIGINAL: KnightHawk75
If you're looking for an alternative scanning method, that may not lag like that (test and see I'd be interested in results), see the script I provided for vettim89 here, I've used it with checking couple hundred once per minute, but not thousands of units so don't know if it lags.
fb.asp?m=4797380
The event is just saying a unit (of the appropriate type) has been here for '5 minutes'.
local side = VP_GetSide({side='sidea'})
print(side)
local u = side:unitsInArea({Area = { 'RP-3137', 'RP-3139', 'RP-3136', 'RP-3138'}, TargetFilter = { TargetType = 'Ship' } })
print(u)
side {
guid = '387dfb31-e553-412a-8258-9b959aa00aed',
name = 'SideA',
units = 'table',
contacts = 'table',
}
{ [1] = { name = 'DD 101 Murasame', guid = 'a1a52edf-3541-4b55-bea4-58d4e1ab11dc' } }
ORIGINAL: michaelm75au
It may be more practical to make this part of the 'side' wrapper as in:
local side = VP_GetSide({side='sidea'})
print(side)
local u = side:unitsInArea({Area = { 'RP-3137', 'RP-3139', 'RP-3136', 'RP-3138'}, TargetFilter = { TargetType = 'Ship' } })
print(u)
side {
guid = '387dfb31-e553-412a-8258-9b959aa00aed',
name = 'SideA',
units = 'table',
contacts = 'table',
}
{ [1] = { name = 'DD 101 Murasame', guid = 'a1a52edf-3541-4b55-bea4-58d4e1ab11dc' } }
Omit the TargetFilter, and it would give all units on the side in the area. Area needs to be mandatory of course.
ORIGINAL: michaelm75au
It may be more practical to make this part of the 'side' wrapper as in:
local side = VP_GetSide({side='sidea'})
print(side)
local u = side:unitsInArea({Area = { 'RP-3137', 'RP-3139', 'RP-3136', 'RP-3138'}, TargetFilter = { TargetType = 'Ship' } })
print(u)
side {
guid = '387dfb31-e553-412a-8258-9b959aa00aed',
name = 'SideA',
units = 'table',
contacts = 'table',
}
{ [1] = { name = 'DD 101 Murasame', guid = 'a1a52edf-3541-4b55-bea4-58d4e1ab11dc' } }
Omit the TargetFilter, and it would give all units on the side in the area. Area needs to be mandatory of course.
local side = VP_GetSide({side='NATO Allied Air Command'})
local jammerArea = {'Jammer 1', 'Jammer 2', 'Jammer 3', 'Jammer 4', 'Jammer 5', 'Jammer 6', 'Jammer 7', 'Jammer 8'}
for k,v in ipairs(side.units) do
local x = ScenEdit_GetUnit({ guid=v.guid })
if x:inArea(jammerArea) == true then print("In!") else print("Out!") end
end



This is the first time I've encountered the : operator and I'm still not clear on how it's functioning. Could you elaborate on it?
Code: Select all
gKH = {};gKH.Sensors = {} -- build our namespace for example.
gKH.Sensors.MatchParams = {} -- our MatchParams table\object.
--Method returns a instance of MatchParams with '.'
function gKH.Sensors.MatchParams.new(p)
local self = {};
self.MatchType = p.MatchType or 'DBID';
self.MatchValue = p.MatchValue or '0';
return self
end
--Now using : notation.
--Method returns a instance of MatchParams with ':'
function gKH.Sensors.MatchParams:new(p)
-- a variable 'self' exists here that refers to the instance of a MatchParams object that new was called on)
self.MatchType = p.MatchType or 'DBID';
self.MatchValue = p.MatchValue or '0';
return self;
end
Code: Select all
--function that is part of each MatchParams instance, does a self-check on it's own values using '.'
-- without getting into metatable stuff... that's out of scope
function gKH.Sensors.MatchParams.checkparams(obj)
-- we need caller to specify the object to use
if obj.MatchType ~= 'RANGELOWER' then print('not range lower'); end
end
--Same thing with ':' only we inherently have 'self' to use.
function gKH.Sensors.MatchParams:checkparams()
--self inherently means this instance.
if self.MatchType ~= 'RANGELOWER' then print('not range lower');end
end
Code: Select all
-- Both notations above accomplish the same thing just differently.
local m = gKH.Sensors.MatchParams.new({MatchType="ROLE"})
m.checkparams(m); -- <-- we have to tell it which object
-- vs.
local m = gKH.Sensors.MatchParams:new({MatchType="ROLE"})
m:checkparams; -- <-- m is automatically passed
ORIGINAL: michaelm75au
The new method in the 'side' wrapper would not be available until a future build. Sorry if I caused confusion.
