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.
void Start()
{
//Block//Vehicles////////////////////////////////////////////////////////////////////////////////
VehicleList vl("Fahrzeug_1"); //Name of the vehicle on the map
if(vl.GetNumVehicles() == 0)
System::Log("Vehicle not found: %s", vl.GetVehicle(0)->GetName());
else
{
Vehicle v(vl.GetVehicle(0));
v.SetSpeed(10.0f); //Speed value
}
//Block//Vehicles////////////////////////////////////////////////////////////////////////////////
//If there are additional vehicles, copy the block and change values
//Block//Dispatchers////////////////////////////////////////////////////////////////////////////////
PersonList pl("Disponent_1");
if(pl.GetNumPersons() == 0)
System::Log("Dispatcher not found: %s", pl.GetPerson(0)->GetName());
else
Game::AddToGroup(pl.GetPerson(0), 0); //Last number is equal to the code block
//0 equal to code block 1
//1 equal to code block 2
//2 equal to code block 3
//...
//Block//Dispatchers////////////////////////////////////////////////////////////////////////////////
//If where should be additional dispatchers, copy the block and change values
};
bool OnLoad()
{
Start();
Process::Kill();
return true;
}
Display More
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
VehicleList vl("ELW_Haupt"); //Name of the ELW (battalion chief) of the fire department on the map
if(vl.GetNumVehicles() == 0)
System::Log("Vehicle not found: %s", vl.GetVehicle(0)->GetName());
else
{
Vehicle v(vl.GetVehicle(0));
v.SetSpeed(12.0f); //Value of speed
}
VehicleList vl("DLK_Haupt"); //Name of the DLK (aerial ladder vehicle) of the fire department on the map
if(vl.GetNumVehicles() == 0)
System::Log("Vehicle not found: %s", vl.GetVehicle(0)->GetName());
else
{
Vehicle v(vl.GetVehicle(0));
v.SetSpeed(9.0f); //Value of speed
}
VehicleList vl("HLF_Haupt"); //Name of the HLF (rescue squad) of the fire department on the map
if(vl.GetNumVehicles() == 0)
System::Log("Vehicle not found: %s", vl.GetVehicle(0)->GetName());
else
{
Vehicle v(vl.GetVehicle(0));
v.SetSpeed(10.0f); //Value of speed
}
Display More
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.
VehicleList vl("MTW_FFW"); //Name of the MTW of the volunteer fire department
if(vl.GetNumVehicles() == 0)
System::Log("Vehicle not found: %s", vl.GetVehicle(0)->GetName());
else
{
Vehicle v(vl.GetVehicle(0));
v.SetSpeed(12.0f); //Value of speed
}
VehicleList vl("LF16_FFW"); //Name of the LF of the volunteer fire department
if(vl.GetNumVehicles() == 0)
System::Log("Vehicle not found: %s", vl.GetVehicle(0)->GetName());
else
{
Vehicle v(vl.GetVehicle(0));
v.SetSpeed(8.0f); //Value of speed
}
Display More
Rescue station
We use the same procedure again.
VehicleList vl("RTW1"); //Name of the first ambulance
if(vl.GetNumVehicles() == 0)
System::Log("Vehicle not found: %s", vl.GetVehicle(0)->GetName());
else
{
Vehicle v(vl.GetVehicle(0));
v.SetSpeed(11.0f); //Value of speed
}
VehicleList vl("RTW2"); //Name of the second ambulance
if(vl.GetNumVehicles() == 0)
System::Log("Vehicle not found: %s", vl.GetVehicle(0)->GetName());
else
{
Vehicle v(vl.GetVehicle(0));
v.SetSpeed(11.0f); //Value of speed
}
VehicleList vl("NEF"); //Name of the emergency doctors vehicle
if(vl.GetNumVehicles() == 0)
System::Log("Vehicle not found: %s", vl.GetVehicle(0)->GetName());
else
{
Vehicle v(vl.GetVehicle(0));
v.SetSpeed(13.0f); //Value of speed
}
Display More
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.
PersonList pl("Disponent_1"); //Name of the first dispatcher
if(pl.GetNumPersons() == 0)
System::Log("Dispatcher not found: %s", pl.GetPerson(0)->GetName());
else
Game::AddToGroup(pl.GetPerson(0), 0); //Dispatcher on code block 1
PersonList pl("Disponent_2"); //Name of the second dispatcher
if(pl.GetNumPersons() == 0)
System::Log("Dispatcher not found: %s", pl.GetPerson(0)->GetName());
else
Game::AddToGroup(pl.GetPerson(0), 1); //Dispatcher on code block 2
PersonList pl("Disponent_3"); //Name of the third dispatcher
if(pl.GetNumPersons() == 0)
System::Log("Dispatcher not found: %s", pl.GetPerson(0)->GetName());
else
Game::AddToGroup(pl.GetPerson(0), 2); //Dispatcher on code block 3
Display More
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
void Start()
{
VehicleList vl("ELW_Haupt"); //Name of the ELW (battalion chief) of the fire department on the map
if(vl.GetNumVehicles() == 0)
System::Log("Vehicle not found: %s", vl.GetVehicle(0)->GetName());
else
{
Vehicle v(vl.GetVehicle(0));
v.SetSpeed(12.0f); //Value of speed
}
VehicleList vl("DLK_Haupt"); //Name of the DLK (aerial ladder vehicle) of the fire department on the map
if(vl.GetNumVehicles() == 0)
System::Log("Vehicle not found: %s", vl.GetVehicle(0)->GetName());
else
{
Vehicle v(vl.GetVehicle(0));
v.SetSpeed(9.0f); //Value of speed
}
VehicleList vl("HLF_Haupt"); //Name of the HLF (rescue squad) of the fire department on the map
if(vl.GetNumVehicles() == 0)
System::Log("Vehicle not found: %s", vl.GetVehicle(0)->GetName());
else
{
Vehicle v(vl.GetVehicle(0));
v.SetSpeed(10.0f); //Value of speed
}
VehicleList vl("MTW_FFW"); //Name of the MTW of the volunteer fire department
if(vl.GetNumVehicles() == 0)
System::Log("Vehicle not found: %s", vl.GetVehicle(0)->GetName());
else
{
Vehicle v(vl.GetVehicle(0));
v.SetSpeed(12.0f); //Value of speed
}
VehicleList vl("LF16_FFW"); //Name of the LF of the volunteer fire department
if(vl.GetNumVehicles() == 0)
System::Log("Vehicle not found: %s", vl.GetVehicle(0)->GetName());
else
{
Vehicle v(vl.GetVehicle(0));
v.SetSpeed(8.0f); //Value of speed
}
VehicleList vl("RTW1"); //Name of the first ambulance
if(vl.GetNumVehicles() == 0)
System::Log("Vehicle not found: %s", vl.GetVehicle(0)->GetName());
else
{
Vehicle v(vl.GetVehicle(0));
v.SetSpeed(11.0f); //Value of speed
}
VehicleList vl("RTW2"); //Name of the second ambulance
if(vl.GetNumVehicles() == 0)
System::Log("Vehicle not found: %s", vl.GetVehicle(0)->GetName());
else
{
Vehicle v(vl.GetVehicle(0));
v.SetSpeed(11.0f); //Value of speed
}
VehicleList vl("NEF"); //Name of the emergency doctors vehicle
if(vl.GetNumVehicles() == 0)
System::Log("Vehicle not found: %s", vl.GetVehicle(0)->GetName());
else
{
Vehicle v(vl.GetVehicle(0));
v.SetSpeed(13.0f); //Value of speed
}
PersonList pl("Disponent_1"); //Name of the first dispatcher
if(pl.GetNumPersons() == 0)
System::Log("Dispatcher not found: %s", pl.GetPerson(0)->GetName());
else
Game::AddToGroup(pl.GetPerson(0), 0); //Dispatcher on code block 1
PersonList pl("Disponent_2"); //Name of the second dispatcher
if(pl.GetNumPersons() == 0)
System::Log("Dispatcher not found: %s", pl.GetPerson(0)->GetName());
else
Game::AddToGroup(pl.GetPerson(0), 1); //Dispatcher on code block 2
PersonList pl("Disponent_3"); //Name of the third dispatcher
if(pl.GetNumPersons() == 0)
System::Log("Dispatcher not found: %s", pl.GetPerson(0)->GetName());
else
Game::AddToGroup(pl.GetPerson(0), 2); //Dispatcher on code block 3
};
bool OnLoad()
{
Start();
Process::Kill();
return true;
}
Display More
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.
const char ICON[] = "";
const char CURSOR[] = "";
const char VEHICLE_NAME[] = "";
const char VIRTUAL_OBJECT[] = "";
const char SOUND[] = "";
const char MESSAGE[] = "";
const char NUM_PERSON[] = "";
const char PROTO_PERSON[] = "";
float WAIT_PERSON = 5;
float WAIT_VEHICLE = 20;
bool vehiclefull = false;
object Alarm_ELW : CommandScript
{
Alarm_ELW()
{
SetIcon(ICON);
SetCursor(CURSOR);
SetValidTargets(TARGET_STREET);
SetValidTargets(TARGET_FLOOR);
}
bool CheckTarget(GameObject *Caller, Actor *Target, int childID)
{
return true;
}
void PushActions(GameObject *Caller, Actor *Target, int childID)
{
Vector APos = Game::GetCommandPos();
VehicleList vl(VEHICLE_NAME);
if(gol.GetNumObjects()==0)
{
System::Log("%s not found", VEHICLE_NAME);
return;
}
Vehicle v(vl.GetVehicle(0));
ActorList al(VIRTUAL_OBJECT);
if(al.GetNumActors()==0)
{
System::Log("%s not found", VIRTUAL_OBJECT);
return;
}
Vector SPos = al.GetActor(0)->GetPosition();
v.SetUserData(1);
Audio::PlaySample(SOUND);
Mission::PlayHint(MESSAGE);
for(int i = 1; i <= NUM_PERSON; i++)
{
Person p = Game::CreatePerson(PROTO_PERSON, "Unnamed");
p.SetRole(ROLE_SQUAD);
p.SetUpgradeLevel(3);
Game::FindFreePosition(&p, spawnp, 100.f);
p.SetPosition(SPos);
p.PushActionShowHide(ACTION_NEWLIST, true);
p.PushActionWait(ACTION_APPEND, WAIT_PERSON);
p.PushActionShowHide(ACTION_APPEND, false);
p.PushActionMove(ACTION_APPEND, v.GetPosition());
p.PushActionEnterCar(ACTION_APPEND, &v);
if(i == NUM_PERSON)
vehiclefull = true;
}
if(vehiclefull)
{
v.PushActionWait(ACTION_NEWLIST, WAIT_VEHICLE);
v.PushActionMove(ACTION_APPEND, Apos);
}
}
};
Display More
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.
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.
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.
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!