Jump to content

mist.flagFunc.Units_in_zones -- Spherical


Recommended Posts

Hi,

See attached mission.

 

I want a low flying Blue aircraft to set a flag when the a/c passes over a Red ship. Some odd results from this test mission -

 

1. I tried using Once, Do Script:

mist.flagFunc.units_in_zones{ units = {'[blue][plane]'}, zones = {'1 Sphere Zone'}, flag = 50107, zone_type = 'sphere' }

Example on Page 14 in Mist v2_0 guide rev0.pdf.

 

^^^ This did not work so I removed the zone_type, for this script:

mist.flagFunc.units_in_zones{ units = {'[blue][plane]'}, zones = {'1 Sphere Zone'}, flag = 50107 }

 

I also have a separate Do Script to detect the low altitude Blue a/c.

 

Both flags gets triggered prematurely - before the first, high altitude a/c gets to the zone. Why??

 

2. When the second, low altitude a/c gets to the zone the proper message is not generating. ??

 

3. When the two a/c circle around and enter the zone again, the messages are not repeating as desired. ??

 

---

 

When I look at the Mistv2_0.lua file at the mist.flagFunc.units_in_zones function, I do not see where it has a zone_type = sphere capability.

 

Am I correct that the zone_type = spherical is missing for this function? If I am, then the example in the Guide on Page 14 will not work, right?

 

---

 

I want this to work with the spherical zone type, not a cylindrical zone. How does a spherical zone get established - where does its altitude get set?

 

WC

Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site.

Link to comment
Share on other sites

You are missing some brackets. Function parameters are enclosed by round brackets:

mist.flagFunc.units_in_zones[color=red]([/color]{ units = {'[blue][plane]'}, zones = {'1 Sphere Zone'}, flag = 50107, zone_type = 'sphere' }[color=red])[/color]

 

Suggestion:

Why not use this:

mist.flagFunc.units_in_moving_zones({
units = {'[blue][plane]'},
zone_units = {'[red][ship]'},
flag = 50107,
radius = 3000,
zone_type = 'sphere'
})

 

Saves you a triggerzone ;)

aka: Baron

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

Thanks for the reply, St3v3f,

But I don't think that will help.

 

The Guide does not include the round brackets, and I've not used them in other vehicles in zone functions. To be sure I will test this, though.

 

As for the zone_units you suggest, I won't be able to use a generic '[red][ship]' as I have eight different places and not all have a red ship in them. So, I need to use a zone name.

 

---

 

How is the altitude of a spherical zone determined? I want to prevent the high altitude plane from triggering the script.

 

Why aren't the flags and messages repeating in the test mission?

 

WC

Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site.

Link to comment
Share on other sites

Thanks for the reply, St3v3f,

But I don't think that will help.

 

The Guide does not include the round brackets, and I've not used them in other vehicles in zone functions. To be sure I will test this, though.

Error in the manual. Even the fantastic Grimes and Speed make them as it seems ;)

 

Edit:

Oh wow, I've had no idea that it works without the round brackets. I always assumed that you'd need them.

 

How is the altitude of a spherical zone determined? I want to prevent the high altitude plane from triggering the script.

 

Why aren't the flags and messages repeating in the test mission?

 

WC

 

I can't look into the mission itself as I don't have access to DCS at this time, so unless you put the scripts in here, I can't comment ;)

You possibly expect the functions to work as on/off triggers, but they don't. They can only set the flag to true, they won't set it off again when the conditions are not met anymore.

 

Would be a nice feature though.

 

As to the altitude: There is no 'altitude' variable. Setting it to sphere will make it a bubble with the trigger zone's radius.

 

You could use the mist.flagFunc.units_in_polygon function, it will build a zone with a fixed ceiling. Create a red, deactivated unit and make it's waypoint's the outline of your triggerzone

 

mist.flagFunc.units_in_polygon({ 
units = {'[blue][plane]' }, 
zone = mist.getGroupPoints('groupname'), 
flag = 50107, 
maxalt = 1000,
})

 

Update:

Ok, it didn't let me go.

Checked your mission, something is odd here. The aircraft don't appear on the map or visually as if they were deactivated, yet they trigger the scripts. Doesn't look like script problem but a DCS problem.

I've set them to deactivated and built a trigger to activate them after 20 seconds. The first one flies to the trigger zone and activates both trigger - as it should be...

Set them to activate at mission start via trigger, all fine again.

I've added the zone_type = 'sphere' to the second script with flag 50207 and the first plane flew over the ships, triggered the high message but not the low message. That was properly triggered by the second aircraft - all well

 

Your Switched Condition triggers seem to indicate that you're trying just what I said. The functions don't set the flags off again, so the condition does not get set to false...

 

Update2:

Okay try this one:

 

local units = mist.makeUnitTable({'[blue][plane]'})
local flag = 50207
local zones = {'1 Sphere Zone'}
local zone_type = 'sphere'

local function unitsInZonesOnOff(result)
local ret = mist.getUnitsInZones(units, zones, zone_type)
if #ret == 0 and result == true then
	trigger.action.setUserFlag(flag, 0)
	result = false
elseif #ret > 0 and result == false then
	trigger.action.setUserFlag(flag, 1)
	result = true
end
mist.scheduleFunction (unitsInZonesOnOff, {result}, timer.getTime() + 1)
end

unitsInZonesOnOff(false)

 

Just run it once as you do with the other functions.

Important: Delete the flag off action from the switched condition


Edited by St3v3f

aka: Baron

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

Hi,

Look at the events that have the messages in them - those are what reset the flags to False. The a/c should trigger the events a few times.

 

ED folk - why are the Do Script events getting triggered so early in the test mission? The a/c are not even close to the zone, yet the flags are being set to True and that triggers the messages for the indication that the scripts are executing prematurely.

 

I should be able to F10 View the scene and see the a/c approach the zone and then see the messages as the a/c fly into the zone.

 

The zone_type of spherical MUST HAVE an altitude setting - how is that determined, or set?

 

Does a spherical zone have to be centered on a unit (that would provide the altitude variable)?

 

WC

Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site.

Link to comment
Share on other sites

Something is seriously awry with these Mist scripts -

 

mist.flagFunc.units_in_zones{

units = {'[blue][plane]'},

zones = {'Test Zone'},

flag = 50107,

zone_type = 'sphere'

}

 

mist.flagFunc.units_in_zones{

units = {'[blue][plane]'},

zones = {'Test Zone'},

flag = 50207,

zone_type = 'sphere'

}

 

 

Please take a look at this version of my Spherical Zone test mission.

 

Why are the events prematurely triggering?

 

WC

Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site.

Link to comment
Share on other sites

It's the aircraft that are somehow 'broken'. Try to replace them with new ones, the missions and all the scripts worked just as they should after that for me.

 

The problem with your switched condition trigger is that the script will continuously set the flags to true. So either your message comes up every second for as long as an aircraft is in the zone, or what i saw happening was that the trigger didn't even notice the flag was off again, because the script reactivated it too fast.

 

Altitude of the sphere-zone:

It's a sphere, a bubble... It's not only a circle in the horizontal plane but the vertical as well. Max altitude is the triggerzone's radius at it's center, the further you go away, the lower the altitude.

 

Try this mission.

What I've changed:

Replaced aircraft with new ones

Replaced the scripts with mine from above

Removed the Flag Off action from the switched conditions

WC's Spherical Zone Test v02.miz

aka: Baron

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

It appears the AI are "moving" before they spawn and the scripting engine is detecting that movement. Thus the AI are entering the zone before they are supposed to, even though they haven't visually spawned into the mission. As best as I can tell the mist function works as intended.

The right man in the wrong place makes all the difference in the world.

Current Projects: Scripting Wiki, Something...

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread), SLMOD, IADScript, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

St3v3 -

I appreciate your help, but the scripts I used are straight out of the Mist Guide. Is the Guide incorrect??

 

I have similar scripts that use vehicles in a zone and those do not continuously trigger like these planes in a zone seem to be doing. The events in my test mission are patterned after vehicles of a coalition in a zone and those work as expected. These scripts for planes in a zone do not work like the vehicles in zones.

edit - I am testing this further - I used all out of zone conditions before to turn off the script flags.

 

I want to use the scripts from the guide. So why are the triggers prematurely firing?

edit - because the mist tables are still getting populated in the first few seconds of the mission? GUESSing...

 

Why should I have to replace the a/c?

edit - I cloned them - no change.

 

Is the spherical zone center on the ground level? Is that true for sea level, true for in the mountains? What about when a zone is attached to a unit?

 

At what altitude is a spherical zone set to? Is the lower half below the terrain? Can a spherical zone be set completely in the air such that a unit could fly completely around it w/o triggering the event?

 

 

WC


Edited by Wrecking Crew

Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site.

Link to comment
Share on other sites

WC, you inadvertently found a bug with the scripting engine, which is part of the problem. It seems that to the scripting engine, any AI which start in the air AND is activated late is constantly moving in whatever direction of their first WP. Thus if you do a position check, it is possible that the object will enter a zone. Once it spawns it "teleports" back to its original position and everything works like it should. See the attached screenshot, the Scripting Engine sees the A-10C flying the path illustrated by the tape measure. I've reported this bug to the relevant devs and I'll add an extra "unit.isActive() == true" check to applicable Mist functions.

 

 

The other part of the problem is that the flagfuncs aren't meant to be toggled so quickly. So it is advisable to simply use a short "time since flag" instead of "flag true" if you want to switch the flag off to produce a message. The trigger system may not recognize if a flag has switched conditions as quickly as the scripting engine does, and I think that is probably whats going on.

sseBug.thumb.jpg.7c1a8ed5f643b9409dabc6b3a75bf007.jpg

The right man in the wrong place makes all the difference in the world.

Current Projects: Scripting Wiki, Something...

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread), SLMOD, IADScript, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

Grimes and St3v3 -

 

Grimes, agree with your description, looking at the start of the mission, it looked like that tele thingie was happening.

 

All this testing is to improve a multiplayer mission.

 

Had the testing been with Clients, the issue of the premature triggering most likely would not have happened -- ?? -- maybe.

 

^^ I was at the same conclusion as to what was happening, getting my arms around it. None of the other missions with Mist had this, but then they all involved vehicles in zones and not faster moving a/c.

 

WC

Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site.

Link to comment
Share on other sites

It would work without issue with clients. All AI are "alive" until they are killed or despawn. This means AI are alive before they spawn in with late activation. Clients are different, the clients unit simply doesn't exist until it spawns into the world.

 

As I said, the bug only occurs on aircraft if they are airborne and have a late activation. If AI start on the ground with late activation the bug won't occur.

The right man in the wrong place makes all the difference in the world.

Current Projects: Scripting Wiki, Something...

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread), SLMOD, IADScript, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

St3v3f -

This is really interesting -- what you provided above -

 

mist.flagFunc.units_in_moving_zones({

units = {'[blue][plane]'},

zone_units = {'[red][ship]'},

flag = 50107,

radius = 3000,

zone_type = 'sphere'

})

 

If I want a different, specific zone_unit instead of -

zone_units = {'[red][ship]'},

Would I use -

zone_units = {'Red SGrp01'},

Where 'Red SGrp01' is the name of the unit?

 

---

 

Using a script such as above, is there a need to create a zone on the map in the Mission Editor? There won't be a need for an established map zone, right?

 

 

WC

Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site.

Link to comment
Share on other sites

You'd use the constructors still: zone_units = {"[g]Red SGrp01"},

 

And there is no need to create a zone as it is defining a radius from each unit in the group as a "zone" to check.

The right man in the wrong place makes all the difference in the world.

Current Projects: Scripting Wiki, Something...

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread), SLMOD, IADScript, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

OK, I have this working -

 

mist.flagFunc.units_in_moving_zones{

units = {'[blue][plane]'},

zone_units = {'[g]Red SGrp01'},

flag = 40107,

radius = 300,

zone_type = 'sphere'

}

 

There are cases where the same kind of zones are needed around blue ships to detect blue a/c. That script also works fine -

 

mist.flagFunc.units_in_moving_zones{

units = {'[blue][plane]'},

zone_units = {'[g]Blue SGrp01'},

flag = 80107,

radius = 300,

zone_type = 'sphere'

}

 

^^^ With these zones, the blue a/c has to be within ~980 feet of the ship.

 

---

 

Problem - I need to turn off Flags 40107 and 80107 when the **Blue Planes** are out of the respective zones. St3vef, I know you gave a code example above, but I don't understand all of it - where 'result' comes from, why you have the last line 'unitsInZonesOnOff(false)', and what does the mist.scheduleFunction do - why is 'result' in as an argument and what is the timer + 1 for?

 

The turning off of the flags has to have a script. I did set up traditional zones of Radius = 400 to use for turning off the flags with A Coalition Out Of Zone event but that doesn't work when the ship is Blue :-) DOH. And I don't want to specify groups for an All Of Group Out Of Zone event -- too many, plus Clients could change, plus a [blue][planes] script would be better.

 

St3v3f's example -

local units = mist.makeUnitTable({'[blue][plane]'})

local flag = 50207

local zones = {'1 Sphere Zone'}

local zone_type = 'sphere'

 

local function unitsInZonesOnOff(result)

local ret = mist.getUnitsInZones(units, zones, zone_type)

if #ret == 0 and result == true then

trigger.action.setUserFlag(flag, 0)

result = false

elseif #ret > 0 and result == false then

trigger.action.setUserFlag(flag, 1)

result = true

end

mist.scheduleFunction (unitsInZonesOnOff, {result}, timer.getTime() + 1)

end

 

unitsInZonesOnOff(false)

 

With my detection scripts, I don't have a zone name. How do I get the script's flag to go back to false once all blue planes are out of the script-defined zones?

 

WC

Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site.

Link to comment
Share on other sites

Problem - I need to turn off Flags 40107 and 80107 when the **Blue Planes** are out of the respective zones. St3vef, I know you gave a code example above, but I don't understand all of it - where 'result' comes from, why you have the last line 'unitsInZonesOnOff(false)', and what does the mist.scheduleFunction do - why is 'result' in as an argument and what is the timer + 1 for?

 

The turning off of the flags has to have a script. I did set up traditional zones of Radius = 400 to use for turning off the flags with A Coalition Out Of Zone event but that doesn't work when the ship is Blue :-) DOH. And I don't want to specify groups for an All Of Group Out Of Zone event -- too many, plus Clients could change, plus a [blue][planes] script would be better.

 

With my detection scripts, I don't have a zone name. How do I get the script's flag to go back to false once all blue planes are out of the script-defined zones?

 

WC

 

My script does exactly that. It's working like the 'flagFunc' scripts, but turns the flag off again when there are no units in the zone anymore.

 

'mist.scheduleFunction' schedules a function to run at a later time. The 'unitsInZonesOnOff' function schedules itself to run again in one second after it finished (timer + 1), passing on the 'result' variable as an argument.

That is the reason you can call my script once and it continues to run until the mission ends.

 

The 'result' variable is an argument given to my unitsInZonesOnOff function. It is the result from the last time the function ran (Units in zone, yes or no). You could build the function without it, by unconditionally setting the flag true or false every time, but then you couldn't use 'time since flag' conditions in the ME because the flag is set every second.

The last line 'unitsInZonesOnOff(false)' is what really kicks off the script itself, it calls the function for the first time (after that it re-calls itself with scheduleFunction) and passes on false as an argument, because no units in the zone is the initial state in the mission.

Before this last line, the function has only been defined, it didn't run yet.

 

What the script basically does is:

- Get a list of units in the zone

- Check if the status changed:

- If there are no units in the the zone NOW (#ret == 0) but there have been units in the zone BEFORE (result == true), then deactivate the flag and change result to false (so the script knows there have been no units in the zone next time it runs)

- If there are units in the the zone NOW (#ret > 0) but there have been no units in the zone BEFORE (result == false), then activate the flag and change result to true (so the script knows there have been units in the zone next time it runs)

- Schedule to run again in one second

 

To use the script for other situations, just modify the variables in the first lines.

The script is quickly adaptable to work with 'UnitsInMovingZones' as well:

 

local units = mist.makeUnitTable({'[blue][plane]'})
local flag = 50207
local zones = mist.makeUnitTable({'[g]Red SGrp01'})
local radius = 300
local zone_type = 'sphere'

local function unitsInMovingZonesOnOff(result)
local ret = mist.getUnitsInMovingZones ( units, zones, radius, zone_type )
if #ret == 0 and result == true then
	trigger.action.setUserFlag(flag, 0)
	result = false
elseif #ret > 0 and result == false then
	trigger.action.setUserFlag(flag, 1)
	result = true
end
mist.scheduleFunction (unitsInMovingZonesOnOff, {result}, timer.getTime() + 1)
end

unitsInMovingZonesOnOff(false)

  • Like 1

aka: Baron

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

St3v3f -

Excellent! Excellent! Excellent!

 

Everything is working as desired!

 

Adding a few more events and all I want to do is looking good.

 

This is for 104th_Moa's Pirates Of The Crimean - the A-10Cs have to pass low over various ships to determine if they are friendly or pirates arrrgg! Once the flag is set then it is combined in another event with a Random(60) condition, so the pilots have to fly over a few times, maybe, until they can make the determination in the form of a message that lets them know if it is OK to destroy the ship. (I have Moa's permission to edit this mission.)

 

---

 

St3v3f -

Thank you for taking the time to explain your code.

 

Is 'local' a reserved word? Is it there to make it possible to have many events that all use the same function but with different arguments?

 

I do appreciate this - added to your rep. Sorry if I came across like a dick earlier - I was pretty frustrated with the original code I'd posted about.

 

WC

Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site.

Link to comment
Share on other sites

Can I assume that the flag won't be set True again once the ship with the zone is deactivated or destroyed?

 

WC

Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site.

Link to comment
Share on other sites

I'm just glad I could help :)

 

local is a reserved word, yes.

It limits the scope of a variable. A local variable is 'visible' only to the block of code it is declared in, and all blocks within that block. If you declare a variable without local, it will be a global variable. You can use it for example in an entirely different script (within the same mission). While that can be a good thing, it also has drawbacks. For example, you could run into conflicts with other functions using a variable with the same name.

 

Haven't tested it, but I would assume that once the target unit is dead, the function will return no in-Zone units, so it should be on false for the rest of the mission

aka: Baron

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

  • 4 months later...

Sorry to revive this thread but I'm stuck and can't find a way to make it happen so looking for help once more...

 

local units = mist.makeUnitTable({'[blue][plane]'})
local flag = 11
local zones = {'1', '2', '3', '4','5','6','7','8','9','10','11','12','13','14',}  -- it equal of about 2 NM in lenght
local zone_type = 'cylinder'
function StrafePit1OnOff(result)
local ret = mist.getUnitsInZones(units, zones, zone_type)
if #ret == 0 and result == true then
	trigger.action.setUserFlag(flag, 0)
	result = false
	if namesS1 ~= nil then
	namesS1={}
	end		
elseif #ret > 0 and result == false then
	trigger.action.setUserFlag(flag, 1)
	result = true 
	for i = 1, #ret do
		namesS1[#namesS1] = ret[i]:getName()
	end
end
mist.scheduleFunction (StrafePit1OnOff, {result}, timer.getTime() + 1)
end

StrafePit1OnOff(false)

 

In the above it just allow 1 unit to be added to the "namesS1" table which is the first unit to enter the zone.

 

Now if I do

namesS1[#namesS1 + 1] = ret[i]:getName()

It will add all the units name that are in the zone once the flag is activated thought its not what I'm looking for. What I'm trying to get is to be able to update that table so if gets the current unit inside the zone.

 

If I add another statement

Elseif #ret > 0 and result == true then
namesS1[#namesS1 + 1] = ret[i]:getName()

It will add the new units but table will be populated over and over and that's not what I'm looking for again lol

 

If I do the following

elseif #ret > 0 and result == true then
       If namesS1 ~= nil then
           namesS1 ={}
namesS1[#namesS1 + 1] = ret[i]:getName()

Was thinking that clearing the table first then adding the names would work but using mist tanbleshow it return {} so its not working....

 

Anyone have an idea how to make it work so it only add new names that are not already in the tables and remove the ones that aren't inside anymore.

 

Thanks

 

Cougar

sigpic4165_1.gif

attachment.php?attachmentid=36435&d=1266786388

Link to comment
Share on other sites

Also @St3v3f

 

How I would use this script with units in polygon if possible at all?

 

I've browses the mist 3.2 and there doesn't seem to have any specification about getunitsinzones for that one so maybe that's why I'm not able to avhieve anything on that side :/

sigpic4165_1.gif

attachment.php?attachmentid=36435&d=1266786388

Link to comment
Share on other sites

namesS1 is a global table and you keep inserting the values into it each time it runs.

 

The scripting function of "unitsInPolygon" is simply mist.pointInPolygon().

 

You simply need to iterate through the units table check each units position.

 

Something along the lines of...

 

local unitsInPoly = {}
local polyShape = mist.getGroupPoints('dummyGroupPolyZone')
for index, unitName in pairs(mist.makeUnitTable({'[blue][plane]'})) do
	if mist.pointInPolygon(Unit.getByName(unitName):getPosition().p, polyShape) then
		unitsInPoly[unitName] = unitName
	end
end

The right man in the wrong place makes all the difference in the world.

Current Projects: Scripting Wiki, Something...

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread), SLMOD, IADScript, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...