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:
* 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.
#1. In Main mission .cs file, in "onBattleStart()":
#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.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
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()); } } }
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.
Bookmarks