Results 1 to 12 of 12

Thread: Despawning Trains on Trigger

  1. #1
    Combat pilot
    Join Date
    Aug 2020
    Posts
    181
    Post Thanks / Like
    Total Downloaded
    121.31 MB

    Despawning Trains on Trigger

    I am trying to write a script to remove trains 30min after they arrived in the station on a trigger or destroy and remove. AiGroundGroupType.Train I found in the code, but I cannot get them off the map. Or a trigger for despawn in the future patch. OnAiActorCreated we can put a script in for destroy but this does not work on Trains. I have used all the destroy samples in the _all folders.


    PLS any help would be great!

    BlacKnight

  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: Despawning Trains on Trigger

    Can't you call the destroy() function?

  3. #3
    Combat pilot
    Join Date
    Oct 2021
    Posts
    113
    Post Thanks / Like
    Total Downloaded
    12.95 MB

    Re: Despawning Trains on Trigger

    Deleted by GANIX
    Last edited by GANIX; May-01-2023 at 08:09. Reason: Deleted by GANIX

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

    Re: Despawning Trains on Trigger

    The Train object has a list of Wagon objects. The Train is a ChiefGround object which has a destroy() function.

  5. Likes TWC_Flug liked this post
  6. #5
    Combat pilot
    Join Date
    Aug 2020
    Posts
    181
    Post Thanks / Like
    Total Downloaded
    121.31 MB

    Re: Despawning Trains on Trigger

    I will try both ways, I have tried the destroy many time and it might be how I am writing the code as an AiCart...

    Thanks guys!

  7. Likes GANIX liked this post
  8. #6
    ATAG Member ATAG_Oskar's Avatar
    Join Date
    Nov 2017
    Location
    Canada
    Posts
    986
    Post Thanks / Like
    Total Downloaded
    908.31 MB

    Re: Despawning Trains on Trigger

    Quote Originally Posted by BlacKnight View Post
    I will try both ways, I have tried the destroy many time and it might be how I am writing the code as an AiCart...

    Thanks guys!
    Try this:

    Code:
            List<AiGroundGroup> trains = new List<AiGroundGroup>();
            AiGroundGroup[] ggs = GamePlay.gpGroundGroups(1);
            foreach (AiGroundGroup ag in ggs)
            {
                if (ag.GroupType() == AiGroundGroupType.Train)
                {
                    trains.Add(ag);
                }
            }

    EDIT:

    Or to get Trains try this.

    Code:
            List<Train> trains = new List<Train>();
            AiGroundGroup[] ggs = GamePlay.gpGroundGroups(1);  // army number 1 is Britain
            foreach (AiGroundGroup ag in ggs)
            {
                if (ag.GroupType() == AiGroundGroupType.Train)
                {
                    trains.Add((Train)ag);
                }
            }
    Last edited by ATAG_Oskar; Mar-20-2023 at 15:48.

  9. #7
    Combat pilot
    Join Date
    Aug 2020
    Posts
    181
    Post Thanks / Like
    Total Downloaded
    121.31 MB

    Re: Despawning Trains on Trigger

    Ok Here is the Script I am Trying was sent to me a while ago by Oskar:
    Code:
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.IO;
    
    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/Multi/Co-Op/BlacKnight/";
    	
    	int RED = 1;
    	Stopwatch time = new Stopwatch();
    	
    	string[] 	NAME = {"Liverpool-East"};
    	int[]		TIME = { 4, 2 };
    	Stopwatch[]	TIMER = { new Stopwatch(), new Stopwatch() };
    
    	public override void OnBattleStarted() {
    
            MissionNumberListener = -1;
    		loadTrains();
            GamePlay.gpHUDLogCenter("Starting");
        }
    
        public override void OnTickGame() {
    
    		for (int i = 0 ; i < NAME.Length; i++) {
    			if (TIMER[i].Elapsed.Minutes >= TIME[i]) {
    				processTrain(i);
    			}
    		}
    	}
    
    	private void loadTrains() {
    
    		for (int i = 0 ; i < NAME.Length; i++) {
    			GamePlay.gpPostMissionLoad(MISSION_PATH + NAME[i] + ".mis");
    			TIMER[i].Start();
    		}
    	}
    	
    	private void processTrain(int i) {
    
    		AiGroundGroup[] groups = GamePlay.gpGroundGroups(RED);
    		foreach(AiGroundGroup g in groups) {
    			if (g.GroupType() == AiGroundGroupType.Train) {
    				if (g.Name().Contains(NAME[i])) {
    					AiActor[] actors = g.GetItems();
    					foreach (AiActor a in actors) {
    						((AiCart)a).Destroy();
    					}
    					GamePlay.gpPostMissionLoad(MISSION_PATH + NAME[i] + ".mis");
    					TIMER[i].Restart();
    				}
    			}
    		}
    	}
    }
    Files: https://drive.google.com/file/d/1suq...ew?usp=sharing

    Video: https://www.youtube.com/watch?v=Ne7a9P88vqY Sorry no mic will fix tonight!

    Hope ya can help!
    Last edited by BlacKnight; Mar-27-2023 at 13:48.

  10. #8
    Combat pilot
    Join Date
    Aug 2020
    Posts
    181
    Post Thanks / Like
    Total Downloaded
    121.31 MB

    Re: Despawning Trains on Trigger

    Ok I noticed anything with wagons are not removed.

    The simple Train without cars follows the script but the other train just sits there. So I believe the goal is to remove the AiChief with the combination of cars. anyway.

    Hope you guys can figure out how to destroy a full Train. Nothing I have done works...

    BlacKnight

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

    Re: Despawning Trains on Trigger

    Simpler like this.

    Code:
    using System.Diagnostics;
    
    using maddox.game;
    using maddox.game.world;
    
    
    public class Mission : AMission
    {
        int ARMY_RED = 1;
        static string[] TRAIN_MISSION_NAMES = { "Liverpool-East.mis" };
        int[] TRAIN_MISSION_TIMES = { 4, 2 };
        Stopwatch[] TRAIN_TIMERS = new Stopwatch[TRAIN_MISSION_NAMES.Length];
    
        public override void OnBattleStarted()
        {
            loadTrains();
            GamePlay.gpHUDLogCenter("Starting");
        }
    
    
        public override void OnTickGame()
        {
            for (int i = 0; i < TRAIN_MISSION_NAMES.Length; i++)
            {
                if (TRAIN_TIMERS[i].Elapsed.Minutes >= TRAIN_MISSION_TIMES[i])
                {
                    processTrain(i);
                }
            }
        }
    
    
        private void loadTrains()
        {
            for (int i = 0; i < TRAIN_MISSION_NAMES.Length; i++)
            {
                GamePlay.gpPostMissionLoad(BaseMissionPath + TRAIN_MISSION_NAMES[i]);
                TRAIN_TIMERS[i] = new Stopwatch();
                TRAIN_TIMERS[i].Start();
            }
        }
    
    
        private void processTrain(int i)
        {
            AiGroundGroup[] groups = GamePlay.gpGroundGroups(ARMY_RED);
            foreach (AiGroundGroup g in groups)
            {
                if ((g.GroupType() == AiGroundGroupType.Train) && (g.Name().Contains(TRAIN_MISSION_NAMES[i])))
                {
                    AiActor[] actors = g.GetItems();
                    foreach (AiActor a in actors)
                    {
                        ((AiCart)a).Destroy();
                    }
                    GamePlay.gpPostMissionLoad(BaseMissionPath + TRAIN_MISSION_NAMES[i]);
                    TRAIN_TIMERS[i].Restart();
                }
            }
        }
    }

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

    Re: Despawning Trains on Trigger

    Quote Originally Posted by BlacKnight View Post
    Ok I noticed anything with wagons are not removed.

    The simple Train without cars follows the script but the other train just sits there. So I believe the goal is to remove the AiChief with the combination of cars. anyway.

    Hope you guys can figure out how to destroy a full Train. Nothing I have done works...

    BlacKnight
    I don't see any obvious way to do it but destroying the whole train with one call would be desirable. I'll investigate.

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

    Re: Despawning Trains on Trigger

    Just noticed a bug in my code. Here's a different approach.

    Code:
    using System.Collections.Generic;
    using System.Diagnostics;
    
    using maddox.ai.ground;
    using maddox.game;
    using maddox.game.world;
    
    
    public class Mission : AMission
    {
        int ARMY_RED = 1;
        static string[] TRAIN_MISSION_NAMES = { "Liverpool-East.mis" };
        int[] TRAIN_MISSION_TIMES = { 4, 2 };
        Stopwatch[] TRAIN_TIMERS = new Stopwatch[TRAIN_MISSION_NAMES.Length];
        List<AiGroundGroup> trains = new List<AiGroundGroup>();
    
    
        public override void OnBattleStarted()
        {
            loadTrains();
            GamePlay.gpHUDLogCenter("Starting");
        }
    
    
        public override void OnTickGame()
        {
            for (int i = 0; i < TRAIN_MISSION_NAMES.Length; i++)
            {
                if (TRAIN_TIMERS[i].Elapsed.Minutes >= TRAIN_MISSION_TIMES[i])
                {
                    processTrain(i);
                }
            }
        }
    
    
        private void loadTrains()
        {
            for (int i = 0; i < TRAIN_MISSION_NAMES.Length; i++)
            {
                GamePlay.gpPostMissionLoad(BaseMissionPath + TRAIN_MISSION_NAMES[i]);
                TRAIN_TIMERS[i] = new Stopwatch();
                TRAIN_TIMERS[i].Start();
            }
            AiGroundGroup[] groups = GamePlay.gpGroundGroups(ARMY_RED);
            foreach (AiGroundGroup g in groups)
            {
                if (g.GroupType() == AiGroundGroupType.Train)
                {
                    trains.Add(g);
                }
            }
        }
    
    
        private void processTrain(int i)
        {
            AiActor[] actors = trains[i].GetItems();
            foreach (AiActor a in actors)
            {
                ((AiCart)a).Destroy();
            }
            GamePlay.gpPostMissionLoad(BaseMissionPath + TRAIN_MISSION_NAMES[i]);
            TRAIN_TIMERS[i].Restart();
            AiGroundGroup[] groups = GamePlay.gpGroundGroups(ARMY_RED);
            foreach (AiGroundGroup g in groups)
            {
                if (trains.IndexOf(g) < 0)
                {
                    trains[i] = g;
                }
            }
        }
    }

  14. #12
    Combat pilot
    Join Date
    Aug 2020
    Posts
    181
    Post Thanks / Like
    Total Downloaded
    121.31 MB

    Re: Despawning Trains on Trigger

    Can we not just load a mission from the main script and then use a destroy script like this to remove the train: train.miss and train.cs
    Code:
          AiGroundGroup[] groups = GamePlay.gpGroundGroups(RED);
    		foreach(AiGroundGroup g in groups) {
    			if (g.GroupType() == AiGroundGroupType.Train) {
    				if (g.Name().Contains(NAME[i])) {
    					AiActor[] actors = g.GetItems();
    					foreach (AiActor a in actors) {
    						((AiCart)a).Destroy();
    					}
    Code:
        public override void OnActorCreated(int missionNumber, string shortName, AiActor actor)
        {
            base.OnActorCreated(missionNumber,shortName,actor);
    		//ships will die after 55 min when counted from their birth
    		if ((actor as AiGroundActor).Type() == maddox.game.world.AiGroundActorType.Ship)  
    				Timeout (3300, () => 
    									{ if (actor != null)
    										{ (actor as AiGroundActor).Destroy(); }
    									}
    						);
        }

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
  •