Jump to content

MIssion Scripting Tools (Mist)- enhancing mission scripting Lua


Recommended Posts

"mist.makeUnitTable" issue

 

Hi Grimes,

 

I have got a problem I do not get around. I am trying to make a table of all existing fighters and helicoperts of a coalition, with the idea to check their positions regularly for airspace violation. I am using this script to get the units on the map:

 

function getallredaircrafts()--ok
   RedAircraftstable = {'[red][plane]', '[red][helicopter]'}
   allredairunitsstart = {}
   allredairunitsstart = mist.makeUnitTable(RedAircraftstable)
   allredairunits = {}
   for a = 1, #allredairunitsstart
   do
       --local RedAircraftunit = Unit.getByName(allredairunitsstart[a])
       if Unit.getByName(allredairunitsstart[a]):isExist() == true
           then 
           allredairunits[#allredairunits + 1] =
                   {
                   name = allredairunitsstart[a]
                   }
       else
       return
       end
   end
   allredairunitsTable = mist.utils.tableShow(allredairunits)    --checkmessage ok
   trigger.action.outText("Red aircraft on map table:" ..allredairunitsTable, 2) --ok
   
return timer.getTime() + 4
end
timer.scheduleFunction(getallredaircrafts, nil, timer.getTime() + 2)

Before I simply used " mist.makeUnitTable(RedAircraftstable)" to create the table without checking if the unit exists.

 

Now this works nicely as long as no unit dies. If one of the red fighters crashes, dies or gets shot down, whatever, the function getallredaircrafts() breaks and does not give me any more results. The background is, that I am currently working on an "intercept script", which tasks fighters to intercept intruders, if no fighter is airborne, it shall spawn a fighter on the closest defined airfield. But therefore I need to track all the airplanes on the map.

Attached you also find the mission I am testing the script on....

test.miz

[sIGPIC][/sIGPIC]

 

Unsere Facebook-Seite

Link to comment
Share on other sites

Try removing 'else return'. With it there its going through the list and on the first unit that no longer exists it simply returns completely out of the whole function. In reality, you don't even need to do anything to it. The if statement will fail and it will move on to the next.

 

Sorta wonder if I should have a mist.makeActiveUnitTable or something similar.

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

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

That`s where I started. Didn´t use the return in the loop in my first appoach...

 

No joy.

 

Is there a DB function which can be used to create a list of units alive?

Like mist.DB.alive.units?


Edited by SNAFU

[sIGPIC][/sIGPIC]

 

Unsere Facebook-Seite

Link to comment
Share on other sites

Using 'if Unit.getByName('unitName') then' is itself a check to see if the unit exists within the mission. Unit.isExist() is just another check on top of that for when you store each unit object for use later.

 

mist.DBs.aliveUnits is updated constantly as part of a co-routine within mist. So yes, it is an accurate representation of all alive units at the specific moment it is checked throughout the duration of a mission.

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

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

Ok, thanks. I have one option I didn´t test yet, with clearing the

 

 
RedAircraftstable = {'[red][plane]', '[red][helicopter]'}

evertime the function is called, by setting

 

 
RedAircraftstable = {}

infront.

 

 

 

 

I also tried to just make the unit list once in the beginning and then to regularly make a fresh table with the units alive, but this broke a soon as a unit died too. And this would not update the list, if a unit is added dynamically.

 

 

Since I have no idea how to access mist.DBs, this is my last straw I can see. Is there an example how to use DBs somewhere besides the ones in the MIST-subfolder? I see the structure but not how to access them via script.

 

 

 

function getallredaircrafts()--ok

RedAircraftstable = {}

RedAircraftstable = {'[red][plane]', '[red][helicopter]'}

allredairunitsstart = {}

allredairunitsstart = mist.makeUnitTable(RedAircraftstable)

allredairunits = {}

for a = 1, #allredairunitsstart

do

if Unit.getByName(allredairunitsstart[a]):isExist() == true

then

allredairunits[#allredairunits + 1] =

{

name = allredairunitsstart[a]

}

end

end

allredairunitsTable = mist.utils.tableShow(allredairunits) --checkmessage ok

trigger.action.outText("Red aircraft on map table:" ..allredairunitsTable, 2) --ok

return timer.getTime() + 4

end

timer.scheduleFunction(getallredaircrafts, nil, timer.getTime() + 2)

 

 

 


Edited by SNAFU

[sIGPIC][/sIGPIC]

 

Unsere Facebook-Seite

Link to comment
Share on other sites

To access the DBs, it is best to use for x, y, in pairs(mist.DBs.DBname) do

               
	addAllByPrefix = function(searchString, vars)
		for groupName, groupData in pairs(mist.DBs.groupsByName) do
			if string.find(string.lower(groupName), string.lower(searchString)) then
				iads.add(groupName, vars)
			end
		end		
	end

 

In this example the mist.DBs.groupsByName is indexed by each groups name as a string. groupData is the actual table with all of the other data and it looks like the spoiler below.

 

 

 

{
       ["coalition"] = "blue",
       ["country"] = "usa",
       ["groupId"] = 7,
       ["category"] = "plane",
       ["countryId"] = 11,
       ["startTime"] = 0,
       ["groupName"] = "A-10C Client #2",
       ["units"] = 
       {
           [1] = 
           {
               ["alt"] = 2000,
               ["type"] = "A-10C",
               ["point"] = 
               {
                   ["y"] = 644428.57142857,
                   ["x"] = -315857.14285714,
               }, -- end of ["point"]
               ["groupId"] = 7,
               ["unitId"] = 12,
               ["groupName"] = "A-10C Client #2",
               ["coalition"] = "blue",
               ["countryId"] = 11,
               ["unitName"] = "A-10C Client #2",
               ["heading"] = -0.66079849060746,
               ["category"] = "plane",
               ["speed"] = 138.88888888889,
               ["alt_type"] = "BARO",
               ["country"] = "usa",
               ["skill"] = "Client",
           }, -- end of [1]
       }, -- end of ["units"]
   }, -- end of ["A-10C Client #2"]

 

 

 

To check mist.DBs.aliveUnits for what you are looking at, its probably best to something like:

 

for runtimeId, unitData in pairs(mist.DBs.aliveUnits) do
if (unitData.category == ('plane' or 'helicopter')) and unitData.coalition == 'red' then
	-- whatever
end
end

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

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

Well, this way it works

 

local function getallredaircrafts()--ok

   local RedAircraftstable = nil
   local RedAircraftstable = {}
   local RedAircraftstable = {'[red][plane]', '[red][helicopter]'}
   local allredairunitsstart = nil
   local allredairunitsstart = {}
   local allredairunitsstart = mist.makeUnitTable(RedAircraftstable)
   local allredairunits = nil
   local allredairunits = {}
   for a = 1, #allredairunitsstart
   do
       if Unit.getByName(allredairunitsstart[a])
           then 
           allredairunits[#allredairunits + 1] =
                   {
                   name = allredairunitsstart[a]
                   }
       end
   end
   local allredairunitsTable = mist.utils.tableShow(allredairunits)    --checkmessage ok
   trigger.action.outText("Red aircraft on map table:" ..allredairunitsTable, 2) --ok
return timer.getTime() + 10
end
timer.scheduleFunction(getallredaircrafts, nil, timer.getTime() + 1)

[sIGPIC][/sIGPIC]

 

Unsere Facebook-Seite

Link to comment
Share on other sites

Hi,

 

I'm trying to use this modified script to obtain that any group with a "TEST" tag in it's name will start to move in the direction of a particoular unit called Obiettivo1.

 

But it result in error, seems mostly about the use of the "GroupTable = {}" part but I can't understand why :(

 

 

local GroupTable = {}

local pointObj = Unit.getByName("Obiettivo1"):getPosition().p

 

for groupName, groupData in pairs(mist.DBs.groupsByName) do --List of groups by name

if string.find(groupName,"TEST") then --searches for prefix within group names

GroupTable[group_data.groupName] = mist.utils.deepCopy(groupName)

end

end

 

mist.groupToRandomPoint()

{

group = GroupTable

point = pointObj

}

 

ChromiumDis.png

Author of DSMC, mod to enable scenario persistency and save updated miz file

Stable version & site: https://dsmcfordcs.wordpress.com/

Openbeta: https://github.com/Chromium18/DSMC

 

The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.

Link to comment
Share on other sites

Whats the exact error message?

 

here it is:

 

error.jpg

 

and attached there is the miz file. Thanks so much :)

TEST_scripting.miz

ChromiumDis.png

Author of DSMC, mod to enable scenario persistency and save updated miz file

Stable version & site: https://dsmcfordcs.wordpress.com/

Openbeta: https://github.com/Chromium18/DSMC

 

The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.

Link to comment
Share on other sites

Hello Grimes,

 

I am now using your Mist 3.1 scripts also.

 

I see a number of issues with your scripts, as a user:

 

I have a number of Groups declared in a mission, that i want to dynamically spawn using dynAdd.

 

1. Dynamically spawning airplanes from a carrier make the units to start flying in the air, instead of from starting from the carrier.

 

2. Dynamically spawning helicopters does not seem to work at all. The helicopters are instantiated, i see them flying when i quickly jump to that unit when pressing F2, but they fly directly into the ground... Also, the textures of these units are completely wrong! They are yellow.

 

This is the code that i am using:

 

 
function KA50Spawn()

KA50Spawned = KA50Spawned + 1
_KA50GroupID = KA50Nameprefix..string.format("%03d",KA50Spawned)
_KA50Unit1ID = KA50Nameprefix..string.format("%03d",KA50Spawned*2+1)
_KA50Unit2ID = KA50Nameprefix..string.format("%03d",KA50Spawned*2+2)

_KA50Group = mist.cloneGroup(KA50Nameprefix.."000")
--_KA50Group.route = { points = mist.getGroupRoute(KA50Nameprefix.."000", true) }
_KA50Group.lateActivation = false
--_KA50Group.country = "BELGIUM"
--_KA50Group.category = "HELICOPTER"
--_KA50Group.groupName = _KA50GroupID
--_KA50Group.groupId = nil
--_KA50Group.start_time = 0
mist.dynAdd(_KA50Group)
end

 

Anybody having the same experiences?

 

Sven

[TABLE][sIGPIC][/sIGPIC]|

[/TABLE]

Link to comment
Share on other sites

Chromium, two things I noticed.

 

1. Syntax. You are missing a comma, and the table should be inside of the function call ().

mist.groupToRandomPoint({
group = GroupTable,
point = pointObj
})

 

2. GroupTable is not in the right format. It needs to be a "group class" which is basically Group.getByName(group_data.groupName) from above. A string of the groups name also works, but its best to just use the group class. Also I'd suggest putting the mist.groupToRandomPoint() function inside of the for loop if statement as it will send the groups that match to the random point.

 

 

Sorta like this:

 

local pointObj = Unit.getByName("Obiettivo1"):getPosition().p

for groupName, groupData in pairs(mist.DBs.groupsByName) do --List of groups by name
if string.find(groupName,"TEST") then --searches for prefix within group names
	mist.groupToRandomPoint({group = Group.getByName(groupName), point = pointObj})
end
end

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

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

svenvandevelde, I'll check whats going on with carrier spawns. As for helicopters, it looks like you are not giving them a payload and as a result no fuel. Otherwise the aircraft will spawn in the air without fuel, and their engines will shut down and they will crash. I don't have the script assign a default amount of fuel to the aircraft because it is impossible to get an accurate fuel load for specific aircraft due to it being based on fuel weight. I'd have to create a static DB of "max fuel weight" for every aircraft in the game or ask a dev for a scripting function to get that data for me to use. For now, its not in there.

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

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

Hello Grimes,

 

Would it be okay if i give you my mission file? then you can have a look ...

The helicopters are given a payload.

 

Search for units like "BE KA-50 #000". This helicopter group takes off at a ship, and is late activated.

However, using cloneGroup, and dynAdd, the helicopters are colored yellow and fly into the sea...

 

Check out the mission. Maybe you understand the problem better.

 

kind regards,

Sven

[TABLE][sIGPIC][/sIGPIC]|

[/TABLE]

Link to comment
Share on other sites

Thanks, as you probably know i'm slllllllowly learning lua from your script. Thanks so much :)

ChromiumDis.png

Author of DSMC, mod to enable scenario persistency and save updated miz file

Stable version & site: https://dsmcfordcs.wordpress.com/

Openbeta: https://github.com/Chromium18/DSMC

 

The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.

Link to comment
Share on other sites

Grimes,

 

Further debugging learns that the payload indeed is not copied on helicopters. I decommented the debug.write line in the dynAdd function, and this is the result.

 

See the file attached!

 

Looking further in your code what could be the reason ...

 

 
newUnits = 
{
   ["route"] = 
   {
       ["points"] = 
       {
           [1] = 
           {
               ["alt"] = 0,
               ["type"] = "TakeOff",
               ["action"] = "From Runway",
               ["alt_type"] = "BARO",
               ["form"] = "From Runway",
               ["y"] = 180717.21428573,
               ["x"] = -12492.857142857,
               ["speed"] = 41.666666666667,
               ["task"] = 
...

[TABLE][sIGPIC][/sIGPIC]|

[/TABLE]

Link to comment
Share on other sites

/OT

 

Future idea for MIST function: groung group formation for simulate axis of advance structure.

 

The idea is to create some sort of function that tell a group to continously move to a specific heading and distance point in relation of another group.

 

/OT

ChromiumDis.png

Author of DSMC, mod to enable scenario persistency and save updated miz file

Stable version & site: https://dsmcfordcs.wordpress.com/

Openbeta: https://github.com/Chromium18/DSMC

 

The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.

Link to comment
Share on other sites

Grimes,

 

Got a mission, which configures dummy groups with late activation on in the mission editor, and dynamically spawn these groups with mist.dynAdd or mist.cloneGroup using lua scripting.

 

However, i found problems in MIST 3.1 with planes and helicopters, resulting in incorrect actions using MIST 3.1.

 

Debugged your code, and found solutions, which require fixes to functions in MIST 3.1.

 

Please consider these fixes to be included in your further releases of MIST 3.1!

 

FIX 1: Fix the helicopters not having payload and correct speed when mist.cloneGroup is being used.

You'll need to fix the following statement block in the dynAdd function!

The commented code (with the -- prefix) is your code in Mist 3.1. The or expression is wrongly used.

I corrected your statement under your commented if statement ...

 

 

 
[color=gray]-- if (newCat == ('AIRPLANE' or 'HELICOPTER')) and not unitData.payload then[/color]
if [b][color=red](newCat == 'AIRPLANE' or newCat == 'HELICOPTER')[/color][/b] and not unitData.payload then
env.info(('Get payload for '..originalName..' and assign to '..newGroup.units[unitIndex].name))
newGroup.units[unitIndex].payload = mist.getPayload(originalName)
end

 

And add this in mist.getGroupData:

 

 
   if (newData.category == 'plane' or newData.category == 'helicopter') then
    newData.units[unitNum].payload = mist.getPayload(unitData.unitName)
   end

 

FIX 2: Helicopters and Planes not starting from a ship, as configured in the mission editor by my dummy unit, when mist.cloneGroup is being used.

 

And this underlying code fixed the helicopters and planes not starting from the ship, as configured in the mission editor. The underlying code needs to be added in the mist.getGroupRoute function in the code of MIST 3.1:

 
if obj_type_name == "helicopter" or obj_type_name == "plane" then           
   routeData.helipadId = point.helipadId
end

 

Hope this helps the community!

My helicopter is still yellow, so, going to debug to find fixes for the other problems now...

 

kind regards,

Sven


Edited by FlightControl

[TABLE][sIGPIC][/sIGPIC]|

[/TABLE]

Link to comment
Share on other sites

Hi,

 

I'm new to Mist but used to play around a lot with SL Mod, form my taste it was more noob freindly.

 

I would like to start it out easy but I think I cannot understand properly the guide:

 

" mist.msgMGRS

string mist.msgMGRS (table vars)

vars has the following recognized fields (required entries in blue, optional in green):

{

units = table UnitNameTable,

acc = number accuracy,

displayTime = number displayTime,

msgFor = table recipients,

text = string text,

}"

 

This is what I would like to use first. I tried to substitute values to my needs and came out with this one in a do script action.

 

mist.msgMGRS {

units = {P1},

acc = 6,

displayTime = 25,

msgFor = {coa = {'all'}},

}

 

It obviously don't work but I don't know why. Can someone help me out? Thank you!

 

P1 is the name of a singel unit I would like to get info of.

"Fighters make movies, bombers make history."

Link to comment
Share on other sites

Grimes,

 

Check out this post for fixes in MIST 3.1.

 

http://forums.eagle.ru/showthread.php?p=1874350#poststop

 

thanks,

Sven

[TABLE][sIGPIC][/sIGPIC]|

[/TABLE]

Link to comment
Share on other sites

Grimes,

 

I found some typo in the manual:

 

string mist.tostringMGRS(table t, number n)

...

Example returned value:

mist.utils.toStringMGRS(table, 0) returns 38T AB

mist.utils.toStringMGRS(table, 3) returns 38T AB 123 123

mist.utils.toStringMGRS(table, 5) returns 38T AB 12345 12345

 

so is it mist.tostringMGRS or mist.utils.toStringMGRS?

 

It is the same with mist.tostringLL

the example is the same as mist.tostringMGRS

 

 

I am trying to use the different mist.tostring... function to get the position of a unit firing a Kh-58. So far I manage to get a message saying which unit fire which weapons but I cannot get the position. What do I need to add to this code:

 

SEAD_launch = {}												
function SEAD_launch:onEvent(event)

if event.id == world.event.S_EVENT_SHOT 
then
	SEAD_unit = event.initiator	
	SEAD_unitName = Unit.getName(SEAD_unit)
	SEAD_unitGroup = SEAD_unit:getGroup()	
	_SEADmissile = event.weapon									
	_SEADmissileName = _SEADmissile:getTypeName()							
		if _SEADmissileName == "KH-58" or _SEADmissileName == "Kh-25ML" then
		trigger.action.outText("Warning  " ..string.format(SEAD_unitName).. "   launching  " ..string.format(_SEADmissileName),10)
		trigger.action.setUserFlag('10', true)
		end
	
end
end
mist.addEventHandler(SEAD_launch)

 

I am sure there is something clever to do with mist.msgBullseye or other mist.msg... but I can t get them to work either.

 

P.S: I have no knowledge at all about programing so if the code above is pure garbage please educate me! (i.e do I really need to add local to everything?)

Link to comment
Share on other sites

I'll probably update mist to version 3.2 later today.

 

Grimes,

Check out this post for fixes in MIST 3.1.

 

Thanks, I already had a good guess as to what was going on with it. Everything should be fixed regarding that stuff in 3.2. On a side note, helicopters are weird. Fixed wing aircraft can spawn without a livery_id without problem and will simply chose the first livery for that country. For some reason helicopters, especially the Ka-50, don't do that. I've fixed that issue within mist.

 

mist.msgMGRS {

units = {P1},

acc = 6,

displayTime = 25,

msgFor = {coa = {'all'}},

}

 

It obviously don't work but I don't know why. Can someone help me out? Thank you!

 

P1 is the name of a singel unit I would like to get info of.

 

The units table needs to be given a table of strings: units = {'P1'}

With just P1 it thinks that P1 is a variable name, which its not. It needs to be a string 'P1'

 

Grimes,

 

I found some typo in the manual:

 

string mist.tostringMGRS(table t, number n)

...

Example returned value:

mist.utils.toStringMGRS(table, 0) returns 38T AB

mist.utils.toStringMGRS(table, 3) returns 38T AB 123 123

mist.utils.toStringMGRS(table, 5) returns 38T AB 12345 12345

 

so is it mist.tostringMGRS or mist.utils.toStringMGRS?

 

It is the same with mist.tostringLL

the example is the same as mist.tostringMGRS

 

Yeah, thats a typo. It should be: mist.tostringMGRS. It'll be fixed in 3.2 release documentation. I'm also working toward converting the documentation to a wiki page. Partially because its possibly a better source to reference, but also so its easy to fix typos/modify the documentation.

 

I've modified the code example you provided.

SEAD_launch = {}												
function SEAD_launch:onEvent(event)

if event.id == world.event.S_EVENT_SHOT then
	local SEAD_unit = event.initiator	
	local SEAD_unitName = Unit.getName(SEAD_unit)
	local SEAD_unitGroup = SEAD_unit:getGroup()	
	local _SEADmissile = event.weapon									
	local _SEADmissileName = _SEADmissile:getTypeName()							
		if _SEADmissileName == "KH-58" or _SEADmissileName == "Kh-25MPU" then  -- Kh-25ML is not a SEAD missile 
		trigger.action.outText("Warning  " ..string.format(SEAD_unitName).. "   launching  " ..string.format(_SEADmissileName) .. '  at ' .. mist.tostringMGRS(coord.LLtoMGRS(coord.LOtoLL(_SEADmissile:getPosition().p)), 4),10)
		trigger.action.setUserFlag('10', true)
		end
	
end
end
mist.addEventHandler(SEAD_launch)

 

 

The table it accepts is an MGRS table, which is kind of annoying to get. See this page: http://en.wiki.eagle.ru/wiki/Part_1#coord

 

Basically you have to take a vec3 coordinate and convert it to Lat Lon, and then convert it to MGRS using the built in scripting functions of the sim. For example: MGRSTable = coord.LLtoMGRS(coord.LOtoLL(_SEADmissile:getPosition().p))

 

And yes, you have to add 'local' to any variable you want to create that you don't want to be accessible globally.

  • Like 1

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

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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