Results 1 to 8 of 8

Thread: How to: Make the trigger of submission appear in the script file of main mission

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

    How to: Make the trigger of submission appear in the script file of main mission

    We use triggers quite a bit to determine if mission objectives have been completed. You can detected if various objectives have been completed a few different ways, but triggers can be easily set up in FMB, setting them up is quite easy and visual, and--perhaps most important--they work very well for moving targets like convoys and shipping.

    However, we also like to load objectives like this as sub-mission--ie, at some point after the main mission starts, we use a command like GamePlay.gpPostMissionLoad(fileppathandname); to load a small .mis file with that objective and perhaps a few related items (say, flak to protect it). This make it easy to change missions, objectives, etc around dynamically.

    So the problem is, when you load a submission via gpPostMissionLoad, and if that submission has a trigger, the script file of that submission will receive notification of the trigger. But the script (.cs) file of the MAIN mission won't.* So this is a problem if you want to keep track of when triggers were activated in the main mission script file.

    We were talking about this the other day and ATAG_Oskar was able to share a really slick solution to this problem. Below is the code I inserted into our mission files, based on the suggestions ATAG_Oskar made:


    #1. In Main mission .cs file, in "onBattleStart()":

    Code:
    DataDictionary["MAIN.MISSION"] = this; //saves a reference to the main script file class mission to the DataDictionary where the sub-mission script can find & use it
    #2. Here is the complete .cs file that went with each submission. Normally these submissions don't have any .cs so this is the complete file.

    Note that a few lines of it may not be strictly necessary (ie, this is just a standard list of $references and using statements scripts typically use; I didn't spend time paring it down to the absolutely minimum).

    Code:
    //$reference parts/core/Strategy.dll
    //$reference parts/core/gamePlay.dll
    //$reference parts/core/gamePages.dll
    
    
    using System;
    using System.Collections.Generic;
    using System.IO;
    
    using maddox.game;
    using maddox.game.world;
    using maddox.GP;
    using maddox.game.page;
    using part;
    
    
    public class Mission : AMission
    {
    
        AMission mainMission;
    
        public Mission()
        {
    
            Console.WriteLine("SUBMISSION loaded . . . ");
    
            try
            {
                Console.WriteLine("SUBMISSION .cs file loading...");
                mainMission = (AMission)DataDictionary["MAIN.MISSION"]; //get the reference to the main mission object that was saved in the main mission script earlier
            }
            catch (Exception ex) { Console.WriteLine("SUBMISSION initializer(): ERROR! " + ex.ToString()); }
        }
    
        public override void OnTrigger(int missionNumber, string shortName, bool active)
        {
            try
            {
                mainMission.OnTrigger(missionNumber, shortName, active);  //now send the trigger to the main mission OnTrigger() method
            }
            catch (Exception ex) { Console.WriteLine("SUBMISSION OnTrigger ERROR!: " + ex.ToString()); }
        }
    
    }
    * I tested reception of triggers from submissions in the script file of the main mission pretty extensively and received nothing. Then when testing this new scheme, it seemed like they were indeed received! Even when the submission script file was not working! So honestly I'm not 100% sure if they are received or not. It is possible there is a setting somewhere that switches between received/not received in the main mission script file.

    If anyone knows a definitely answer about this (are triggers from sub-missions sent to OnTrigger() in the main script file?) I would appreciate knowing more.

    In the meanwhile, the above is definitely one way to work around the situation.

    UPDATE: It turns out if you have MissionNumberListener=-1 set in your main mission then you should receive all "OnXXX" type events from all missions. This includes OnTrigger().

    Perhaps when I was testing I didn't have MissionNumberListener=-1 set.

    See comments from ATAG_Oskar below.
    Last edited by TWC_Flug; Sep-10-2020 at 19:21.
    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 Yo-Yo, Temuri liked this post
  3. #2
    Team Fusion Artist's Avatar
    Join Date
    Mar 2010
    Posts
    2,878
    Post Thanks / Like
    Total Downloaded
    319.97 MB

    Re: How to: Make the trigger of submission appear in the script file of main mission

    There's another possibility with two methods I've introduced lately (patch 003)

    ABattle has a new method AMission GetBaseMission()

    AMission has a new method object[] OnIntraMissionsMessage(string sMsg, object[] args = null), which allows missions to send arbitrary data to each other.

    /// SUB-MISSION
    Code:
    public override void Inited()
    {
        base.Inited();
        AMission BaseMission = Battle.GetBaseMission();
        BaseMission.OnIntraMissionsMessage("sub-mission xyz to base mission: here I am", new object[] { this });
    }
    /// BASE MISSION
    Code:
    public override object[] OnIntraMissionsMessage(string sMsg, object[] args = null)
    {
        if(sMsg.Equals("sub-mission xyz to base mission: here I am")
        {
            m_SubMissions.Add("xyz", (args[0] as AMission));
        }
        return null;
    }
    Known Limitations (also apply to Oskar's way): Because each mission script is compiled into it's own temporary.dll,
    - only AMission methods can be called, not mission builder's own methods he added to Mission.
    - Classes defined in one mission are unknown to the other.
    This limitation, by the way would not affect instances of classes that have been compiled in a separate dll which is then //$reference'd nby both missions

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

    Re: How to: Make the trigger of submission appear in the script file of main mission

    Quote Originally Posted by Artist View Post
    There's another possibility with two methods I've introduced lately (patch 003)

    ABattle has a new method AMission GetBaseMission()

    AMission has a new method object[] OnIntraMissionsMessage(string sMsg, object[] args = null), which allows missions to send arbitrary data to each other.
    Aha, thanks--that is helpful.
    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

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

    Re: How to: Make the trigger of submission appear in the script file of main mission

    FYI we are definitely getting "double trigger messages" from submissions now.

    I haven't tested this extremely thoroughly, but I assume it is due to one regular old trigger message and then another from the submission .cs (Oskar's code above).

    This is extremely puzzling to me as I am sure I tested whether the trigger of a submission would come through to the main mission, and there was no trigger passthrough at all that I could see.

    So, maybe something has changed in the program, or maybe I messed something up when trying to test the triggers of the submissions.
    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

  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: How to: Make the trigger of submission appear in the script file of main mission

    Quote Originally Posted by TWC_Flug View Post
    FYI we are definitely getting "double trigger messages" from submissions now.

    I haven't tested this extremely thoroughly, but I assume it is due to one regular old trigger message and then another from the submission .cs (Oskar's code above).

    This is extremely puzzling to me as I am sure I tested whether the trigger of a submission would come through to the main mission, and there was no trigger passthrough at all that I could see.

    So, maybe something has changed in the program, or maybe I messed something up when trying to test the triggers of the submissions.
    This is where the "MissionNumberListener" comes into play. You probably have that set to -1 in your main mission. That means 'send me events from all missions'. You could set it to 0 in the main and 1 in your sub-mission.

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

    Re: How to: Make the trigger of submission appear in the script file of main mission

    Quote Originally Posted by ATAG_Oskar View Post
    This is where the "MissionNumberListener" comes into play. You probably have that set to -1 in your main mission. That means 'send me events from all missions'. You could set it to 0 in the main and 1 in your sub-mission.
    Aha, I wondered about that. Perhaps I didn't have it set to -1 when testing, and now I do.

    So "events" of all missions includes things like triggers? Generaly speaking, all the 'OnXXX' type events?

    If you set MissionNumberListener to something other than -1, what does that do? Does it catch events only from mission #s greater than MissionNumberListener or anything tricky like that?
    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

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

    Re: How to: Make the trigger of submission appear in the script file of main mission

    Quote Originally Posted by TWC_Flug View Post
    Aha, I wondered about that. Perhaps I didn't have it set to -1 when testing, and now I do.

    So "events" of all missions includes things like triggers? Generaly speaking, all the 'OnXXX' type events?

    If you set MissionNumberListener to something other than -1, what does that do? Does it catch events only from mission #s greater than MissionNumberListener or anything tricky like that?
    Whenever you start a mission, SP or MP, you select a mission file with a name ending in MIS. In the sim that is mission zero. A script in that mission might load more missions. These will be given numbers starting with 1. You can get events from all mission scripts or just one depending in how you set MissionNumberListener.

  9. #8
    Team Fusion Artist's Avatar
    Join Date
    Mar 2010
    Posts
    2,878
    Post Thanks / Like
    Total Downloaded
    319.97 MB

    Re: How to: Make the trigger of submission appear in the script file of main mission

    Quote Originally Posted by TWC_Flug View Post
    Aha, thanks--that is helpful.
    Did Fatal forward the SampleMission-v1.0.2 to you? There's an example implementation concerning statistics collection (using a sub mission to keep all that code away from the main mission).

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
  •