Results 1 to 12 of 12

Thread: Script for grabbing NAME of an AI(destroyed)

  1. #1
    Manual Creation Group fenbeiduo's Avatar
    Join Date
    May 2013
    Posts
    70
    Post Thanks / Like
    Total Downloaded
    282.61 MB

    Script for grabbing TYPE of an AI(destroyed)

    Thanks to Oskar who helped me out of it

    Code:
    	public override void OnActorDead(int missionNumber, string shortName, AiActor actor, List<DamagerScore> initiatorList)
    	{
    		if (actor is AiAircraft)
    		{
    			int order;
    			string type;
    			string _type = ((AiAircraft)actor).InternalTypeName();
    			order = _type.IndexOf(".");
                            type = _type.Remove(0, order + 1);
    			GamePlay.gpLogServer(type);		
    		}
    	}
    Original code and question:
    Spoiler: 


    I was trying this :
    Code:
    using System.Collections.Generic;
    using maddox.game;
    using maddox.game.world;
    using maddox.GP;
    
    public class Mission : AMission
    {
        public override void OnBattleStarted()
        {
    		base.OnBattleStarted();		
    		GamePlay.gpHUDLogCenter("runs");	
        }
    
        public override void OnActorDead(int missionNumber, string shortName, AiActor actor, List<DamagerScore> initiatorList)
        {
    		base.OnActorDead(missionNumber, shortName, actor, damages);
    		
    		if (actor is AiAircraft)
    		{
    			GetAircraftType (aircraft);
    		}
        }
    
        public string GetAircraftType (AiAircraft aircraft)    //*This part was written by Salmo
        {   // returns the type of the specified aircraft
            string result = null;                                        //Why give it a '= null'?
            if (aircraft != null)
            {
                string type = aircraft.InternalTypeName(); // eg type = "bob:Aircraft.Bf-109E-3"
                //string[] part = type.Trim().Split('.');
    	    string[] part = type.Split('\\.', 2);			//Tried syntax above with negative result, so I made changes
                result = part[1];  // get the part after the "." in the type string
            }
            return result;
        }
    }
    I've tried many times, took me hours to search and modify the code. But it is still invalid to the game. (no UHD msg "runs" at beginning)
    Ask for help.


    Last edited by fenbeiduo; Nov-29-2020 at 08:55.

  2. #2
    ATAG Member ATAG_Oskar's Avatar
    Join Date
    Nov 2017
    Location
    Canada
    Posts
    986
    Post Thanks / Like
    Total Downloaded
    908.31 MB

    Re: Script for grabbing NAME of an AI(destroyed)

    How about this?

    Code:
    using System;
    using System.Collections.Generic;
    using maddox.game;
    using maddox.game.world;
    using maddox.GP;
    
    public class Mission : AMission
    {
    
        public override void OnBattleStarted()
        {
    		GamePlay.gpHUDLogCenter("runs");	
        }
    
    
        public override void OnActorDead(int missionNumber, string shortName, AiActor actor, List<DamagerScore> initiatorList)
        {
    		if (actor is AiAircraft)
    		{
    			string type = ((AiAircraft)actor).InternalTypeName();
    	        GamePlay.gpLogServer(type.Substring(type.IndexOf(".", 0, 0)));
    		}
    	}
    
    }

  3. Likes fenbeiduo liked this post
  4. #3
    Manual Creation Group fenbeiduo's Avatar
    Join Date
    May 2013
    Posts
    70
    Post Thanks / Like
    Total Downloaded
    282.61 MB

    Re: Script for grabbing NAME of an AI(destroyed)

    Thanks for the help!

    Quote Originally Posted by ATAG_Oskar View Post
    How about this?
    [CODE]...

    After some testing it works (I have to change some places)

    I will paste the new code to #1

    Thanks again Oskar

  5. #4
    Manual Creation Group fenbeiduo's Avatar
    Join Date
    May 2013
    Posts
    70
    Post Thanks / Like
    Total Downloaded
    282.61 MB

    Re: Script for grabbing NAME of an AI(destroyed)

    Processing, a further step - To write the 'type' into a txt file.
    Also tried many times, fail to generate txt file...
    And even creat a txt myself, the game does not write a word in it ...oTZ

    (but HUD msg shows 'runs' which indicates script was somehow 'accepted' by game)
    Asking for help !

    I've highlighted added lines:
    Code:
    using System;
    using System.IO;
    using System.Collections;
    using System.Collections.Generic;
    using maddox.game;
    using maddox.game.world;
    using maddox.GP;
    
    public class Mission : AMission
    {	
    	string typelog = @"missions\Single\test\test.txt";  //fail to generate
    	
    	string type;
    	
    	int casualty = 0;  
    	
    	public override void OnBattleStarted()	
    	{
    		base.OnBattleStarted();	
                    MissionNumberListener = -1;
    		GamePlay.gpHUDLogCenter("runs");	
    	}
    	
    	public override void OnActorDead(int missionNumber, string shortName, AiActor actor, List<DamagerScore> initiatorList)
    	{
    		if (actor is AiAircraft)
    		{
    			casualty++;
    			int order;
    			string _type = ((AiAircraft)actor).InternalTypeName();
    			order = _type.IndexOf(".");
                            type = _type.Remove(0, order + 1);
    			GamePlay.gpLogServer(type);	//type name shows every time
    			
    		}
    	}
    
    	private void writetype(string type)
    	{
    		using (StreamWriter sw = new StreamWriter(typelog))
    		{
    			if (casualty > 0)  //to trigger the 'writting'.  I know it maybe not necessary
    			sw.WriteLine(type);
    			sw.Close();
    		}
    	}
    }
    Last edited by fenbeiduo; Nov-29-2020 at 16:15.

  6. #5
    ATAG Member ATAG_Oskar's Avatar
    Join Date
    Nov 2017
    Location
    Canada
    Posts
    986
    Post Thanks / Like
    Total Downloaded
    908.31 MB

    Re: Script for grabbing NAME of an AI(destroyed)

    Code:
    	public override void OnActorDead(int missionNumber, string shortName, AiActor actor, List<DamagerScore> initiatorList)
    	{
    		if (actor is AiAircraft)
    		{
    			casualty++;
    			int order;
    			string _type = ((AiAircraft)actor).InternalTypeName();
    			order = _type.IndexOf(".");
                            type = _type.Remove(0, order + 1);
    			GamePlay.gpLogServer(type);	//type name shows every time
    			writetype(type);
    		}
    	}

  7. Likes fenbeiduo liked this post
  8. #6
    Manual Creation Group fenbeiduo's Avatar
    Join Date
    May 2013
    Posts
    70
    Post Thanks / Like
    Total Downloaded
    282.61 MB

    Re: Script for grabbing NAME of an AI(destroyed)

    Quote Originally Posted by ATAG_Oskar View Post
    Code:
    ...
    		if (actor is AiAircraft)
    		{
    			casualty++;
    			int order;
    			string _type = ((AiAircraft)actor).InternalTypeName();
    			order = _type.IndexOf(".");
                            type = _type.Remove(0, order + 1);
    			GamePlay.gpLogServer(type);	//type name shows every time
    			writetype(type);
    		}
    ...
    unfortunately, I've tried to
    add '//-$debug' to the top.
    remove those 'casualty's
    change 'writetype(type); and private void writetype(string type)' to other parameters
    change 'string typelog = @"missions\Single\test\test.txt";' to private static string

    all-negative

  9. #7
    ATAG Member ATAG_Oskar's Avatar
    Join Date
    Nov 2017
    Location
    Canada
    Posts
    986
    Post Thanks / Like
    Total Downloaded
    908.31 MB

    Re: Script for grabbing NAME of an AI(destroyed)

    This works. You will want to set the MISSION_DATA_PATH.

    Code:
    using System;
    using System.IO;
    using System.Collections;
    using System.Collections.Generic;
    using maddox.game;
    using maddox.game.world;
    using maddox.GP;
    
    public class Mission : AMission
    {	
        static string USER_DOC_PATH = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
        static string MISSION_PATH = USER_DOC_PATH + "/1C SoftClub/il-2 sturmovik cliffs of dover/missions/Single/";
        static string MISSION_DATA_PATH = MISSION_PATH + "dev/TF5/";
        static string TEST_FILENAME = MISSION_DATA_PATH + "test.txt";
    
    	
    	public override void OnBattleStarted()	
    	{
                    MissionNumberListener = -1;
    		GamePlay.gpHUDLogCenter("runs");	
    	}
    	
    	public override void OnActorDead(int missionNumber, string shortName, AiActor actor, List<DamagerScore> initiatorList)
    	{
    		if (actor is AiAircraft)
    		{
    			string type = ((AiAircraft)actor).InternalTypeName();
    			int order = type.IndexOf(".");
                            type = type.Remove(0, order + 1);
    			GamePlay.gpLogServer(type);	//type name shows every time
    			File.AppendAllText(TEST_FILENAME, type + Environment.NewLine);
    		}
    	}
    }

  10. Likes 1lokos, fenbeiduo liked this post
  11. #8
    Manual Creation Group fenbeiduo's Avatar
    Join Date
    May 2013
    Posts
    70
    Post Thanks / Like
    Total Downloaded
    282.61 MB

    Wink Re: Script for grabbing NAME of an AI(destroyed)

    Muahhh ! @Oskar

    Quote Originally Posted by ATAG_Oskar View Post
    This works. ...
    Code:
    ...
    			string type = ((AiAircraft)actor).InternalTypeName();
    			int order = type.IndexOf(".");
                            type = type.Remove(0, order + 1);
    			File.AppendAllText(TEST_FILENAME, type + Environment.NewLine);
    ...


    I 've also tried these to replace: (but I don't know why they do not work)
    1.
    Code:
    File.AppendAllLines(TEST_FILENAME, type);
    2.
    Code:
    using (StreamWriter sw = new StreamWriter(TEST_FILENAME, true));
    			{
    				sw.WriteLine(type);
    				sw.Close();
    			}
    Did I write something wrong to the script?

  12. #9
    ATAG Member ATAG_Oskar's Avatar
    Join Date
    Nov 2017
    Location
    Canada
    Posts
    986
    Post Thanks / Like
    Total Downloaded
    908.31 MB

    Re: Script for grabbing NAME of an AI(destroyed)

    1. Check this URL for info in the File object. https://docs.microsoft.com/en-us/dot...e?view=net-5.0

    Also, read the error message you get when you try to compile. This will tell you why it is failing.

    2. Not sure, I used the easiest method.

  13. #10
    Manual Creation Group fenbeiduo's Avatar
    Join Date
    May 2013
    Posts
    70
    Post Thanks / Like
    Total Downloaded
    282.61 MB

    Re: Script for grabbing NAME of an AI(destroyed)

    Quote Originally Posted by ATAG_Oskar View Post
    1. Check this URL for info in the File object. https://docs.microsoft.com/en-us/dot...e?view=net-5.0

    Also, read the error message you get when you try to compile. This will tell you why it is failing.

    2. Not sure, I used the easiest method.
    Thanks, I'm reading these pages

    And unfortunately, my FMB always return □□□□□□□□□ so I can't read it...

    Anyway many thanks, your are one of the best

  14. #11
    Ace 1lokos's Avatar
    Join Date
    Jan 2012
    Posts
    5,323
    Post Thanks / Like
    Total Downloaded
    1.04 GB

    Re: Script for grabbing NAME of an AI(destroyed)

    Use the Console for debug, the errors is show in the same way that "Debug" in FMB, they are write too in the "Log.txt" file - need enable in Conf.ini, if you leave this file open in Notepad++ will be updated when you Alt+Tab. In Notepad 'Vanilla" need re-open.

    I use Notepad++ and game as debug, make changes in the script in Notepad++, and restart the mission, the console show errors, and missions load more fast than though FMB. Although I don't have issues for run missions from inside FMB, like some people report, but the combination of Notepad++ and game is more practical.
    Last edited by 1lokos; Nov-30-2020 at 13:09.

  15. Likes ATAG_Oskar, fenbeiduo liked this post
  16. #12
    ATAG Member ATAG_Oskar's Avatar
    Join Date
    Nov 2017
    Location
    Canada
    Posts
    986
    Post Thanks / Like
    Total Downloaded
    908.31 MB

    Re: Script for grabbing NAME of an AI(destroyed)

    Remember that there are two kinds of errors. There are compile time errors, your script is not valid C# code for some reason. These are shown in the FMB and also sent to the log file. It is faster to check the FMB when you make script changes in Notepad++ rather than having to start the mission and check the log file.

    The other kind of errors are runtime errors, mostly logical errors in your script. These are written to the log file as they happen.

  17. Likes fenbeiduo liked this post

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
  •