Jump to content

Recommended Posts

Posted (edited)

local unit = Unit.getByName('Pilot #1')

local unitCountry= nil

if unit ~= nil then

unitCountry = unit:getCountry()

trigger.action.outText(unitCountry, 20)

end

Edited by spinter

====VIAF====

Spinter 155° "Pantere Nere"

 

TsSimComms

 

My Site aiupgrade.net

 

 

 

Posted

Yes, you could iterate through the env.mission table to find it. Take a look at the Mist code to see how it's done.

Posted
-- returns name of unit's country if found or nil if not found
function getCountry(unitName)
   local i,j,k
   if env.mission.coalition then
       for coa,coaTable in pairs(env.mission.coalition) do
           if type(coaTable) == 'table' and coaTable.country then
               for i=1,#coaTable.country do
                   local country = coaTable.country[i]
                   for uType,uTable in pairs(country) do
                       if uType == 'helicopter' or uType == 'ship' or uType == 'vehicle' or uType == 'plane' then
                           if type(uTable)=='table' and uTable.group then
                               for j=1,#uTable.group do
                                   local group = uTable.group[j]
                                   if group.units then
                                       for k=1,#group.units do
                                           local unit = group.units[k]
                                           if unit.name and unit.name == unitName then
                                               return country.name
                                           end
                                       end
                                   end
                               end
                           end
                       end
                   end
               end
           end
       end
   end
   return nil
end

Posted
thank you

I would like to know if I can use this function in my script without using mist?

Spinter, I saw your question in the other forum topic but I will answer it here.

 

Yes, feel free to use the function in your scripts and to modify it however you want to. Mist does not need to be loaded.

Posted

If using a group name instead of a unit name, I would change your modification slightly:

[font=Courier New]function getCountry(groupName)
   local i,j,k
   if env.mission.coalition then
       for coa,coaTable in pairs(env.mission.coalition) do
           if type(coaTable) == 'table' and coaTable.country then
               for i=1,#coaTable.country do
                   local country = coaTable.country[i]
                   for uType,uTable in pairs(country) do
                       if uType == 'helicopter' or uType == 'ship' or uType == 'vehicle' or uType == 'plane' then
                           if type(uTable)=='table' and uTable.group then
                               for j=1,#uTable.group do
                                   local group = uTable.group[j]
[color=Blue]                                    if group and group.name == groupName then
                                        return country.name
                                   end
[/color][color=Red]--                                    if group.units then
--                                        for k=1,#group.units do
--                                            local unit = group.units[k]
--                                            -- if unit.name and unit.name == groupName then
--                                                -- return group.name--country.name
--                                            -- end
--            if group.name and group.name == groupName then
--                                                return country.name
--                                             end
--                                        end
--                                    end
[/color]                                end
                           end
                       end
                   end
               end
           end
       end
   end
   return nil
end[/font]

Posted
Spinter, I saw your question in the other forum topic but I will answer it here.

 

Yes, feel free to use the function in your scripts and to modify it however you want to. Mist does not need to be loaded.

 

Thank you you are very kind!

====VIAF====

Spinter 155° "Pantere Nere"

 

TsSimComms

 

My Site aiupgrade.net

 

 

 

Posted
can you write a script/formula what we can use to add more countries via mods folder ?

 

Do you mean add countries not currently available in DCS? If so, I'm sure somebody has the knowledge to do it but I'm sorry to say I don't. IIIRC, I think someone has actually done that (in a previous version of DCS). I can't remember any specifics. This thread might point you in the right direction:

http://forums.eagle.ru/showthread.php?t=54015&highlight=add+country .

Posted (edited)
Do you mean add countries not currently available in DCS? If so, I'm sure somebody has the knowledge to do it but I'm sorry to say I don't. IIIRC, I think someone has actually done that (in a previous version of DCS). I can't remember any specifics. This thread might point you in the right direction:

http://forums.eagle.ru/showthread.php?t=54015&highlight=add+country .

 

thanks, i know that mods but that was for fc2

afaik we needed to edit many lua files in scripts/database folder but as you know if we will able to add countries in mods folder then we wont need too edit existing lua files in database folder - which will be overwritten all the time when we run an update

 

of course it's possible to add more countries in database folder afaik but i dont like that way :) however with using jsgme it is not a difficult activity

 

another old topic by Michelange:

http://forums.eagle.ru/showthread.php?t=93205

^ afaik that was for fc3-dcsw but i dont know it's still working with current version (1.2.8.) or not :dunno:

Edited by NRG-Vampire

sign-pic4.jpg

  • Recently Browsing   0 members

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