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.
Bookmarks