Ил-2 Штурмовик: Битва за Британию. Скрипты. Скрипты для чайников. Часть 2 - Загрузка подмиссий

Материал из АвиаВики
Перейти к: навигация, поиск
Автор: FG28_Kodiak
Ссылка: Перейти (перевод Google)
Samples.zip

As we have already learned in the last lesson, newly charged objects are ignored by the triggers. You can remedy this by providing the submissions with triggers.

Sfdp2-1.jpg

Sfdp2-2.jpg

Sfdp2-3.jpg

It is advisable to use in each mission, a different trigger name, trigger with the same name there may be "oddities" to come. Think this is a bug in Clodo before, at the same trigger name now and then I had the problem that the third trigger is triggered once and another time not: /. Also you can gpGetTrigger("Triggername") mitübergeben no mission number.

So we now have three submissions each each with its own circuit for the trigger to destroying ground targets. Now it is also time to combine these triggers another. One could now pretend that such a mission goal of the players (or the corresponding page) at least two of three sub-goals must meet in order to successfully complete the mission. One could, of course, now program the Trigger1 AND OR Trigger2 the Trigger2 AND OR Trigger3 the Trigger1 AND Trigger3 must be met to win the mission. Are then of course a very nice mess of if - queries. By the time we will integrate more with their own submissions triggers the whole more than confusing. An alternative is here simply the number of triggered win (or fail) to trigger count, and then simply compare it to a number which represents the number of necessary sub-goals. Also still would be a useful variable to specify whether the mission has been successful or has been lost. This variable could then query later, for example if you want the mission will be considered only after a successful landing.

So we come to the code:

using System; 
using maddox.game; 
using maddox.game.world; 
public class Mission : maddox.game.AMission 
{ 
enum MissionCondition {Neutral, Success, Failure}
MissionCondition AktuelleMissionCondition = MissionCondition.Neutral; 
const int NeededForMissionSuccess = 2; 
int WinConditionCounter = 0;
private void serverMessage (string msg) 
{ 
GamePlay.gpLogServer (null, msg, new object [] {msg}); 
}
public override void OnBattleStarted() 
{ 
base.OnBattleStarted(); 
MissionNumberListener = -1; 
serverMessage ("\nZerstören sie jeweils mindestens 3 Fahrzeuge aus zwei Gruppen\n\n");
GamePlay.gpPostMissionLoad("missions\\Single\\Samples\\TestSubmissions\\MissionNachladen3Sub1.mis"); 
GamePlay.gpPostMissionLoad("missions\\Single\\Samples\\TestSubmissions\\MissionNachladen3Sub2.mis"); 
GamePlay.gpPostMissionLoad("missions\\Single\\Samples\\TestSubmissions\\MissionNachladen3Sub3.mis"); 
}
public override void OnTrigger(int missionNumber, string shortName, bool active) 	 	 { 
base.OnTrigger(missionNumber, shortName, active); 	 	 
GamePlay.gpLogServer (null, "OnTrigger({0} | {1} | {2}) wurde ausgelöst", new object [] {missionNumber, shortName, active}); //Nur für Testzwecke, löschen oder auskommentieren wenn Endfassung 	 	 
if (AktuelleMissionCondition == MissionCondition.Neutral) 
{ 
if ("WinCondition1".Equals(shortName) && active) 
{ 
WinConditionCounter++; 
GamePlay.gpGetTrigger(shortName).Enable = false; 
} 
if ("WinCondition2".Equals(shortName) && active) 
{ 
WinConditionCounter++; 
GamePlay.gpGetTrigger(shortName).Enable = false; 
} 
if ("WinCondition3".Equals(shortName) && active) 
{ 
WinConditionCounter++; 
GamePlay.gpGetTrigger(shortName).Enable = false; 
} 
serverMessage ("Anzahl erledigter Teilziele: " + WinConditionCounter.ToString()); // Für Testzwecke. 	 
if (WinConditionCounter >= NeededForMissionSuccess) 
{ 
AktuelleMissionCondition = MissionCondition.Success; 
GamePlay.gpHUDLogCenter("Ziel erreicht"); 
serverMessage ("Endanzahl: " + WinConditionCounter.ToString()); // Für Testzwecke. 
GamePlay.gpGetTrigger("FailCondition1").Enable = false; 
} 
if ("FailCondition1".Equals(shortName) && active) 
{ 
AktuelleMissionCondition = MissionCondition.Failure; 
GamePlay.gpHUDLogCenter("Sie haben die Zeit überschritten"); 	 	 
serverMessage ("Endanzahl: " + WinConditionCounter.ToString()); // Für Testzwecke. 	 
GamePlay.gpGetTrigger(shortName).Enable = false; 	 
} 
} 
} 
} 


enum MissionCondition {Neutral, Success, Failure} enum enumerated type identifies a missionary here named condition, in the curly brackets are the states can assume the mission condition. Here stands for Neutral mission is still in the balance, the mission is successful for Success and Failure, of course, is for mission failed. Behind the brace is not a semicolon.

MissionCondition AktuelleMissionCondition = MissionCondition.Neutral; Initializes a condition variable current mission by mission-type condition with the value neutral. const int NeededForMissionSuccess = 2; Contains the successful mission for the necessary trigger number in the example once set to 2, was also the number as a constant (const) is defined, it would change the variable later, you would get an error message. WinConditionCounter int = 0; This is our "Trigger counter" it is increased when calling a "WinTriggers" by one. At the beginning of its value was set to 0. The declarations are just made in the entire class mission valid, ie they can be addressed by each method and modified up to the constant.

server private void message (string msg) { GamePlay.gpLogServer (null, msg, new object [] {msg}); }

Here I have introduced something new. I have a method which strings programmed into the chat bar (or in the console or in the server log if enabled) as output. You can simply use the method in which one example message server ("example text"); fits in the program code.

Simple example:

using System; using maddox.game; using maddox.game.world;


public class Mission : maddox.game.AMission { private void serverMessage (string msg) { GamePlay.gpLogServer (null, msg, new object [] {msg}); }

public override void OnBattleStarted() { base.OnBattleStarted();

serverMessage("Dieser Text wird zum Beginn der Mission ausgegeben"); } }


Sfdp2-4.jpg

message server has a transfer value is a string and passes it to the method of gpLogserver IGamePlay class. GamePlay.gpLogServer (null, msg, new object [] {msg}); Let us take a closer look gpLogServer has three transfer parameters: void gpLogServer (maddox.game.Player [] to, string format, object [] args) and indeed, with the first parameter (maddox.game.Player [] to) specify the addressee of the message, which may consist of any player (zero) or even a particular player. The second parameter contains the message to be output as a string ("string"). With the help of the third parameter you can even pass variables that are in the string {0}, {1} ... Can add {n}. Where {0}, the first variable, {1} the second, {n} the n-th variable (depending on number) refers. In the first example above, I use the following call (as a debugging aid in OnTrigger): GamePlay.gpLogServer (null, "OnTrigger ({0} | {1} | {2}) has been thrown", new object [] {mission number, short name, active}); The example is when the trigger from the WinCondition2 Submission 2 was released, following in the chat bar:

Sfdp2-5.jpg

After this brief slide back to the topic:

Let's go to OnBattleStarted (), this remains to previous versions of the past in much the same lesson is issued only with the help of server-message a short explanatory text. server message ("\ nZerstören it at least three vehicles from two groups \ n \ n"); \ N is a control sequence and provides for a line break.

Sfdp2-6.jpg

The biggest changes took place in OnTrigger.

public override void OnTrigger(int missionNumber, string shortName, bool active) {

   base.OnTrigger(missionNumber, shortName, active); 
         
   GamePlay.gpLogServer (null, "OnTrigger({0} | {1} | {2})  wurde ausgelöst", new object [] {missionNumber, shortName, active}); //Nur für Testzwecke, löschen oder auskommentieren wenn Endfassung
   
   if (AktuelleMissionCondition == MissionCondition.Neutral)
   {
       if ("WinCondition1".Equals(shortName) && active) 
       { 
           WinConditionCounter++; 
           GamePlay.gpGetTrigger(shortName).Enable = false; 
         }
         if ("WinCondition2".Equals(shortName) && active) 
       { 
           WinConditionCounter++;
           GamePlay.gpGetTrigger(shortName).Enable = false;
         }
         if ("WinCondition3".Equals(shortName) && active) 
       { 
           WinConditionCounter++;
           GamePlay.gpGetTrigger(shortName).Enable = false;
         }
         serverMessage ("Anzahl erledigter Teilziele: " + WinConditionCounter.ToString()); // Für Testzwecke.
             
       if (WinConditionCounter >= NeededForMissionSuccess)
       {
           AktuelleMissionCondition = MissionCondition.Success;
           GamePlay.gpHUDLogCenter("Ziel erreicht");
           serverMessage ("Endanzahl: " + WinConditionCounter.ToString()); // Für Testzwecke.
           GamePlay.gpGetTrigger("FailCondition1").Enable = false;
         }
         if ("FailCondition1".Equals(shortName) && active) 
       { 
           AktuelleMissionCondition = MissionCondition.Failure;
           GamePlay.gpHUDLogCenter("Sie haben die Zeit überschritten");      
           serverMessage ("Endanzahl: " + WinConditionCounter.ToString()); // Für Testzwecke.   
           GamePlay.gpGetTrigger(shortName).Enable = false;   
         }
   }

}

if (condition == current mission MissionCondition.Neutral) If it were our main query, as long as the mission has not decided yet, can the contents of the query are executed, the mission was successful or unsuccessful, all other trigger events are ignored. If you want to continue to count the events yet, as if the mission had been successful, one can extend the if statement also if ((condition == current mission MissionCondition.Neutral) | | (condition == MissionCondition.Success current mission)) that | is for | OR.

if ("WinCondition1." Equals (shortname) & & active) { WinConditionCounter + +; GamePlay.gpGetTrigger (ShortName) Enable = false.; }

The if-statements for the WinCondition Triggers have been adjusted, and that is registered in the trigger is invoked by WinConditionCounter is increased by one (this is + + so to speak, the abbreviation of WinConditionCounter WinConditionCounter = + 1). This is repeated for all of our WinTrigger.

To save on copying and pasting the if statement and not repeat it at every trigger newcomers need to, we can exploit the WinCondition - triggers were simply numbered. And with

if (shortName.Substring (0, 12). Equals ("WinCondition") & & active) { WinConditionCounter + +; GamePlay.gpGetTrigger (ShortName) Enable = false.; }

shortName.Substring (0, 12). Equals ("WinCondition"). Substring (0, 12) ensures that only the first 12 letters of the trigger name to be observed (Actually, had also passed the first three so shortName.Substring (0, 3 )), thus making the inside of each instruction executed when the trigger is the beginning WinCondition.

server message ("Number of completed sub-goals:" + WinConditionCounter.ToString ()) / / For testing purposes only. serves as a control output for debugging purposes, I have deliberately chosen this form, I would be able to write GamePlay.gpLogServer (null, "number of completed sub-goals: {0}", new object [] {} WinConditionCounter); As already mentioned, you can spend with server message ("...") a string. WinConditionCounter but is to be of type int (integer) and must therefore first in a string (String) converted, plus there is the ToString () method that will do this for us.

Continue with

if (WinConditionCounter> = NeededForMissionSuccess) { current mission condition = MissionCondition.Success; GamePlay.gpHUDLogCenter ("goal reached"); server message ("final number:" + WinConditionCounter.ToString ()) / / For testing purposes only. GamePlay.gpGetTrigger ("FailCondition1") enable = false.; }

This if statement to ask whether WinConditionCounter NeededForMissionSuccess already greater than or equal (that is to win the necessary number of sub-goals) is. If this is the case, the condition variable current mission is set to Success (mission is won) and the message "destination reached" is displayed on the screen. Also, the trigger "FailCondition1" disabled.

if ("FailCondition1." Equals (shortname) & & active) { current mission condition = MissionCondition.Failure; GamePlay.gpHUDLogCenter ("You have exceeded the time"); server message ("final number:" + WinConditionCounter.ToString ()) / / For testing purposes only. GamePlay.gpGetTrigger (ShortName) Enable = false.; }

This query asks if released from the trigger was FailCondition1 & & this is activated. If the expression is true, the if statement, the message "You have exceeded the time", the variable current mission set to failure condition (the mission is lost. And as so often is also the trigger FailCondition1 disabled.


At the conclusion of the entire code again without the test messages and "shortName.Substring (0, 12). Equals (" WinCondition ")"

As mission designers need to actually specify only the number of events needed for victory with NeededForMissionSuccess, replace the paths and file names of the missions to be loaded and, if the on-screen messages (or control messages) with your own.


using System; using maddox.game; using maddox.game.world;

public class Mission : maddox.game.AMission { enum MissionCondition {Neutral, Success, Failure}

MissionCondition AktuelleMissionCondition = MissionCondition.Neutral; const int NeededForMissionSuccess = 2; int WinConditionCounter = 0;


private void serverMessage (string msg) { GamePlay.gpLogServer (null, msg, new object [] {msg}); }

public override void OnBattleStarted() { base.OnBattleStarted(); MissionNumberListener = -1;

serverMessage ("\nZerstören sie jeweils mindestens 3 Fahrzeuge aus zwei Gruppen\n\n");

GamePlay.gpPostMissionLoad("missions\\Single\\Samples\\TestSubmissions\\MissionNachladen3Sub1.mis"); GamePlay.gpPostMissionLoad("missions\\Single\\Samples\\TestSubmissions\\MissionNachladen3Sub2.mis"); GamePlay.gpPostMissionLoad("missions\\Single\\Samples\\TestSubmissions\\MissionNachladen3Sub3.mis"); }

public override void OnTrigger(int missionNumber, string shortName, bool active) { base.OnTrigger(missionNumber, shortName, active);

if (AktuelleMissionCondition == MissionCondition.Neutral) { if (shortName.Substring(0, 12).Equals("WinCondition") && active) { WinConditionCounter++; GamePlay.gpGetTrigger(shortName).Enable = false; }

if (WinConditionCounter >= NeededForMissionSuccess) { AktuelleMissionCondition = MissionCondition.Success; GamePlay.gpHUDLogCenter("Ziel erreicht"); GamePlay.gpGetTrigger("FailCondition1").Enable = false; }

if ("FailCondition1".Equals(shortName) && active) { AktuelleMissionCondition = MissionCondition.Failure; GamePlay.gpHUDLogCenter("Sie haben die Zeit überschritten"); GamePlay.gpGetTrigger(shortName).Enable = false; } } } }

Again, I am as always grateful for criticism and suggestions.

Attachment as the training mission, MissionNachladen3.cs contains the first version at the top and bottom of the adjusted MissionNachladen4.cs.

The sample directory to ... \ Documents \ 1C club Soft \ IL-2 Sturmovik cliffs of dover \ missions \ single copy or adapt the paths to the submissions manually.