Mission scripts (EM4)

Information: The EMERGENCY community board is completely free and is financed by advertisement. Please deactivate adblocker if you use this site. Thank you!
Note about the webdisk: Downloading larger files should be possible again.
  • 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.).


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


    Code
    object Mission01 : MissionScript
    {
    
    
    };
    • 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.


    2 Constructor / destructor


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

    Code
    object Mission01 : MissionScript
    {
    	Mission01()
    	{}
    
    
    	~Mission01()
    	{}
    };

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


    • 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));


    4 Strings


    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!

    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.


    5 Predefined methods


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


    void Start()

    Code
    void Start()
    {
    }


    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()

    Code
    void Update()
    {
    }


    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()

    Code
    void OnTrigger(const char *Trigger, Actor *Collider)
    {
    }


    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.


    Example:


    void OnTimer()

    Code
    void OnTimer(const char *TimerName, float TimeInSec)
        switch(TimerName)
            case "nameDesTimers":
                // Anweisungen
            break;
        }
    }


    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()

    Code
    MissionState GetMissionState()
    {
     return MISSION_RUNNING;
    }


    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:


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


    return MISSION_SUCCEEDED;
    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()


    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.