Results 1 to 11 of 11

Thread: Using Trigger/Action in FMB scripting; Action in .mis disabled=0, enabled=1?

  1. #1
    Ace
    Join Date
    May 2015
    Location
    Kansas City, Missouri area
    Posts
    515
    Post Thanks / Like
    Total Downloaded
    130.02 MB

    Using Trigger/Action in FMB scripting; Action in .mis disabled=0, enabled=1?

    OK, here is a little note I came across today because some triggers/actions in a .mis that I thought SHOULD be firing off, were not.

    So, what went wrong?

    Two things commonly go wrong.

    FACT #1. If you make a .mis file and you have a Trigger and an Action both with the EXACT same name, when the Trigger is called it will cause the Action to happen.

    So:

    Code:
    [Trigger]
      GerRaidBarrani1Hr TTime 3600
    
     [Action]
       GerRaidBarrani1Hr ASpawnGroup 1 BoB_LW_KuFlGr_706.03    <--- WILL RUN
    3600 seconds into your mission, the Action will occur, and the spawn group shown there will spawn in and start flying. Great.

    PROBLEM #1. If you have ANYTHING in the script file if your mission--anything, even one line--then this magic "trigger triggers corresponding action" suddenly stops happening.

    SOLUTION #2. Just put a few lines into your script file and you can fix this. The lines, of course, are just a little script to do what CLoD does automatically if you DON'T have a script.

    Code:
            
    public class Mission : AMission
    { 
    ...  bunch of things in your script ....
      public override void OnTrigger(int missionNumber, string shortName, bool active)
      {
        if (active)
        {
          AiAction action = GamePlay.gpGetAction("actionName"));
          if (action != null)
          action.Do();
       }
      }
    ... bunch more things in your script ....
    }
    There are various ways to fancy that up, but the basic idea is you are putting a small script in place in your script that duplicates the internal CloD script--in other words, whenever a Trigger is called, then just check if there is a corresponding Action and call if it there is.

    PROBLEM #2: ACTIONS ARE TURNED ON/OFF BY MYSTERIOUS 1S and 0S in the .MIS FILE

    Here is what I noticed, via testing, and I am not sure of the explanation or reason--or anyway to set this value in FMB?

    So posting here in hopes of further explanation.

    In the .mis file, every Action has a little 0 or 1. Examples:
    Code:
     [Action]
       action1 ASpawnGroup 1 BoB_LW_KuFlGr_706.03    <--- WILL RUN
       action2 ASpawnGroup 0 BoB_LW_KuFlGr_706.04    <--- WILL ***NOT*** RUN!!!!
    The note to the right is mine--because indeed, the ASpawnGroup 1 will run when you expect it to (say there is a trigger with the exact same name & you have inserted the code above into your .cs file) and ASpawnGroup 0 just won't run.

    So my explanation is, that 0 or 1 is the "enabled/disabled" switch for that action. If you used your script to enable the action, then it would run, I believe.

    However, it is puzzling because TRIGGERS have an enable switch (AiTrigger.Enable = bool {get;set;}) but AiAction doesn't have anything like an "enable" value.

    FACT #2. Using OnTrigger, we can trigger any action if we know its name via action.Do() - it doesn't need to be the associated action in the .mis file

    You can call actions at any time; you don't need to rely on the trigger to set it off. You only need to know the exact name of the
    trigger from the .mis file. When you call the trigger, the asasociated action will happen. Or, you can bypass the trigger altogether and simply call the Action.

    Sample of direct call of Action:

    Code:
         
         string ac = "MyAction";
         AiAction action = GamePlay.gpGetAction(ac);
         if (action != null) action.Do();
    Sample of call of Trigger--which will cause any Action of the same name to activate:

    Code:
         
                    string tr = "MyTrigger";       
                    if (GamePlay.gpGetTrigger(tr) != null ) { 
                    GamePlay.gpGetTrigger(tr).Enable = true; //only needed if you want to be sure the Trigger is enabled               
                    Battle.OnEventGame(GameEventId.Trigger, tr, true, 1);
    I believe that you can call both triggers and actions from any mission--either the main mission file or any sub-mission loaded via gpPostMissionLoad.

    As mentioned on a separate recent thread, if you have set MissionNumberListener = -1; in your script file (usually in method "Init()") then you'll receive the OnTrigger() notification from all submissions, as well as the main .mis file.

    Why use triggers/actions?

    You can set triggers & actions using your .mis file. That is often a convenient way to do so, especially for people who can't script or program. But even if you can script, it is often just more convenient, because of the ease of use of FMB in many situations such as selecting groups of objects in one given area.

    But even more important, if you load large submissions via GamePlay.gpPostMissionLoad(); partway into a mission, the result is often a large glitch for users. Solution: Put the airgroups, ships, trains, whatever in a .mis you load at the beginning of the mission. Then call that group via an Action or a Trigger/Action pair you have set up for that group sometime later in the mission. The airgroups etc will load without the slightest glitch or hesitation.

    Say you have a flight of 12 bombers you want to call in 20 minutes into the mission. You could just put that bomber flight into a .mis file and load it via GamePlay.gpPostMissionLoad(); at the 20 minute mark.

    Or, you could do this:

    • Put the bombers into a .mis file
    • Check the box "Script Spawn C" (short for Script Spawn ONLY as discussed on a recent thread) for that group in FMB setup box.
      • This checkbox prevents the airgroup from being spawned in automatically as soon as the mission is loaded
      • You can leave the box unchecked and in that case the airgroup will be spawned in at second 0 and AGAIN whenever you call the action as described below
    • Create a Trigger "MyBombers" at time 1200 (1200 seconds = 20 minutes)
    • Create an action "MyBombers" and associate it with the bomber group you want (use the clicky things in FMB)
    • Load the .mis file at minute ZERO of the mission using GamePlay.gpPostMissionLoad("MyHappyPath/Myhappyfile.mis");
    • The bombers will auto-load at minute 20. Assuming you have followed all the instructions above!


    Another option is to simply use the script to call action "MyBombers" whenever you want. Once it is setup in the .mis file, use something like:

    Code:
         
         string ac = "MyBombers";
         AiAction action = GamePlay.gpGetAction(ac);
         if (action != null) action.Do();
    This should work if you have Action "MyBombers" set up in (any) mission file you have loaded.
    Last edited by TWC_Flug; Sep-10-2020 at 20:43.
    System: Microsoft Windows 10 Pro 64 bit, 10.0.18362 N/A Build 18362, 20,437 MB |
    ASUS GeForce GTX 1060 3GB | Intel Core i5-2500 Quad-Core Processor 3.3 GHz 6 MB Cache LGA 1155 | Intel DB65AL motherboard | ARCTIC Freezer i11 CPU Cooler | SVGA 500 watt power supply | Microsoft Sidewinder 2 Force Feedback joystick

  2. Likes von Graf liked this post
  3. #2
    Ace
    Join Date
    May 2015
    Location
    Kansas City, Missouri area
    Posts
    515
    Post Thanks / Like
    Total Downloaded
    130.02 MB

    Re: Using Trigger/Action in FMB scripting; Action in .mis disabled=0, enabled=1?

    TL;DR of the aboove post is:

    Code:
    [Action]
       action1 ASpawnGroup 1 BoB_LW_KuFlGr_706.03
       action2 ASpawnGroup 0 BoB_LW_KuFlGr_706.04
    If the above lines are in your .mis file, when you call action1 in your script--or by matching it with a corresponding [Trigger], it works just fine.

    But action2, which includes the deadly 0, never fires off at all. No airgroup spawns in.

    So:

    • Does anyone know the meaning of the 0 and 1 in those lines?
    • Does anyone know how to set the 0 or 1 using FMB?


    There doesn't seem to be a dialogue or checkbox that allows you to set the 0 or 1. Or perhaps it is just not obvious?

    Anyway, I added a bunch of airgroups, triggers, and actions to a mission file recently and they all had the "0" in spot on the list in the [Action] section of the .mis file. And none of them ever appeared in the mission.

    I'm pretty sure when I change them to 1s (using a text editor on the .mis file) all will be well.
    System: Microsoft Windows 10 Pro 64 bit, 10.0.18362 N/A Build 18362, 20,437 MB |
    ASUS GeForce GTX 1060 3GB | Intel Core i5-2500 Quad-Core Processor 3.3 GHz 6 MB Cache LGA 1155 | Intel DB65AL motherboard | ARCTIC Freezer i11 CPU Cooler | SVGA 500 watt power supply | Microsoft Sidewinder 2 Force Feedback joystick

  4. #3
    ATAG_Colander's Avatar
    Join Date
    Nov 2011
    Location
    Bir Tawil
    Posts
    11,128
    Post Thanks / Like
    Total Downloaded
    255.73 MB

    Re: Using Trigger/Action in FMB scripting; Action in .mis disabled=0, enabled=1?

    For the computers 0=false and anything else = true (in this case anything else is 1)

  5. Likes danperin liked this post
  6. #4
    Supporting Member
    Join Date
    Dec 2019
    Posts
    473
    Post Thanks / Like
    Total Downloaded
    22.61 MB

    Re: Using Trigger/Action in FMB scripting; Action in .mis disabled=0, enabled=1?

    Aaaargh! don't do this to me, you've aroused my curiosity and I really didn't want to get into an unexplained FMB quirk that I couldn't understand!

    On a side note, loading sub missions is my next learning objective.
    I am Yo-Yo not YoYo (that's someone else)

  7. #5
    Supporting Member
    Join Date
    Dec 2019
    Posts
    473
    Post Thanks / Like
    Total Downloaded
    22.61 MB

    Re: Using Trigger/Action in FMB scripting; Action in .mis disabled=0, enabled=1?

    I can't see or remember any time that I have had it set as 0. So my question is how you manage to get it so!
    I am Yo-Yo not YoYo (that's someone else)

  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: Using Trigger/Action in FMB scripting; Action in .mis disabled=0, enabled=1?

    Quote Originally Posted by Yo-Yo View Post
    On a side note, loading sub missions is my next learning objective.

    Try this.


    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;
    using part;
    
    
    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 + "LoadMissionExample/data/";
    
        Stopwatch bomberTimer = new Stopwatch();
        Stopwatch jaboTimer = new Stopwatch();
        Stopwatch defenderTimer = new Stopwatch();
        Random random = new Random();
    
        static int BOMBER_INTERVAL = 2;
        static string[] bomberMissionNames = {"bomber0.mis", "bomber1.mis", "bomber0.mis", "bomber1.mis", "bomber2.mis", "bomber3.mis"};
    
        static int JABO_INTERVAL = 3;
        static string[] jaboMissionNames = {"JaBo_0.mis", "JaBo_1.mis"};
    
        static int DEFENDER_INTERVAL = 1;
        static string[] defenderMissionNames = {"defend0.mis", "defend1.mis"};
    
    
        public override void OnBattleStarted() {
    
            MissionNumberListener = -1;
            bomberTimer.Start();
            jaboTimer.Start();
            defenderTimer.Start();
        }
    
    
        public override void OnTickGame() {
    
            if (bomberTimer.Elapsed.Minutes >= BOMBER_INTERVAL) {
                bomberTimer.Restart();
    			GamePlay.gpPostMissionLoad(MISSION_DATA_PATH + bomberMissionNames[random.Next(0, bomberMissionNames.Length)]);
            }
            if (jaboTimer.Elapsed.Minutes >= JABO_INTERVAL) {
                jaboTimer.Restart();
    			GamePlay.gpPostMissionLoad(MISSION_DATA_PATH + jaboMissionNames[random.Next(0, jaboMissionNames.Length)]);
    		}
            if (defenderTimer.Elapsed.Minutes >= DEFENDER_INTERVAL) {
                defenderTimer.Restart();
                GamePlay.gpPostMissionLoad(MISSION_DATA_PATH + defenderMissionNames[random.Next(0, defenderMissionNames.Length)]);
    		}
    	}
    
    }
    Last edited by ATAG_Oskar; Sep-14-2020 at 13:36. Reason: fixed

  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: Using Trigger/Action in FMB scripting; Action in .mis disabled=0, enabled=1?

    Quote Originally Posted by TWC_Flug View Post
    OK, here is a little note I came across today because some triggers/actions in a .mis that I thought SHOULD be firing off, were not.
    Thanks for writing this up. It does make sense that you can use the no-script solution with triggers and actions or you can do it all in code. That OnTrigger code is perfect.

    I usually set the MissionNumberListener in the OnBattleStarted which you almost always write.

    In the FMB if you create an action without the airgroup being set the 'active flag' will be 0, false. If you then set an airgroup and save the mission the flag will change to 1, true.

  10. Likes Yo-Yo liked this post
  11. #8
    Ace
    Join Date
    May 2015
    Location
    Kansas City, Missouri area
    Posts
    515
    Post Thanks / Like
    Total Downloaded
    130.02 MB

    Re: Using Trigger/Action in FMB scripting; Action in .mis disabled=0, enabled=1?

    Quote Originally Posted by ATAG_Oskar View Post
    In the FMB if you create an action without the airgroup being set the 'active flag' will be 0, false. If you then set an airgroup and save the mission the flag will change to 1, true.
    Aha. I've just been working on a mission and when the Actions came out (ie, when I saved it) they were all 0 for some reason. Then I worked on it again today, saved again, and again all the new actions were set to 0.

    I'm pretty sure they were all associated with an airgroup, as that was the point of making them.

    There may be some other minorly mysterious thing going on here.
    System: Microsoft Windows 10 Pro 64 bit, 10.0.18362 N/A Build 18362, 20,437 MB |
    ASUS GeForce GTX 1060 3GB | Intel Core i5-2500 Quad-Core Processor 3.3 GHz 6 MB Cache LGA 1155 | Intel DB65AL motherboard | ARCTIC Freezer i11 CPU Cooler | SVGA 500 watt power supply | Microsoft Sidewinder 2 Force Feedback joystick

  12. #9
    Supporting Member
    Join Date
    Dec 2019
    Posts
    473
    Post Thanks / Like
    Total Downloaded
    22.61 MB

    Re: Using Trigger/Action in FMB scripting; Action in .mis disabled=0, enabled=1?

    Quote Originally Posted by ATAG_Oskar View Post
    Try this.


    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;
    using part;
    
    
    public class Mission : AMission {
    
        static string MISSION_PATH = USER_DOC_PATH + "/1C SoftClub/il-2 sturmovik cliffs of dover/missions/Single/";
        static string MISSION_DATA_PATH = MISSION_PATH + "LoadMissionExample/data/";
    
        Stopwatch bomberTimer = new Stopwatch();
        Stopwatch jaboTimer = new Stopwatch();
        Stopwatch defenderTimer = new Stopwatch();
        Random random = new Random();
    
        static int BOMBER_INTERVAL = 2;
        static string[] bomberMissionNames = {"bomber0.mis", "bomber1.mis", "bomber0.mis", "bomber1.mis", "bomber2.mis", "bomber3.mis"};
    
        static int JABO_INTERVAL = 3;
        static string[] jaboMissionNames = {"JaBo_0.mis", "JaBo_1.mis"};
    
        static int DEFENDER_INTERVAL = 1;
        static string[] defenderMissionNames = {"defend0.mis", "defend1.mis"};
    
    
        public override void OnBattleStarted() {
    
            MissionNumberListener = -1;
            bomberTimer.Start();
            jaboTimer.Start();
            defenderTimer.Start();
        }
    
    
        public override void OnTickGame() {
    
            if (bomberTimer.Elapsed.Minutes >= BOMBER_INTERVAL) {
                bomberTimer.Restart();
    			GamePlay.gpPostMissionLoad(MISSION_DATA_PATH + bomberMissionNames[random.Next(0, bomberMissionNames.Length)]);
            }
            if (jaboTimer.Elapsed.Minutes >= JABO_INTERVAL) {
                jaboTimer.Restart();
    			GamePlay.gpPostMissionLoad(MISSION_DATA_PATH + jaboMissionNames[random.Next(0, jaboMissionNames.Length)]);
    		}
            if (defenderTimer.Elapsed.Minutes >= DEFENDER_INTERVAL) {
                defenderTimer.Restart();
                GamePlay.gpPostMissionLoad(MISSION_DATA_PATH + defenderMissionNames[random.Next(0, defenderMissionNames.Length)]);
    		}
    	}
    
    }
    Does USER_DOC_PATH need to be manually set or can it read the system somehow? I can't see how it has a value in this code sorry.
    I am Yo-Yo not YoYo (that's someone else)

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

    Re: Using Trigger/Action in FMB scripting; Action in .mis disabled=0, enabled=1?

    static string USER_DOC_PATH = Environment.GetFolderPath(Environment.SpecialFolde r.MyDocuments);

    Updated original post.
    Last edited by ATAG_Oskar; Sep-14-2020 at 13:36.

  14. Likes Yo-Yo, TWC_Flug liked this post
  15. #11
    Novice Pilot ITAF_Airone1989's Avatar
    Join Date
    Aug 2020
    Posts
    95
    Post Thanks / Like
    Total Downloaded
    812.8 KB

    Re: Using Trigger/Action in FMB scripting; Action in .mis disabled=0, enabled=1?

    Quote Originally Posted by TWC_Flug View Post
    TL;DR of the aboove post is:

    Code:
    [Action]
       action1 ASpawnGroup 1 BoB_LW_KuFlGr_706.03
       action2 ASpawnGroup 0 BoB_LW_KuFlGr_706.04
    If the above lines are in your .mis file, when you call action1 in your script--or by matching it with a corresponding [Trigger], it works just fine.

    But action2, which includes the deadly 0, never fires off at all. No airgroup spawns in.

    So:

    • Does anyone know the meaning of the 0 and 1 in those lines?
    • Does anyone know how to set the 0 or 1 using FMB?


    There doesn't seem to be a dialogue or checkbox that allows you to set the 0 or 1. Or perhaps it is just not obvious?

    Anyway, I added a bunch of airgroups, triggers, and actions to a mission file recently and they all had the "0" in spot on the list in the [Action] section of the .mis file. And none of them ever appeared in the mission.

    I'm pretty sure when I change them to 1s (using a text editor on the .mis file) all will be well.

    "ASpawnGroup 1" become "ASpawnGroup 0" any time you are writing a script from FMB and then instead of "save" you press "cancel".
    This happens to all the triggers already in the script.

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
  •