Results 1 to 4 of 4

Thread: Return nationality in script - GB, DE, IT ?

  1. #1
    Supporting Member
    Join Date
    Sep 2019
    Location
    Yorkshire
    Posts
    138
    Post Thanks / Like
    Total Downloaded
    1.39 GB

    Return nationality in script - GB, DE, IT ?

    Hi,

    Is there a way to find the player nationality for use in a script, like you can the army side?

    player.Army() = 1

    i.e.

    player.Nation() = GB, DE or IT ?


    Also, is it posible to return the mission map e.g. MAP Land$English_Channel_1940_Autumn

    Or maybe read it from the mission file?

    I've searched but found no examples.

    Thanks

    M
    Last edited by Marcost; Nov-14-2020 at 09:32.

  2. #2
    Supporting Member
    Join Date
    Sep 2019
    Location
    Yorkshire
    Posts
    138
    Post Thanks / Like
    Total Downloaded
    1.39 GB

    Re: Return nationality in script - GB, DE, IT ?

    Ok I worked out a (clunky) way to do it, thanks to a script I found here from Salmo that allows reading of the mission.mis file. Serves my purpose anyway:

    Code:
    using System;
    using System.IO;
    using System.Media;
    using maddox.game;
    using maddox.game.world;
    using part;
    using System.Collections.Generic;
    using maddox.GP;
    
    
    public class Mission : AMission
    {
    
        private static string mydocpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
        private static string missionfile = mydocpath + @"\1C SoftClub\il-2 sturmovik cliffs of dover\missions\single\Dover_attack MC\Dover Attack.mis";   
    
    
        public override void OnBattleStarted()
        {
            
     	string theatre = null;
    	string nationality = null;
    
    	nationality = Nationality(missionfile);
    	theatre = Theatre(missionfile);
    	GamePlay.gpHUDLogCenter("  You are flying for  "+nationality + "  In the  "+theatre +"  Theatre");
    
        }
    
    
        public string Nationality(string missionfile)
       {
            string line = null;
    	string nationality = "none";
       try
            {
                System.IO.StreamReader file = new System.IO.StreamReader(missionfile);
                while ((line = file.ReadLine()) != null)
                {
    
    
                   if (line.TrimStart().StartsWith("player"))
                    {
                        
    			line = line.Trim(); 
    		    	if (line.Contains("_RAF_")) 
    				nationality = "RAF";
    		    	if (line.Contains("_LW_")) 
    				nationality = "LW";
    		    	if (line.Contains("_RA_")) 
    				nationality = "RA";
    		    	if (line.Contains("gb")) 
    				nationality = "RAF";
    		    	if (line.Contains("_AA_")) 
    				nationality = "FR";
    
    		return nationality;
    
                    }
                }
    
                file.Close(); 
    
                return null;
            }
            catch { return null; }
    
       }
        public string Theatre(string missionfile)
       {
            string line = null;
    	string theatre = "none";
       try
            {
                System.IO.StreamReader file = new System.IO.StreamReader(missionfile);
                while ((line = file.ReadLine()) != null)
                {
    
    
                   if (line.TrimStart().StartsWith("MAP"))
                    {
                        
    			line = line.Trim(); 
    		    	if (line.Contains("Channel")) 
    			   { 
    			    if (line.Contains("Autumn")) 
    				theatre = "Channel Autumn";
    			    else
    
    			    if (line.Contains("Winter")) 
    				theatre = "Channel Winter";
    			    else
    				theatre = "Channel Summer";
    			   }
    
    			else
    				theatre = "Desert";
    
    		return theatre;
    
                    }
                }
    
                file.Close(); 
    
                return null;
            }
            catch { return null; }
    
       }
    }

  3. Likes 1lokos liked this post
  4. #3
    ATAG Member ATAG_Oskar's Avatar
    Join Date
    Nov 2017
    Location
    Canada
    Posts
    986
    Post Thanks / Like
    Total Downloaded
    908.31 MB

    Re: Return nationality in script - GB, DE, IT ?

    Here is another way.

    Code:
    	public override void OnActorDead(int missionNumber, string shortName, AiActor actor, List<DamagerScore> damages) 
    	{
    
    		if (actor is AiAircraft) { 
    			string name = actor.Name();
    			if (name.Contains("_LW_")) {
    				GamePlay.gpLogServer(null, "Luftwaffe aircraft destroyed", new object[] { });
    				return;
    			}
    			if (name.Contains("_RA_")) {
    				GamePlay.gpLogServer(null, "Regia Aeronautica aircraft destroyed", new object[] { });
    				return;
    			}
    		}
    	}

  5. #4
    Supporting Member
    Join Date
    Sep 2019
    Location
    Yorkshire
    Posts
    138
    Post Thanks / Like
    Total Downloaded
    1.39 GB

    Re: Return nationality in script - GB, DE, IT ?

    Much better, means I don't have to declare the path to the missionfile and therefore the script is more portable.


    Many thanks Oskar!

    Regards,

    M

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •