Chapter 6: Scripting

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 the scripting for EMERGENCY 4.
    In this part of the master tutorial the scripting for EMERGENCY 4 is the main topic. You don't need any programming skills in order to change scripts, but you should read the comments in the scripts very carefully to make the right changes. As mentioned in the chapter 'The first concept' we will include a start script, a dispatch script and aparking script into the modification.


    1 The start script


    The start script will be loaded at the start of the freeplay mode, immediately after the loading screen. For this modification we want to place the vehicles directly onto the map, so the automatic positioning of the vehicle won't be needed in this project. In our script, the script will assign speed limits and key bindings to the vehicles.

    At this point we won't explain this very shorty script. Adding additional vehicles is more interesting for the further modding steps. At first we start with the three vehicles of the fire department: The ELW (battalion chief), DLK (aerial ladder vehicle) and HLF (rescue squad). We have assigned the number of seats and necessary commands in the editor. But we can't assign the vehicle speed in the editor - this part will be done by the start script.


    1.1 Vehicles in the start script


    Fire department

    We've chosen the speeds 12 for the ELW, 9 for the DLK and 10 for the HLF. You can change this values at any time later. Double check the names in the script, otherwise it won't work!


    Volunteer fire department
    Here we use the same procedure as for the fire department.

    Rescue station
    We use the same procedure again.

    1.2 Dispatcher in the start script


    The dispatcher will be availabe to dispatch units. For this reason, we will assign the dispatch commands to the dispatcher later. In this example we'll use three different dispatchers. The first one will handle all battalion alarms, the second one only fire department and the third one rescue units.

    The names of the vehicles and persons have to be equal in the editor and the script. Otherwise there will be malfunctions!


    1.3 The finnished start script


    If there are any failures and you aren't able to solve the problem by your own, you can open a new topic in the Scripting department of the EMERGENCY community message boards. You should attach your complete script and the logfile (can be found in the EMERGENCY 4 main folder) in order to get quick help.


    This information is important for all problems with scripts, not only for the start script.


    2 The dispatch scripts

    2.1 Create the first dispatcher


    As mentioned, we'll use three dispatchers. The first dispatcher can dispatch all battallions, the second one can dispatch all fire department vehicles (fire department and volunteer fire department). There's a different between the two departments, because at the regular fire department the fire fighters will stay on the station all day and the volunteer fire fighters have to get to the station first. The third dispatcher can dispatch all rescue service vehicles. Technically it's the same system as for the fire department. Below you can find the basic version of the script, we will make some changes later.


    This script won't be changed that much for usual. The only changse will be made in the first part. The script was programmed in a very clean way, so every variable, duration, prototype and name is defined in the first eight lines of the script.


    2.2 Add additional dispatcher


    The third dispatcher is responsible for the mecial services. We'll start with an ambulance.

    Code
    const char ICON[] = "RTW1";
    const char CURSOR[] = "RTW1";
    const char VEHICLE_NAME[] = "";
    const char VIRTUAL_OBJECT[] = "";
    const char SOUND[] = "";
    const char MESSAGE[] = "";
    const char NUM_PERSON[] = "";
    const char PROTO_PERSON[] = "";

    The variables ICON and CURSOR are the names of the graphics, which will be displayed in the interface by clicking the vehicle or person. You'll only have to assign a name, the game will choose the corresponding graphic from the UI folder.


    const char VEHICLE_NAME[] = "RTW1";


    Equal to the start script, the name of the vehicle will be assigned with this step. The game knows then, to which vehicle the persons have to go.


    const char VIRTUAL_OBJECT[] = "Spawn_RTW1";


    The variable VIRTUAL_OBJECT is the name of the Virtual Object, where the persons will be generated.

    Code
    const char SOUND[] = "mod:Audio/Alarm/Piepser.wav";
    const char MESSAGE[] = "Alarm for ambulance 1";

    At this point, you can assign a sound file - e.g. for the alarm sound - to the action. You'll have to insert the path to the .wav file. Usually sound files will be placed in the folder Audio. But you can place them where you want, if you assign the correct path. The variable Message defines a text which will be shown in the blue information window in the upper part of the screen.

    Code
    const char NUM_PERSON[] = "2";
    const char PROTO_PERSON[] = "mod:Prototypes/Persons/Ambulance/paramedic.e4p";

    Here you can define the number of persons which will be generated by the script. An ambulance has two persons for common. Below you can define to path of the prototype file of the persons. Repeat this steps for the second ambulance, the emergency doctors vehicle, the battalion chiefs car, the aerial ladder vehicle and the engine.


    If you test the script and persons won't be generated, check the path at first!