Mission scripts (EM4)

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

Information: The EMERGENCY community board is completely free and is financed by advertisement. Please deactivate adblocker if you use this site. Thank you!

  • Information about missions scripts for EMERGENCY 4.
    Mission scripts are the story script of the missions. These scripts can be used to define events, soundtracks, cutscenes and complex logics (if house A is burning, house A crashes, car B is destroyed, etc.).

    Basic class

    At the beginning was the wheel - and that is how you have to imagine the first important class of a script. This base class is called "Mission Script" and encloses the entire script. Please note the exact spelling, because C ++ is a language that is case-sensitive, that is case-dependent. If a letter is not capitalized, although it is required, then complications and the worst (and most likely) case result in an error message and the crash of the game.

    Source Code

    1. object Mission01 : MissionScript
    2. {
    3. };
    • Mission01 is the name of the mission script. This can be freely chosen, but should be meaningful and equal to the name of the script file.
    • MissionScript is the already mentioned basic class.
    Within this object (another class of C ++), important functions and methods can now be defined. For all that is outside this object, one speaks of "Script global variables". These are, for example, special #Strings.
    Particular attention should be paid to braces. Each opening bracket also needs a closing bracket. This is one of the most important syntax rules of C ++. With the code lines above we already have a first script, which does not help us for the moment.

    Constructor / destructor

    As the name implies, there are scriptparts that build up and break down.

    Source Code

    1. object Mission01 : MissionScript
    2. {
    3. Mission01()
    4. {}
    5. ~Mission01()
    6. {}
    7. };

    Mission Conditions

    In principle, you have to distinguish between the mission targets displayed in the overview window and the status of the mission (running, completed or lost). The status of the mission is checked by the function "GetMissionState ()", which must return a value from the list "MissionState". Possible "MissionState" values are "MISSION_RUNNING" for a running, "MISSION_SUCCEEDED" for a successfully completed, and "MISSION_FAILED" for a failed mission. When a value other than "MISSION RUNNING" is returned, the mission is immediately terminated.

    Mission conditions are added with the "Mission :: AddObjective ()" function and removed with "Mission :: RemoveObjective ()" or even "Mission :: RemoveAllObjectives ()". Usually, mission conditions are added to "void Start ()", but this can also be done at any other point (for example, when the mission changes during the mission). "Mission: Set Objective Accomplished ()" determines whether a mission condition is fulfilled or not.It is possible to re-establish a condition that has already been fulfilled, for example when new fires break out. A useful function both for mission status and mission conditions is "Mission :: GetCounter ()", which can be used to query predefined counters, such as the number of Burning Houses. For the sake of simplicity, the strings (OBJECTIVE AB) can be immediately translated with the later text; this method is also used in the example.

    Source Code

    1. const char OBJECTIVE_A[] = "Löschen Sie alle Brände!";
    2. const char OBJECTIVE_B[] = "Bringen Sie alle verletzten und toten Personen ins Krankenhaus";
    3. object Mission01 : MissionScript
    4. {
    5. Mission01()
    6. {}
    7. ~Mission01()
    8. {}
    9. void Start()
    10. {
    11. Mission::AddObjective(OBJECTIVE_A);
    12. Mission::SetObjectiveAccomplished(OBJECTIVE_A, false);
    13. Mission::AddObjective(OBJECTIVE_B);
    14. Mission::SetObjectiveAccomplished(OBJECTIVE_B, false);
    15. }
    16. MissionState GetMissionState()
    17. {
    18. if (Mission::GetCounter("Burning Objects") + Mission::GetCounter("Burning Houses") == 0)
    19. {
    20. if (!Mission::IsObjectiveAccomplished(OBJECTIVE_A))
    21. Mission::SetObjectiveAccomplished(OBJECTIVE_A, true);
    22. }
    23. else
    24. {
    25. if (Mission::IsObjectiveAccomplished(OBJECTIVE_A))
    26. Mission::SetObjectiveAccomplished(OBJECTIVE_A, false);
    27. }
    28. if (Mission::GetCounter("Injured Persons") + Mission::GetCounter("Dead Persons") == 0)
    29. {
    30. if (!Mission::IsObjectiveAccomplished(OBJECTIVE_B))
    31. Mission::SetObjectiveAccomplished(OBJECTIVE_B, true);
    32. }
    33. else
    34. {
    35. if (Mission::IsObjectiveAccomplished(OBJECTIVE_B))
    36. Mission::SetObjectiveAccomplished(OBJECTIVE_B, false);
    37. }
    38. return MISSION_RUNNING;
    39. }
    40. };
    Display All
    • void Mission::AddObjective(const char *Name_); adds a new mission condition.
    • void Mission::RemoveObjective(const char *Name_); deletes an existing mission condition from the list.
    • void Mission::RemoveAllObjectives(); clears all mission conditions.
    • bool Mission::HasObjective(const char *Name_); asks whether there is an mission condition.
    • void Mission::SetObjectiveAccomplished(const char *Name_, bool State_); has a "true" as a green, a "false" as a red.
    • bool Mission::IsObjectiveAccomplished(const char *Name_); is intended as a test and "asks for" whether the condition has been met.
    • int Mission::GetCounter(const char *Counter_); queries the value of a counter.
    To ask if the condition was not fulfilled, put a "!" (exclamation mark) at the beginning.

    if (!Mission::IsObjectiveAccomplished(OBJECTIVE_A));


    Strings are texts or names which are usually saved in an XML file. These names are collections of many different things. Here they are often names of objects, persons, houses, triggers, virtual objects, etc. The collection of the strings with the above "const char *" allows a quick modification of certain names or values and simplifies the scripting. Also, a good "const char *" fixes an unsightly error in EMERGENCY 3, as well as EMERGENCY 4 script interpreter, which occurs when the script is closed and a name is duplicated. For further information see the article error messages (EM4).

    Since all "const char *" are valid globally for a script, they must be set via the newly created base class. Strings are specified in "const char STRINGNAME [] =" object_name ";". Important as always is the exact syntax!

    Source Code

    1. const char NAME_CRASHCARS[] = "unfallfahrzeug";
    2. object Mission01 : MissionScript
    3. {
    4. Mission01()
    5. {}
    6. ~Mission01()
    7. {}
    8. };
    In this example, the object is named "unfallfahrzeug" on the mission map.
    • NAME_CRASHCARS Is the name used in the script.
    • unfallfahrzeug Is the name of the object on the map.

    Predefined methods

    In mission scripts, there are predefined methods that can be used to query certain things directly. These are listed below:

    void Start()

    Source Code

    1. void Start()
    2. {
    3. }

    void Start()“ is called once at the start of the mission. Perfect for defining arrays at the beginning, which you need over the entire mission script.

    void Update()

    Source Code

    1. void Update()
    2. {
    3. }

    void Update()“ is executed once every tick. Here you should be careful about which functions are executed. Under certain circumstances the performance deteriorates massively. Alternatively, a desired interval timer can also be used.

    void OnTrigger()

    Source Code

    1. void OnTrigger(const char *Trigger, Actor *Collider)
    2. {
    3. }

    If a trigger is activated, it is called here. With „*Trigger“ you can find out which trigger was executed and „*Collider“ Is the actor that collides with the trigger.


    Source Code

    1. void OnTrigger(const char *Trigger, Actor *Collider)
    2. {
    3. if (Trigger->HasName("Trigger_01"))
    4. {
    5. if (Collider->GetType() == ACTOR_PERSON)
    6. {
    7. Person p(Collider);
    8. p.Kill();
    9. }
    10. }
    11. }
    Display All

    void OnTimer()

    Source Code

    1. void OnTimer(const char *TimerName, float TimeInSec)
    2. switch(TimerName)
    3. case "nameDesTimers":
    4. // Anweisungen
    5. break;
    6. }
    7. }

    The "OnTimer ()" function is called when a timer has ended or an interval timer has reached its interval limit."void OnTimer()" goes along with "Mission::StartSingleTimer(„nameDesTimers“, 5.f);" and "Mission::StartIntervalTimer(„nameDesTimers“, 5.f);". The floats (5.f, abbreviation of 5.0f) indicate seconds. In the SingleTimer, the 5.f indicates how long the timer is running before it is terminated and the timer is executed every five seconds in the IntervalTimer.

    MissionState GetMissionState()

    Source Code

    1. MissionState GetMissionState()
    2. {
    3. return MISSION_RUNNING;
    4. }

    In MissionState, there are usually counters, e.g. Check whether there are still injured persons on the mission card or still burn buildings. „GetMissionState()“ is a similar function to „void Update()“ and is called continuously.

    Possible tasks for this function are:

    Gives the game the information that there is no change in the mission's success or failure.

    Gives the game the information that if this counter or bool is true, that game was successful.

    return MISSION_FAILED;
    Gives the game the information that the mission failed if this counter or bool is true.

    ActionCallbackResult OnPostAction()

    Source Code

    1. ActionCallbackResult OnPostAction(const char *Action, ActionCallback* Data)
    2. {
    3. switch(Action)
    4. {
    5. case "EActionUse" :
    6. {
    7. }
    8. break;
    9. }
    10. return ACTION_CONTINUE;
    11. }
    Display All

    With this rather complex function it is possible to find out what actions have been carried out by the emergency personnel. In the example above, the "Benutzen" action is executed. An exact list of all possible action names can be found at EActions (EM4). Here, the „ActionCallbackResults“ are briefly explained. There are different ways of callingback results.

    ActionCallbackResult OnPostAction()

    Invoked when an action has been executed and terminated (e.g., a firefighter who has used the power box).

    ActionCallbackResult OnPreAction()

    Wird aufgerufen kurz bevor eine EAction ausgeführt wird (e.g. If the fireman has to run to the power box first, then PreAction is executed with respect to „EActionUse“, after the fireman turns to the power box and before he starts using the electric box).

    ActionCallbackResult OnAbortAction()
    Runs only when the player interrupts his units during an action.

    1,809 times viewed