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

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

Как мы узнали из предыдущего урока загруженные из под-миссий объекты игнорируются триггерами миссии-хоста (триггеры основной миссии не знают о под-миссиях и их объектах). Этого можно избежать используя триггеры в самих под-миссиях. Создадим по одному триггеру в каждой из наших трех под-миссий:

Sfdp2-1.jpg


Sfdp2-2.jpg


Sfdp2-3.jpg

Используйте разные имена триггеров, чтобы избежать ошибок в дальнейшем. Вы можете обращаться к триггеру без указания номера миссии при помощи gpGetTrigger("Triggername").

Теперь у нас есть три под-миссии, в каждой из которых стоит триггер на уничтожение создаваемых этой под-миссией объектов. Далее объединим эти триггеры в одно условие, чтобы иметь возможность оценить результаты атаки. Можно задать несколько условий используя логические И/ИЛИ, однако мы сделаем более удобный вариант. За успешную атаку будет засчитывать очки и по их количеству потом подводится общий итог. Пусть количество необходимых выполненных заданий будет равно 2, третью миссиию можно провалить. Также введем переменную, которая будет определять выполнили ли мы все задание (если 2 из 3-х - задание выполнено).


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} -перечисление состояний статуса выполнения миссии (Нейтрально, Успех, Провал). Точка с запятой в конце не ставится.

MissionCondition AktuelleMissionCondition = MissionCondition.Neutral; - инициализация переменной состояния текщей миссии со значением Нейтрально.

const int NeededForMissionSuccess = 2; - константа, в которой мы задаем кол-во успешно завершенных миссий, для выполнения задания по штурмовке.

int WinConditionCounter = 0; - задаем начальное значение (ноль) счетчика успешно выполненных миссий. Увеличивается на единицу с каждым выполнением под-миссий.

private void serverMessage (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

serverMessage ("Пример текста. Я сервер. Баню читеров и таранщиков"); 
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.