Jump to content

Password protected .miz files (one password for Red, one for Blue)


Recommended Posts

Posted

Hi there,

love your work!  Could we please be able to hide, then password protect the units we have located in a map?  The we send the mission file to our opposition, they do the same, then we can fly against each other, and neither of us knows where the others units are.

Thanks for everything you've done so far.

'52

Posted

That sounds a lot like a technological attempt to solve a social problem. If you can't trust the people you are playing with not to cheat, don't play with them.  Problem solved.

  • Like 1
Posted
21 hours ago, Gunslinger52 said:

Hi there,

love your work!  Could we please be able to hide, then password protect the units we have located in a map?  The we send the mission file to our opposition, they do the same, then we can fly against each other, and neither of us knows where the others units are.

Thanks for everything you've done so far.

'52

Is this the same request as the one asked 4 weeks ago?

 

 

If so - you may have missed the replies after your comment, but there are already a few solutions to what you need that might be worth you checking out, including importing files as templates or scripts. 

Posted

Hi Dangerzone, 

I did miss them, thanks.  Did you try out your idea of importing templates?

Cheers

'52

Posted (edited)
28 minutes ago, Gunslinger52 said:

Hi Dangerzone, 

I did miss them, thanks.  Did you try out your idea of importing templates?

Cheers

'52

If you mean using the script to import templates, then yes. The script that was provided in that post does work - although you may want to strip the UnitID out of the table before spawning. I use the script quite a bit to inject various scenario's into running missions in real time. 

If you mean to 'import templates' using the mission editor - yes, I have done that too. (Saved an existing .miz file as a tempalte in the mission editor, and then opening up another and importing the saved 'tempalte'.). I tend to just call it 'Temp' or similar and overwrite the previous one saved in the mission editor so I don't get a huge list of templates I'm not interested in keeping for once-off's.  What you could do is create the original mission (with neither sides units) as the base mission. When saving it - zoom right in to the top right corner of the map when saving (and have the other designers do the same), so then when you go to import the other missions - the person that's doing the compilation of all the missions into a single mission doesn't get to 'see' anything else accidently. Obviously there's a bit of an honesty system here - but you're only talking about one person who's merging the files into a single mission at this point. 

Alternatively - the script to import the templates will work as well - saving anyone having to even go in or use the mission editor. Obviously though it's lua scripting, so requires a bit of knowledge (including desanitizing the server so it has access to "require" as well as the LFS/OS stuff).  The benefit with this though is that you don't have to merge stuff. Once you set up your base mission you can just update the .miz files (copy them over) and have them re-load the new ones in if this is something you will be repeating on a weekly basis making short work of it once it's setup.

So I know both solutions will work as I've used both. It's just a matter of whether you want to mess around with scripting to import/spawn the stuff on the fly in the mission editor, or whether you want to just do it manually prior using what DCS already has to offer. 

Edited by Dangerzone
Posted

Hi Dangerzone, 

really appreciate the detailed answer.  I'd be keen to learn a bit of Lua scripting.  Being new though (even at Forums) 🙂 I can't seem to find the post with the script in it for loading in templates.  Would you mind posting it in here please?

 

Thanks again.

'52

Posted
On 6/3/2023 at 12:08 PM, Gunslinger52 said:

Hi Dangerzone, 

really appreciate the detailed answer.  I'd be keen to learn a bit of Lua scripting.  Being new though (even at Forums) 🙂 I can't seem to find the post with the script in it for loading in templates.  Would you mind posting it in here please?

 

Thanks again.

'52

Hi GS.

 

Sure thing - see below.

Spoiler


TempMizPath = 'C:\\temp\\dcstemp'
missionpath = 'c:\\temp'

function file_exists(file)
  if io then
    local f=io.open(file, "r")
    if f~=nil then
      io.close(f)
      return true
    else
      return false
    end
  else
    return nil
  end
end

function tablespawn(tbl, _country, _cat)
    for k, v in pairs(tbl) do
        local _subcat = _cat
        -- Detects if type is train - for some reason fails to still spawn in trains!
        if v.units ~= nil then
           if v.units[1] ~= nil then
               if v.units[1].type == "Train" then
                   _subcat = Group.Category.TRAIN
               end
           end
       end

       if _cat == Group.Category.STRUCTURE then
           coalition.addStaticObject(_country, v)
       else
           coalition.addGroup(_country, _subcat, v)
       end
    end
end

function multitablespawn(tbl, _country)
    for i = 1, #tbl do
        if tbl[i].helicopter ~= nil then
            if tbl[i].helicopter.group ~= nil then
                tablespawn(tbl[i].helicopter.group, _country, Group.Category.HELICOPTER)
            end
        end
        if tbl[i].vehicle ~= nil then
            if tbl[i].vehicle.group ~= nil then

                local istrain = false

                local grps = tbl[i].vehicle.group
                for j = 1, #grps do

                if tbl[i].vehicle.group[j].units ~= nil then
                    if #tbl[i].vehicle.group[j].units > 0 then
                        local grpunits  = tbl[i].vehicle.group[j].units
                        for k = 1, #grpunits do 

                        if tbl[i].vehicle.group[1].units[1].type == "Train" then
                            istrain = true
                        end
                        end
                    end
                end
            end

                if istrain then
                    tablespawn(tbl[i].vehicle.group, _country, Group.Category.TRAIN)
                else
                    tablespawn(tbl[i].vehicle.group, _country, Group.Category.GROUND)
                end
            end
        end
        if tbl[i].plane ~= nil then
            if tbl[i].plane.group ~= nil then
                tablespawn(tbl[i].plane.group, _country, Group.Category.AIRPLANE)
            end
        end
        if tbl[i].ship ~= nil then
            if tbl[i].ship.group ~= nil then
                tablespawn(tbl[i].ship.group, _country, Group.Category.SHIP)
            end
        end
        
        if tbl[i].static ~= nil then
            if tbl[i].static.group ~= nil then
                local grps = tbl[i].static.group
                for j = 1, #grps do
                   if grps[i].units ~= nil then 
                         local grpunits = grps[j].units
                         tablespawn(grpunits, _country, Group.Category.STRUCTURE)
                   end 
                end   
            end    
        end    
    end
end


function missionspawn(_missionfile, _coalition)
   mission = nil 

   local minizip                = require("minizip")  -- Note - _G['require'] = nil must be DESANITISED in missionscripts.lua for this to work!!!
   local TemplateFile = missionpath..'\\'.._missionfile
   lfs.mkdir(TempMizPath)    
   if file_exists(TempMizPath..'\\mission') then
    os.remove(TempMizPath..'\\mission')    
   end
   
   local zipFile = minizip.unzOpen(TemplateFile,TempMizPath)

   while true do 
      local filename = zipFile:unzGetCurrentFileName()
      if filename == 'mission' then
        local fullpath = TempMizPath..'\\'..filename
        zipFile:unzUnpackCurrentFile(fullpath) 
      end

       if not zipFile:unzGoToNextFile() then 
         break
       end  
   end

   dofile(TempMizPath..'/mission')

   if mission == nil then
     MESSAGE:New("Admin Error: No misison template", 15):ToAll()
   else
     local tbl = ''
     local ctrl = ''

    if _coalition == nil then
        missionspawn(_missionfile, coalition.side.RED)
        missionspawn(_missionfile, coalition.side.BLUE)
        missionspawn(_missionfile, coalition.side.NEUTRAL)
        return
    end

     if _coalition == coalition.side.RED then
        tbl = mission.coalition.red.country  
        ctry = country.id.CJTF_RED
     end
     if _coalition == coalition.side.BLUE then
          tbl = mission.coalition.blue.country  
          ctry = country.id.CJTF_BLUE
     end
     if _coalition == coalition.side.NEUTRAL then
         tbl = mission.coalition.neutrals.country  
         ctry = country.id.UN_PEACEKEEPERS
     end

     if tbl ~= nil then
         multitablespawn(tbl, ctry)
     end
  end
endfunction tablespawn(tbl, _country, _cat)
    for k, v in pairs(tbl) do
        local _subcat = _cat
        -- Detects if type is train - for some reason fails to still spawn in trains!
        if v.units ~= nil then
           if v.units[1] ~= nil then
               if v.units[1].type == "Train" then
                   _subcat = Group.Category.TRAIN
               end
           end
       end

       if _cat == Group.Category.STRUCTURE then
           coalition.addStaticObject(_country, v)
       else
           coalition.addGroup(_country, _subcat, v)
       end
    end
end

function multitablespawn(tbl, _country)
    for i = 1, #tbl do
        if tbl[i].helicopter ~= nil then
            if tbl[i].helicopter.group ~= nil then
                tablespawn(tbl[i].helicopter.group, _country, Group.Category.HELICOPTER)
            end
        end
        if tbl[i].vehicle ~= nil then
            if tbl[i].vehicle.group ~= nil then

                local istrain = false

                local grps = tbl[i].vehicle.group
                for j = 1, #grps do

                if tbl[i].vehicle.group[j].units ~= nil then
                    if #tbl[i].vehicle.group[j].units > 0 then
                        local grpunits  = tbl[i].vehicle.group[j].units
                        for k = 1, #grpunits do 

                        if tbl[i].vehicle.group[1].units[1].type == "Train" then
                            istrain = true
                        end
                        end
                    end
                end
            end

                if istrain then
                    tablespawn(tbl[i].vehicle.group, _country, Group.Category.TRAIN)
                else
                    tablespawn(tbl[i].vehicle.group, _country, Group.Category.GROUND)
                end
            end
        end
        if tbl[i].plane ~= nil then
            if tbl[i].plane.group ~= nil then
                tablespawn(tbl[i].plane.group, _country, Group.Category.AIRPLANE)
            end
        end
        if tbl[i].ship ~= nil then
            if tbl[i].ship.group ~= nil then
                tablespawn(tbl[i].ship.group, _country, Group.Category.SHIP)
            end
        end
        
        if tbl[i].static ~= nil then
            if tbl[i].static.group ~= nil then
                local grps = tbl[i].static.group
                for j = 1, #grps do
                   if grps[i].units ~= nil then 
                         local grpunits = grps[j].units
                         tablespawn(grpunits, _country, Group.Category.STRUCTURE)
                   end 
                end   
            end    
        end    
    end
end


function missionspawn(_missionfile, _coalition)
   mission = nil 

   local minizip                = require("minizip")  -- Note - _G['require'] = nil must be DESANITISED in missionscripts.lua for this to work!!!
   local TempMizPath = 'C:\\mymissionpath'
   local TemplateFile = missionpath.._missionfile
   lfs.mkdir(TempMizPath)    
   if file_exists(TempMizPath..'\\mission') then
    os.remove(TempMizPath..'\\mission')    
   end
   
   local zipFile = minizip.unzOpen(TemplateFile,TempMizPath)

   while true do 
      local filename = zipFile:unzGetCurrentFileName()
      if filename == 'mission' then
        local fullpath = TempMizPath..'\\'..filename
        zipFile:unzUnpackCurrentFile(fullpath) 
      end

       if not zipFile:unzGoToNextFile() then 
         break
       end  
   end

   dofile(TempMizPath..'/mission')

   if mission == nil then
     MESSAGE:New("Admin Error: No misison template", 15):ToAll()
   else
     local tbl = ''
     local ctrl = ''

    if _coalition == nil then
        missionspawn(_missionfile, coalition.side.RED)
        missionspawn(_missionfile, coalition.side.BLUE)
        missionspawn(_missionfile, coalition.side.NEUTRAL)
        return
    end

     if _coalition == coalition.side.RED then
        tbl = mission.coalition.red.country  
        ctry = country.id.CJTF_RED
     end
     if _coalition == coalition.side.BLUE then
          tbl = mission.coalition.blue.country  
          ctry = country.id.CJTF_BLUE
     end
     if _coalition == coalition.side.NEUTRAL then
         tbl = mission.coalition.neutrals.country  
         ctry = country.id.UN_PEACEKEEPERS
     end

     if tbl ~= nil then
         multitablespawn(tbl, ctry)
     end
  end
end

 

Posted

Fantastic.

Do you have a preferred scripting tool?  Or will just any text editor do?

 

Posted
9 minutes ago, Gunslinger52 said:

Fantastic.

Do you have a preferred scripting tool?  Or will just any text editor do?

 

I'm using Visual Studio myself for the .lua files. Not sure what others use. I'm probably not the best source of info for .lua stuff - I'm more of a hack when it comes to lua - I can find my way through it and get (some 😉) stuff to work. There's probably better ways of doing things than I am doing - but I share my (limited) knowledge where it's useful. 

Posted

Hi Dangerzone

I've found how to save a mission as a template, and got myself Visual Studio.  Done some very basic triggers with scripts.  

Are you saying that all I would need to do, is make a basic trigger, add your script in, and it should load any templates stored somewhere?

Thanks again,

'52

Posted
3 hours ago, Gunslinger52 said:

Hi Dangerzone

I've found how to save a mission as a template, and got myself Visual Studio.  Done some very basic triggers with scripts.  

Are you saying that all I would need to do, is make a basic trigger, add your script in, and it should load any templates stored somewhere?

Thanks again,

'52

You'll need to load in the script to 'load in the functions'. This won't actually load in the file - but like MOOSE it should give you the functions ready for use.

Then it's just a matter of calling...

missionspawn('c:\\mymissionfolder\mymissionfile.miz', 2)
missionspawn('c:\\mymissionfolder\anotherofmymissionfiles.miz', 2)

... I believe in order to load in your template. You can do multiple templates in a row no problems... The above shows 2 being loaded in.

I'm currently away on holidays so I'm going by memory at the moment. Just note - I think if you have 2 mission files that have the same group names you could run into issues, so make sure that your mission files have different names or one might 'overwrite' the other for the groups that have the same names if this makes sense.

Posted

Hi Dangerzone, 

hope your holiday went well.  So far I get the attached.  But there are things that I suspect I need to do 1st, one is the 2nd attachment, and the other is something you mentioned about "require" and Unit ID's.  At the moment, I am not trying to run it on a dedicated server, but is this required maybe?nullnull

Have a good week.

'52

image.png

image.png

  • 2 weeks later...
Posted
On 6/18/2023 at 8:43 AM, Gunslinger52 said:

Hi Dangerzone, 

hope your holiday went well.  So far I get the attached.  But there are things that I suspect I need to do 1st, one is the 2nd attachment, and the other is something you mentioned about "require" and Unit ID's.  At the moment, I am not trying to run it on a dedicated server, but is this required maybe?nullnull

Have a good week.

'52

image.png

image.png

Check out line 156. When I copied it back off the forum - it looked like the forum was broken:

endfunction tablespawn(tbl, _country, _cat)

put a carriage return between end and function and that should resolve the issue. (NOt sure why the carriage return isn't there in the post above - I'm guessing it's something to do with the forum).

Also, you will need to desanitise regardless of whether you're running on a server or not because the script requires DCS to write files to the hard drive in order to unzip and extract the required file/data from the .miz file. 

 

 

  • Recently Browsing   0 members

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