Jump to content

MIssion Scripting Tools (Mist)- enhancing mission scripting Lua


Recommended Posts

You want to use these random numbers with the ME triggers as part of a condition or as parameter to an action, if I understand you correctly?

 

That is not directly possible. Those conditions and actions always use a fixed value that you have to enter in the ME. Instead you would have to use more scripting. You would perhaps define the trigger without a condition and would program your condition directly within the lua code (surround your "action" code with IF ... ENDIF where you check your condition that uses the random function).

 

Maybe the simplest way to use the new random function with the existing ME tools is to set a flag to the result of the function - but for that, you need to use a small script, too (DO SCRIPT or DO SCRIPT FILE as SET FLAG VALUE only accepts fixed values, not lua function results). MIST and/or the DCS scripting engine make that quite easy, though. From there on, you could work with that flag as usual.

 

Use something like this to set a ME flag to a random value (attention: wrote this on the fly, not tested!):

do
 local flagName = "100"
 local minVal = 20
 local maxVal = 29
 
 trigger.action.setUserFlag(flagName, mist.random(minVal, maxVal))
end

 

 

That looks VERY doable! Thanks Flagrum!

 

 

Yeah, sorry about that. The instant I'd submitted the reply, I realized that I had answered the wrong question so I went ahead and tried to come up with something useful. :music_whistling:

 

 

 

The result of this random number generator is simply a number, so you can do anything with it that you could do with a number, like setting it as a flag value, going through an if/elseif/else condition, using it in an iterator, concatenating it to a string and so on. It's totally up to you.

 

One more example. Let's say there were 5 sound files in the mission named sound1.ogg to sound5.ogg and in a DO SCRIPT container, one of them should be randomly played:

 

local random_number = mist.random(1, 5)
local funny_tune = "sound" .. random .. ".ogg"
trigger.action.outSound(funny_tune)

 

 

Thanks also for this Yurgon!

"ENO"

Type in anger and you will make the greatest post you will ever regret.

 

"Sweetest's" Military Aviation Art

Link to comment
Share on other sites

Grimes,

 

In line 4789, there is the following code in dynAdd:

 

coalition.addGroup(country.id[newCountry], Unit.Category[newCat], newGroup)

 

I believe this call is wrong, because for vehicles, it would not spawn vehicles, but "buildings" instead... I notice this because of two things:

 

1. When i kill vehicles spawned with dynAdd, i get the message "killed building"...

2. When i play my mission in Multi player, on the server i see smoke of the vehicles, but on the client side, they appear without smoke.

3. I cannot see on the client side the vehicles spawned...

 

I think doing the call using Group.Category would fix this problem. (the category should be "vehicle", not "ground_unit" ) ...

 

I believe this is the root cause of the above problem, because in the documentation, category of a unit is documented as follows:

 

Unit.Category = {

AIRPLANE,

HELICOPTER,

GROUND_UNIT,

SHIP,

STRUCTURE

}

 

and of a group:

 

Group.Category = {

AIRPLANE,

HELICOPTER,

GROUND,

SHIP

}

 

Please revert if i am right...

 

Sven


Edited by FlightControl

[TABLE][sIGPIC][/sIGPIC]|

[/TABLE]

Link to comment
Share on other sites

Grimes,

 

In line 4789, there is the following code in dynAdd:

 

coalition.addGroup(country.id[newCountry], Unit.Category[newCat], newGroup)

 

I believe this call is wrong, because for vehicles, it would not spawn vehicles, but "buildings" instead... I notice this because of two things:

 

1. When i kill vehicles spawned with dynAdd, i get the message "killed building"...

2. When i play my mission in Multi player, on the server i see smoke of the vehicles, but on the client side, they appear without smoke.

3. I cannot see on the client side the vehicles spawned...

 

I think doing the call using Group.Category would fix this problem. (the category should be "vehicle", not "ground_unit" ) ...

 

I believe this is the root cause of the above problem, because in the documentation, category of a unit is documented as follows:

 

Unit.Category = {

AIRPLANE,

HELICOPTER,

GROUND_UNIT,

SHIP,

STRUCTURE

}

 

and of a group:

 

Group.Category = {

AIRPLANE,

HELICOPTER,

GROUND,

SHIP

}

 

Please revert if i am right...

 

Sven

 

The changes were done on the mist script, but without effect. ... Need to dig deeper into the problem... When i kill the ground units, it says "killed building". Maybe i have incorrectly applied the unit type for each unit. Need to check the mission file for that.

 

Sven


Edited by FlightControl

[TABLE][sIGPIC][/sIGPIC]|

[/TABLE]

Link to comment
Share on other sites

The changes were done on the mist script, but without effect. ... Need to dig deeper into the problem... When i kill the ground units, it says "killed building". Maybe i have incorrectly applied the unit type for each unit. Need to check the mission file for that.

 

Sven

 

OK... Found the problem with the "killed building" message ...

It is an unforeseen bug within MIST 3.2.

 

Grimes, the following:

You use a "category" field within your tables to highlight which data for which types of objects the records contain.

 

GROUND UNITS, if you spawn them using coalition.addGroup(country.id[newCountry], Unit.Category[newCat], newGroup), you must ensure that the category field is made a value nil, or the category field will be used by the addGroup method, and will recognize the object as a "static object", or building...

 

Now, looking in your mist 3.3 logic that is exactly what i found:

 

 -- sanitize table
newGroup.groupName = nil
newGroup.clone = nil
newGroup.category = nil
newGroup.country = nil

pffff... and that to know how much time i've spent trying to solve this issue myself ... Anyway, found the root cause.

 

There are two issues open for me then for ground units:

1. spawned units on the server don't show at the client on the map. They are hidden.

2. spawned units don't show a dust trail on the client.

 

I'll move to your mist 3.3 version with my logic.

 

Sven

[TABLE][sIGPIC][/sIGPIC]|

[/TABLE]

Link to comment
Share on other sites

Hi Eno.

 

The problem was with mist 3.2.

 

Issue 1 was solved having a correct table structure as input. Setting the category, country etc to nil solves the "killed building" issue.

 

Issues 2 and 3 are still open.

Vehicles dynamically spawned don't show a dust trail and don't show up in the map during a client session. Earlier spawned ground units show up when the mission is loaded on the client by joining an active server session.

 

Small message to Eagle dynamics, so Ed, maybe this is an opportunity to fix these little issues. .. (You don't have to search for them yourself).

 

Also tried yesterday to host my mission, crash after 20 minutes when clients popped in. Server runs stable without clients.

 

Sv.


Edited by FlightControl

[TABLE][sIGPIC][/sIGPIC]|

[/TABLE]

Link to comment
Share on other sites

Small message to Eagle dynamics, so Ed, maybe this is an opportunity to fix these little issues. .. (You don't have to search for them yourself).

 

Also tried yesterday to host my mission, crash after 20 minutes when clients popped in. Server runs stable without clients.

 

Sv.

 

I think that issues with dynamically spawned units are fixed in internal DCS versions. At least, right now.

Intelligent discourse can only begin with the honest admission of your own fallibility.

Member of the Virtual Tactical Air Group: http://vtacticalairgroup.com/

Lua scripts and mods:

MIssion Scripting Tools (Mist): http://forums.eagle.ru/showthread.php?t=98616

Slmod version 7.0 for DCS: World: http://forums.eagle.ru/showthread.php?t=80979

Now includes remote server administration tools for kicking, banning, loading missions, etc.

Link to comment
Share on other sites

MIST3.3: some dynamically added groups not added to mist.DBs.groupsByName

 

Hi,

 

Starting with MIST 3.3 I have the problem that some of the dynamically added groups do not appear in mist.DBs.groupsByName and mist.DBs.unitsByName tables. The same missions work flawlessly in MIST3.2, but in MIST3.3 it appears that only those dynamically added units that are generated close to mission start get updated into the DBs. Those units generated later on in missions never make it into the DBs.

 

I have not yet investigated this carefully. At this point I want to find out if anyone else has that problem, and/or if there is interest to investigate this more thoroughly.

[sIGPIC][/sIGPIC]

 

Intel Core I7 4820K @4.3 GHz, Asus P9X79 motherboard, 16 GB RAM @ 933 MHz, NVidia GTX 1070 with 8 GB VRAM, Windows 10 Pro

Link to comment
Share on other sites

I've decided it's time to learn how to script. I chose one arbitrary function to try out for practice purposes and while fiddling with that I've come to find something I want to add to an actual mission. I'm using MIST 3.2

 

1. mist.dynAdd (practice)

2. Add attack group as a triggered action to an Escort flight

 

For the first, I took a look at the DB's provided with MIST and modified them:

 

dynGroupsAdded = 
{
   [1] = 
   {
       ["country"] = "usa",
       ["units"] = 
       {
           [1] = 
           {
               ["type"] = "F-15C",
               ["point"] = 
               {
                   ["y"] = 0,
                   ["x"] = 0,
               }, -- end of ["point"]
               ["country"] = "usa",
               ["groupName"] = "Group",
               ["unitId"] = 44,
               ["coalition"] = "blue",
               ["heading"] = 1.4977557614926,
               ["alt"] = 10000,
               ["alt_type"] = "RADIO",
               ["category"] = "plane",
               ["unitName"] = "Unit",
               ["countryId"] = 2,
               ["groupId"] = 22,
               ["skill"] = "Excellent",
           }, -- end of [1]
           
       }, -- end of ["units"]
       
} -- end of dynGroupsAdded
}
mist.dynAdd('dynGroupsAdded', 'usa', 'plane')

I just want to spawn a F-15 somewhere.

 

I'm only getting errors. As it is now, I think it's saying it expects a string in the last line but gets nil. I'm not quite sure from reading the pdf how exactly I'm supposed to write the script. I've tried downloading other scripts that I expected to have dynAdd, but none used it, which made me think I might be using the wrong function anyway.

 

For the second issue, I don't have anything written yet since I'm still dealing with getting MIST to work at all.

Awaiting: DCS F-15C

Win 10 i5-9600KF 4.6 GHz 64 GB RAM RTX2080Ti 11GB -- Win 7 64 i5-6600K 3.6 GHz 32 GB RAM GTX970 4GB -- A-10C, F-5E, Su-27, F-15C, F-14B, F-16C missions in User Files

 

Link to comment
Share on other sites

I've decided it's time to learn how to script. I chose one arbitrary function to try out for practice purposes and while fiddling with that I've come to find something I want to add to an actual mission. I'm using MIST 3.2

 

1. mist.dynAdd (practice)

2. Add attack group as a triggered action to an Escort flight

 

For the first, I took a look at the DB's provided with MIST and modified them:

 

dynGroupsAdded = 
{
   [1] = 
   {
       ["country"] = "usa",
       ["units"] = 
       {
           [1] = 
           {
               ["type"] = "F-15C",
               ["point"] = 
               {
                   ["y"] = 0,
                   ["x"] = 0,
               }, -- end of ["point"]
               ["country"] = "usa",
               ["groupName"] = "Group",
               ["unitId"] = 44,
               ["coalition"] = "blue",
               ["heading"] = 1.4977557614926,
               ["alt"] = 10000,
               ["alt_type"] = "RADIO",
               ["category"] = "plane",
               ["unitName"] = "Unit",
               ["countryId"] = 2,
               ["groupId"] = 22,
               ["skill"] = "Excellent",
           }, -- end of [1]
           
       }, -- end of ["units"]
       
} -- end of dynGroupsAdded
}
mist.dynAdd('dynGroupsAdded', 'usa', 'plane')

I just want to spawn a F-15 somewhere.

 

I'm only getting errors. As it is now, I think it's saying it expects a string in the last line but gets nil. I'm not quite sure from reading the pdf how exactly I'm supposed to write the script. I've tried downloading other scripts that I expected to have dynAdd, but none used it, which made me think I might be using the wrong function anyway.

 

For the second issue, I don't have anything written yet since I'm still dealing with getting MIST to work at all.

I'm no expert in dynamic spawning, Grimes wrote that part, but why are you modifying the DBs? They exist only for reference, like if you need to write some code that looks up what kinds of units, and how many, are in the mission. You should consider them "read only". You can't expect to modify them and expect something to actually happen as a result of it; that would be similar to making a page about yourself on Wikipedia, saying that you are a billionaire, and then expecting it to come true :)

 

Again, I know little about how Grimes programmed the dynamic spawning, but looking at your code, it is clear you made at least one error.

mist.dynAdd('dynGroupsAdded', 'usa', 'plane')

 

should be

mist.dynAdd(dynGroupsAdded, 'usa', 'plane')

 

But I doubt that will work, as it doesn't look like the proper format for a group you're trying to add. Didn't Grimes include some examples in the documentation?


Edited by Speed

Intelligent discourse can only begin with the honest admission of your own fallibility.

Member of the Virtual Tactical Air Group: http://vtacticalairgroup.com/

Lua scripts and mods:

MIssion Scripting Tools (Mist): http://forums.eagle.ru/showthread.php?t=98616

Slmod version 7.0 for DCS: World: http://forums.eagle.ru/showthread.php?t=80979

Now includes remote server administration tools for kicking, banning, loading missions, etc.

Link to comment
Share on other sites

I'm no expert in dynamic spawning, Grimes wrote that part, but why are you modifying the DBs? They exist only for reference, like if you need to write some code that looks up what kinds of units, and how many, are in the mission. You should consider them "read only". You can't expect to modify them and expect something to actually happen as a result of it; that would be similar to making a page about yourself on Wikipedia, saying that you are a billionaire, and then expecting it to come true :)

 

To be more clear, I wasn't editing the DB lua's and saving, I copy pasted from them to use as a template. I load MIST using the Initialization script option in the mission trigger page then I use DO SCRIPT with the code I posted above.

 

Again, I know little about how Grimes programmed the dynamic spawning, but looking at your code, it is clear you made at least one error.
mist.dynAdd('dynGroupsAdded', 'usa', 'plane')

should be

mist.dynAdd(dynGroupsAdded, 'usa', 'plane')

But I doubt that will work, as it doesn't look like the proper format for a group you're trying to add. Didn't Grimes include some examples in the documentation?

 

There isn't an example I can copy from pdf for dynAdd. I was playing with that last line, I'm pretty sure one of the variations was without quotes around dynGroupsAdded, but I'll try again in case I missed that one while I wait for Grimes. Thanks for the help.

Awaiting: DCS F-15C

Win 10 i5-9600KF 4.6 GHz 64 GB RAM RTX2080Ti 11GB -- Win 7 64 i5-6600K 3.6 GHz 32 GB RAM GTX970 4GB -- A-10C, F-5E, Su-27, F-15C, F-14B, F-16C missions in User Files

 

Link to comment
Share on other sites

I haven't used this MiST function, but I'll try to help anyway.

 

First thing I notice is that by the MiST documentation, mist.dynnAdd takes only one parameter

 

table  mist.dynAdd (table vars)

 

Where vars = {units, country, category}

 

So it should look like:

 

mist.dynAdd({dynGroupsAdded, 'usa', 'plane'})

 

Let me know of this works

Link to comment
Share on other sites

I still get the same error, so something else must be wrong.

 

I took a screenshot so someone could double check that I'm not just doing something wrong on the triggers tab

 

 

EDIT - Looks like my set up is fine. I changed my script to a very simple respawn script and the unit did respawn.

Screen_140217_211113.thumb.jpg.bc1a4cd53cb39b899684fd742e113cb3.jpg


Edited by Exorcet

Awaiting: DCS F-15C

Win 10 i5-9600KF 4.6 GHz 64 GB RAM RTX2080Ti 11GB -- Win 7 64 i5-6600K 3.6 GHz 32 GB RAM GTX970 4GB -- A-10C, F-5E, Su-27, F-15C, F-14B, F-16C missions in User Files

 

Link to comment
Share on other sites

I suspect the problem is an invalid unit table. The MiST documentation gives this as the table explanation:

 

{ 
x = number vec2XCoord, 
y =  number vec2YCoord, 
type = string objectTypeName, 
unitId = number unitId, 
name or unitName = string unitsName, 
payload = table mePayloadTable, 
speed = number speed, 
alt = number altitude, 
alt_type = string altitudeType, 
skill = string skill, 
route = table routeData, 
callsign = table callsignTable, 
livery_id = string liveryName,  
}

 

And it says it should match mission editor format. The exemple you gave do not. Try with this:

 

dynGroupsAdded = 
{
   ["country"] = "usa",
    ["category"] = "plane",
   ["units"] = 
   {
       [1] = 
       {
            ["x"] = 0,
            ["y"] = 0,
           ["type"] = "F-15C",
           ["unitId"] = 44,
            ["name"] = "Unit",
           ["heading"] = 1.4977557614926,
           ["alt"] = 10000,
           ["alt_type"] = "RADIO",
            ["speed"] = 500,
           ["skill"] = "Excellent",
       }, -- end of [1]      
   }, -- end of ["units"]
} -- end of dynGroupsAdded

mist.dynAdd(dynGroupsAdded)

 

Since dynnGroupsAdded is already a table with all the info, you only need to pass it directly to the function.

 

If it doesn't work, try looking at a unit table in a mission file (unzip a mission file, and look at the extensionless "mission" file).

Link to comment
Share on other sites

I had the time to give it a try (as opposed to guess-working what would work), and it turns out my above correction works indeed. Only, I hadn't realized speed was in m/s, so 500 is a little high :D It's also optional, and will be defaulted to 150 m/s (540 km/h) if left out.

 

Also, the aircraft spawns and the pilot immediately ejects, because, as pointed out in the MiST manual:

 

payload is a table matching the mission editor table for a payload. It is important to note that

the scripting engine cannot generate the values needed for this table unless the information is

provided beforehand. If the unit being spawned is an helicopter or airplane and no payload is

specified, then the aircraft WILL NOT HAVE FUEL and its engines will not run.

So, once again, take a look at a mission file to sort out the correct formatting for the payload table.

Link to comment
Share on other sites

That was indeed it, thanks. Now the plane spawns

 

I know about the payload issue, I just decided to put it to the side. At least the pilot survived. The life of a test pilot isn't always easy

Awaiting: DCS F-15C

Win 10 i5-9600KF 4.6 GHz 64 GB RAM RTX2080Ti 11GB -- Win 7 64 i5-6600K 3.6 GHz 32 GB RAM GTX970 4GB -- A-10C, F-5E, Su-27, F-15C, F-14B, F-16C missions in User Files

 

Link to comment
Share on other sites

Hi,

 

Starting with MIST 3.3 I have the problem that some of the dynamically added groups do not appear in mist.DBs.groupsByName and mist.DBs.unitsByName tables. The same missions work flawlessly in MIST3.2, but in MIST3.3 it appears that only those dynamically added units that are generated close to mission start get updated into the DBs. Those units generated later on in missions never make it into the DBs.

 

I have not yet investigated this carefully. At this point I want to find out if anyone else has that problem, and/or if there is interest to investigate this more thoroughly.

 

Wolle, i have the same problem... trying to find out why this happens ...

 

Grimes, if you have a clue why, pls tell us, so we don't have to waste our time ...

 

thanks,

Sven

[TABLE][sIGPIC][/sIGPIC]|

[/TABLE]

Link to comment
Share on other sites

Wolle, i have the same problem... trying to find out why this happens ...

 

Grimes, if you have a clue why, pls tell us, so we don't have to waste our time ...

 

thanks,

Sven

 

Hi Sven,

 

Now that I know others have that problem too, I will also try to investigate further ...

[sIGPIC][/sIGPIC]

 

Intel Core I7 4820K @4.3 GHz, Asus P9X79 motherboard, 16 GB RAM @ 933 MHz, NVidia GTX 1070 with 8 GB VRAM, Windows 10 Pro

Link to comment
Share on other sites

Hi Sven,

 

Now that I know others have that problem too, I will also try to investigate further ...

 

the bug will be within his rewritten functions dbUpdate...

 

The code needs further testing. I wonder how much he has tested this...

 

Somewhere down the lines here:

 

 mist.dbUpdate = function(event)
 local groupData

 env.info('dbUpdate')
--[[ Similar to normal DBs, example...
 [unitID] = {
  [instance1] = {fist added unitData}
  [instance2] = {2nd added Unit Data}
 ]]


 if type(event) == 'string' then -- if name of an object. 
  --env.info('event')
  local newObject
  local newType = 'group'
  if Group.getByName(event) then
   newObject = Group.getByName(event)
   env.info('dbUpdate: group')
  elseif StaticObject.getByName(event) then
   newObject = StaticObject.getByName(event)
   newType = 'static'
   env.info('its static')
  else
   --env.info('WTF')
   return false
  end
  
  groupData = {}
  groupData.name = newObject:getName()
  groupData.groupId = tonumber(newObject:getID())
   env.info('dbUpdate: groupData.name = ' .. groupData.name )
  env.info('dbUpdate: groupData.groupId = ' .. groupData.groupId )
  
  local unitOneRef 
  if newType == 'static' then
  
   unitOneRef = newObject 
   groupData.countryId = tonumber(newObject:getCountry())
   groupData.coalitionId = tonumber(newObject:getCoalition())
   groupData.category = 'static'
  else
   unitOneRef = newObject:getUnits()
   groupData.countryId = tonumber(unitOneRef[1]:getCountry())
   groupData.coalitionId = tonumber(unitOneRef[1]:getCoalition())
   groupData.category = tonumber(newObject:getCategory())
  end
  
  groupData.units = {}
  if newType == 'group' then
   for unitId, unitData in pairs(unitOneRef) do
    groupData.units[unitId] = {}
    groupData.units[unitId].name = unitData:getName()
    env.info('dbUpdate: unitId = ' .. unitId .. ', groupData.units['.. unitId .. '].name = ' .. groupData.units[unitId].name )
    
    groupData.units[unitId].x = mist.utils.round(unitData:getPosition().p.x)
    groupData.units[unitId].y = mist.utils.round(unitData:getPosition().p.z)
    groupData.units[unitId].alt = mist.utils.round(unitData:getPosition().p.y)
    groupData.units[unitId].alt_type = "BARO"    
    groupData.units[unitId].heading = mist.getHeading(unitData)
     groupData.units[unitId].type = unitData:getTypeName()
    groupData.units[unitId].unitId = tonumber(unitData:getID())
    groupData.units[unitId].skill = "HIGH" 
    
    groupData.units[unitId].groupName = groupData.name
    groupData.units[unitId].groupId = groupData.groupId
    groupData.units[unitId].countryId = groupData.countryId
    groupData.units[unitId].coalitionId = groupData.coalitionId
    
   end
  else -- its a static
    groupData.units[1] = {}
   groupData.units[1].name = newObject:getName()
   
   groupData.units[1].x = mist.utils.round(newObject:getPosition().p.x)
   groupData.units[1].y = mist.utils.round(newObject:getPosition().p.z)
   groupData.units[1].alt = mist.utils.round(newObject:getPosition().p.y)
   groupData.units[1].heading = mist.getHeading(newObject)
   groupData.units[1].type = newObject:getTypeName()
   groupData.units[1].unitId = tonumber(newObject:getID())
   groupData.units[1].groupName = groupData.name
   groupData.units[1].groupId = groupData.groupId
   groupData.units[1].countryId = groupData.countryId
   groupData.units[1].coalitionId = groupData.coalitionId

  
  end
  
 else -- its a table
  groupData = event

 end

 local mistCategory 
 if type(groupData.category) == 'string' then
  mistCategory = string.lower(groupData.category)
 end
  --mist.debug.writeData(mist.utils.serialize,{'DBs', groupData}, 'newUnits.txt') 
 --for newGroupIndex, newGroupData in pairs(groupData) do
  local newTable = {}
 
 local tableSize = #mist.DBs.dynGroupsAdded + 1
 newTable['name'] = groupData.name
 newTable['groupId'] = groupData.groupId
 newTable['startTime'] =  timer.getAbsTime()
 newTable['task'] = groupData.task
 
  for countryData, countryId in pairs(country.id) do
  if groupData.country and string.upper(countryData) == string.upper(groupData.country) or countryId == groupData.countryId then
   newTable['countryId'] = countryId
   newTable['country'] = string.lower(countryData)
   for coaData, coaId in pairs(coalition.side) do
    if coaId == coalition.getCountryCoalition(countryId) then 
     newTable['coalition'] = string.lower(coaData)
    end
   end
  end
 end
  for catData, catId in pairs(Unit.Category) do
  if Group.getByName(groupData.name) then
   if catId == Group.getByName(groupData.name):getCategory() then
    newTable['category'] = string.lower(catData)
   end
  elseif StaticObject.getByName(groupData.name) then
   if catId == StaticObject.getByName(groupData.name):getCategory() then
    newTable['category'] = string.lower(catData)
   end
  end
 end
 
  if string.upper(newTable['category']) == 'GROUND_UNIT' then
  mistCategory = 'vehicle'
  newTable['category'] = mistCategory
 elseif string.upper(newTable['category']) == 'AIRPLANE' then
  mistCategory = 'plane'
  newTable['category'] = mistCategory
 
 end
 newTable['units'] = {}
 for newUnitId, newUnitData in pairs(groupData.units) do
  if not newUnitData.unitId then
   
  end
  
  
  newTable['units'][newUnitId] = {}
  newTable['units'][newUnitId]['unitName'] = newUnitData.name
  newTable['units'][newUnitId]['groupId'] = tonumber(groupData.groupId)
  newTable['units'][newUnitId]['heading'] = newUnitData.heading
  newTable['units'][newUnitId]['point'] = {}
  newTable['units'][newUnitId]['point']['x'] = newUnitData.x
  newTable['units'][newUnitId]['point']['y'] = newUnitData.y
  newTable['units'][newUnitId]['alt'] = newUnitData.alt
  newTable['units'][newUnitId]['alt_type'] = newUnitData.alt_type
  newTable['units'][newUnitId]['unitId'] = tonumber(newUnitData.unitId)
  newTable['units'][newUnitId]['speed'] = newUnitData.speed
  newTable['units'][newUnitId]['airdromeId'] = newUnitData.airdromeId
  newTable['units'][newUnitId]['type'] = newUnitData.type
  newTable['units'][newUnitId]['skill'] = newUnitData.skill
  newTable['units'][newUnitId]['groupName'] = groupData.name
  newTable['units'][newUnitId]['livery_id'] = groupData.livery_id
  newTable['units'][newUnitId]['country'] = string.lower(newTable.country)
  newTable['units'][newUnitId]['countryId'] = newTable.countryId
  newTable['units'][newUnitId]['coalition'] = newTable.coalition
  newTable['units'][newUnitId]['category'] = newTable.category
  
  newTable['units'][newUnitId]['shape_name'] = newTable.shape_name -- for statics
  
     
  
  if newUnitData.unitId then
   mist.DBs.unitsById[tonumber(newUnitData.unitId)] = mist.utils.deepCopy(newTable['units'][newUnitId]) 
  end
  
  mist.DBs.unitsByName[newUnitData.name] = mist.utils.deepCopy(newTable['units'][newUnitId])
  mist.DBs.unitsByCat[mistCategory][#mist.DBs.unitsByCat[mistCategory] + 1] = mist.utils.deepCopy(newTable['units'][newUnitId])
  mist.DBs.unitsByNum[#mist.DBs.unitsByNum + 1] = mist.utils.deepCopy(newTable['units'][newUnitId])  

 end
  
 
 -- this is a really annoying DB to populate. Gotta create new tables in case its missing
 if not mist.DBs.units[newTable.coalition] then
  mist.DBs.units[newTable.coalition] = {}
 end
  if not mist.DBs.units[newTable.coalition][newTable.country] then
  mist.DBs.units[newTable.coalition][(newTable.country)] = {}
  mist.DBs.units[newTable.coalition][(newTable.country)]['countryId'] = newTable.countryId
 end
 if not mist.DBs.units[newTable.coalition][newTable.country][mistCategory] then
  mist.DBs.units[newTable.coalition][(newTable.country)][mistCategory] = {}
 end
 mist.DBs.units[newTable.coalition][(newTable.country)][mistCategory][#mist.DBs.units[newTable.coalition][(newTable.country)][mistCategory] + 1] = mist.utils.deepCopy(newTable)
 
 if newTable.groupId then
  mist.DBs.groupsById[groupData.groupId] = mist.utils.deepCopy(newTable)
 end
 
 mist.DBs.groupsByName[groupData.name] = mist.utils.deepCopy(newTable)
 
 newTable['timeAdded'] = timer.getAbsTime() -- only on the dynGroupsAdded table. For other reference, see start time
 mist.DBs.dynGroupsAdded[#mist.DBs.dynGroupsAdded + 1] = mist.utils.deepCopy(newTable)
 
  --mist.debug.dumpDBs()
 --end
 return
end

 

Sven

[TABLE][sIGPIC][/sIGPIC]|

[/TABLE]

Link to comment
Share on other sites

Hi Sven,

 

Now that I know others have that problem too, I will also try to investigate further ...

 

Jippie, found it... Find the following code within MIST 3.3, starting line 4214 ending 4255.

 

if eventData:getCategory() == 1 then -- normal groups
    local match = false
    if #groupsToAdd > 0 then -- if groups are expected
     for groupId, groupData in pairs(groupsToAdd) do -- iterate through known groups to add
      if (type(groupData) == 'string' and groupData == eventData:getGroup():getName()) or (type(groupData) == 'table' and groupData.name == eventData:getGroup():getName()) then -- already added, do nothing
       match = true
       break
      end
     end
     if match == false then -- hasn't been added
      groupsToAdd[#groupsToAdd + 1] = Unit.getByName(eventData):getGroup():getName()
     end
    else -- no groups added by mist
     groupsToAdd[#groupsToAdd + 1] = Unit.getByName(eventData):getGroup():getName()
    end

The bug is with the code:

groupsToAdd[#groupsToAdd + 1] = Unit.getByName(eventData):getGroup():getName()

this needs to be changed to:

groupsToAdd[#groupsToAdd + 1] = Unit.getByName(eventData:getName()):getGroup():getName()

 

hope it helps, and try if it works.

 

Also, you may want to add in the function getGroupData the line highlighted in RED, or dynAdd will reject the group structure...

 

mist.getGroupData = function(gpName)
for groupName, groupData in pairs(mist.DBs.groupsByName) do
 if string.lower(groupName) == string.lower(gpName) then
  local newData = {}
  newData.hidden = false -- maybe add this to DBs
  newData.groupId = groupData.groupId
  newData.groupName = groupName
  newData.category = groupData.category
  [color=red][b]newData.country = groupData.country[/b][/color]
  newData.units = {}
  newData.task = groupData.task
   for unitNum, unitData in pairs(groupData.units) do
   newData.units[unitNum] = {}
   
   newData.units[unitNum]["unitId"] = unitData.unitId
   --newData.units[unitNum]['point'] = unitData.point
   newData.units[unitNum]['x'] = unitData.point.x
   newData.units[unitNum]['y'] = unitData.point.y
   newData.units[unitNum]['alt'] = unitData.alt
   newData.units[unitNum]['alt_type'] = unitData.alt_type
   newData.units[unitNum]['speed'] = unitData.speed
   newData.units[unitNum]["type"] = unitData.type
   newData.units[unitNum]["skill"] = unitData.skill
   newData.units[unitNum]["unitName"] = unitData.unitName
   newData.units[unitNum]["heading"] = unitData.heading -- added to DBs
   newData.units[unitNum]["playerCanDrive"] = unitData.playerCanDrive -- added to DBs
   
   
   if newData.category == 'plane' or newData.category == 'helicopter' then
    newData.units[unitNum]["payload"] = mist.getPayload(unitData.unitName)
    newData.units[unitNum]['livery_id'] = unitData.livery_id
   end
  end
  return newData 
 end
end
end

  • Like 1

[TABLE][sIGPIC][/sIGPIC]|

[/TABLE]

Link to comment
Share on other sites

Jippie, found it... Find the following code within MIST 3.3, starting line 4214 ending 4255.

 

if eventData:getCategory() == 1 then -- normal groups
    local match = false
    if #groupsToAdd > 0 then -- if groups are expected
     for groupId, groupData in pairs(groupsToAdd) do -- iterate through known groups to add
      if (type(groupData) == 'string' and groupData == eventData:getGroup():getName()) or (type(groupData) == 'table' and groupData.name == eventData:getGroup():getName()) then -- already added, do nothing
       match = true
       break
      end
     end
     if match == false then -- hasn't been added
      groupsToAdd[#groupsToAdd + 1] = Unit.getByName(eventData):getGroup():getName()
     end
    else -- no groups added by mist
     groupsToAdd[#groupsToAdd + 1] = Unit.getByName(eventData):getGroup():getName()
    end

The bug is with the code:

groupsToAdd[#groupsToAdd + 1] = Unit.getByName(eventData):getGroup():getName()

this needs to be changed to:

groupsToAdd[#groupsToAdd + 1] = Unit.getByName(eventData:getName()):getGroup():getName()

 

hope it helps, and try if it works.

 

Also, you may want to add in the function getGroupData the line highlighted in RED, or dynAdd will reject the group structure...

 

mist.getGroupData = function(gpName)
for groupName, groupData in pairs(mist.DBs.groupsByName) do
 if string.lower(groupName) == string.lower(gpName) then
  local newData = {}
  newData.hidden = false -- maybe add this to DBs
  newData.groupId = groupData.groupId
  newData.groupName = groupName
  newData.category = groupData.category
  [color=red][b]newData.country = groupData.country[/b][/color]
  newData.units = {}
  newData.task = groupData.task
   for unitNum, unitData in pairs(groupData.units) do
   newData.units[unitNum] = {}
   
   newData.units[unitNum]["unitId"] = unitData.unitId
   --newData.units[unitNum]['point'] = unitData.point
   newData.units[unitNum]['x'] = unitData.point.x
   newData.units[unitNum]['y'] = unitData.point.y
   newData.units[unitNum]['alt'] = unitData.alt
   newData.units[unitNum]['alt_type'] = unitData.alt_type
   newData.units[unitNum]['speed'] = unitData.speed
   newData.units[unitNum]["type"] = unitData.type
   newData.units[unitNum]["skill"] = unitData.skill
   newData.units[unitNum]["unitName"] = unitData.unitName
   newData.units[unitNum]["heading"] = unitData.heading -- added to DBs
   newData.units[unitNum]["playerCanDrive"] = unitData.playerCanDrive -- added to DBs
   
   
   if newData.category == 'plane' or newData.category == 'helicopter' then
    newData.units[unitNum]["payload"] = mist.getPayload(unitData.unitName)
    newData.units[unitNum]['livery_id'] = unitData.livery_id
   end
  end
  return newData 
 end
end
end

 

Hi Sven,

 

I am sad to say making your corrections did not solve the problem I am having. Some groups still don't make it into the databases. Looking at the correction you mention, do I have to replace "eventData:getGroup():getName()" everywhere by "(eventData:getName()):getGroup():getName()"? This code appears also in several lines you have not indicated to require that change... Haven't tried that yet. Have I interpreted the Grimes' code correctly that eventData contains the initiator unit of a spawning event. If so, it should not be required to get its name before calling getGroup(), correct? In your opinion, what type of object is eventData?

 

Looking at Grimes' code I start to suspect that some spawning events do not trigger a "world.event.S_EVENT_BIRTH". What do you think of this?

[sIGPIC][/sIGPIC]

 

Intel Core I7 4820K @4.3 GHz, Asus P9X79 motherboard, 16 GB RAM @ 933 MHz, NVidia GTX 1070 with 8 GB VRAM, Windows 10 Pro

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
×
×
  • Create New...