Skip to content
View in the app

A better way to browse. Learn more.

Learn more

Vehicles Spawning without Commands

So I'e decided to use the last of my remaining free time to update a mod of mine. I am trying to create my own "Auto Spawn" script for freeplay. When freeplay loads, I want all vehicles to spawn in their parking spots. I've managed to get them all to spawn (they don't face the right direction but thats a fix for another time), but the biggest problem that I need some help with is that they spawn without ANY commands. I can select the vehicle without a problem, but no commands show up. When I attempt to forcibly add a commands like:

v.AssignCommand("MoveTo");

Still nothing appears. Not even the MoveTo command I'm explicitly adding.

 

All vehicles are affected by this, and all vehicles have their commands set in the editor.

 

Here is my code thus far:

//******************************************************************************************
// 		Northview South County - VEHICLE SPAWN SCRIPT v1.0
//
//		Author(s): Chris07
//		Reuse without explicit permission from author is forbidden!
//
//******************************************************************************************

//Vehicle Prototype Delcarations
const char PROTO_ENGINE01[]			= "mod:Prototypes/Vehicles/02 LA Fire Department/fire_engine1.e4p";
const char PROTO_ENGINE02[]			= "mod:Prototypes/Vehicles/02 LA Fire Department/fire_engine2.e4p";
const char PROTO_RENGINE01[]		= "mod:Prototypes/Vehicles/02 LA Fire Department/rescue_engine1.e4p";
const char PROTO_RENGINE02[]		= "mod:Prototypes/Vehicles/02 LA Fire Department/rescue_engine2.e4p";
const char PROTO_BC[]				= "mod:Prototypes/Vehicles/02 LA Fire Department/battalion_chief_vehicle.e4p";
const char PROTO_SQUAD[]			= "mod:Prototypes/Vehicles/02 LA Fire Department/squad_1.e4p";
const char PROTO_HEAVYRESCUE[]		= "mod:Prototypes/Vehicles/02 LA Fire Department/Rescue.e4p";
const char PROTO_RESCUECRANE[]		= "mod:Prototypes/Vehicles/02 LA Fire Department/heavy_rescue_crane.e4p";
const char PROTO_HAZMAT[]			= "mod:Prototypes/Vehicles/02 LA Fire Department/hazmat_squad.e4p";
const char PROTO_BRUSH[]			= "mod:Prototypes/Vehicles/02 LA Fire Department/brush_truck.e4p";
const char PROTO_TANKER[]			= "mod:Prototypes/Vehicles/02 LA Fire Department/water_tanker.e4p";

const char PROTO_AMBULANCE01[]		= "mod:Prototypes/Vehicles/01 LA Ambulance/amrambulance01.e4p";
const char PROTO_AMBULANCE02[]		= "mod:Prototypes/Vehicles/01 LA Ambulance/amrambulance02.e4p";
const char PROTO_AMBULANCE03[]		= "mod:Prototypes/Vehicles/01 LA Ambulance/amrambulance03.e4p";
const char PROTO_AMBULANCE04[]		= "mod:Prototypes/Vehicles/01 LA Ambulance/amrambulance04.e4p";
const char PROTO_AMBULANCE05[]		= "mod:Prototypes/Vehicles/01 LA Ambulance/amrambulance05.e4p";
const char PROTO_EMS_SUP[]			= "mod:Prototypes/Vehicles/01 LA Ambulance/supervisor.e4p";

const char PROTO_PATROL01[] 		= "mod:Prototypes/Vehicles/03 LA Police/cv_patrol1.e4p";
const char PROTO_PATROL02[] 		= "mod:Prototypes/Vehicles/03 LA Police/cv_patrol2.e4p";
const char PROTO_PATROL03[] 		= "mod:Prototypes/Vehicles/03 LA Police/dodge_charger_patrol3.e4p";
const char PROTO_PATROL04[] 		= "mod:Prototypes/Vehicles/03 LA Police/cv_patrol4.e4p";
const char PROTO_PATROL05[] 		= "mod:Prototypes/Vehicles/03 LA Police/dodge_charger_patrol5.e4p";
const char PROTO_PATROL06[] 		= "mod:Prototypes/Vehicles/03 LA Police/cv_patrol6.e4p";
const char PROTO_UMPCPATROL[] 		= "mod:Prototypes/Vehicles/03 LA Police/ATF_cv.e4p";
const char PROTO_SUVPATROL[] 		= "mod:Prototypes/Vehicles/03 LA Police/suv_lapd.e4p";
const char PROTO_SWATUMPC[] 		= "mod:Prototypes/Vehicles/03 LA Police/cv_umpc.e4p";
const char PROTO_SWATRESCUE[] 		= "mod:Prototypes/Vehicles/03 LA Police/rescue_truck02_lapd.e4p";
const char PROTO_BOMBSQUAD[] 		= "mod:Prototypes/Vehicles/03 LA Police/suv_bomb_squad.e4p";
const char PROTO_TRANSPORTVAN[] 	= "mod:Prototypes/Vehicles/03 LA Police/svan1.e4p";

//VO Declarations (Parking Spots)
const char VO_ENGINE01[]			= "E81_1";
const char VO_ENGINE02[]			= "E83_1";
const char VO_RENGINE01[]			= "E82_1";
const char VO_RENGINE02[]			= "E84_1";
const char VO_BC[]					= "BC11_1";
const char VO_SQUAD[]				= "S83_1"; 
const char VO_HEAVYRESCUE[]			= "HR81_1";
const char VO_RESCUECRANE[]			= "C81_1";
const char VO_HAZMAT[]				= "H81_1";
const char VO_BRUSH[]				= "B82_1";
const char VO_TANKER[]				= "T83_1";

const char VO_AMBULANCE01[]			= "M511_1";
const char VO_AMBULANCE02[]			= "M512_1";
const char VO_AMBULANCE03[]			= "M513_1";
const char VO_AMBULANCE04[]			= "M521_1";
const char VO_AMBULANCE05[]			= "M522_1";
const char VO_EMS_SUP[]				= "EMS5_1";

const char VO_PATROL01[]			= "7A1_1";
const char VO_PATROL02[]			= "7A2_1";
const char VO_PATROL03[]			= "7A3_1";
const char VO_PATROL04[]			= "7A4_1";
const char VO_PATROL05[]			= "7A5_1";
const char VO_PATROL06[] 			= "7A6_1";
const char VO_UMPCPATROL[] 			= "umpc_1";
const char VO_SUVPATROL[] 			= "7S1_1";
const char VO_SWATUMPC[] 			= "tac1_1";
const char VO_SWATRESCUE[] 			= "tac2_1";
const char VO_BOMBSQUAD[] 			= "eod_1";
const char VO_TRANSPORTVAN[] 		= "tac3_1";

//VO Declarations (Orientation Markers)
const char VO_ENGINE01_ORIENT[]			= "E81_2";
const char VO_ENGINE02_ORIENT[]			= "E83_2";
const char VO_RENGINE01_ORIENT[]		= "E82_2";
const char VO_RENGINE02_ORIENT[]		= "E84_2";
const char VO_BC_ORIENT[]				= "BC11_2";
const char VO_SQUAD_ORIENT[]			= "S83_2"; 
const char VO_HEAVYRESCUE_ORIENT[]		= "HR81_2";
const char VO_RESCUECRANE_ORIENT[]		= "C81_2";
const char VO_HAZMAT_ORIENT[]			= "H81_2";
const char VO_BRUSH_ORIENT[]			= "B82_2";
const char VO_TANKER_ORIENT[]			= "T83_2";

const char VO_AMBULANCE01_ORIENT[]		= "M511_2";
const char VO_AMBULANCE02_ORIENT[]		= "M512_2";
const char VO_AMBULANCE03_ORIENT[]		= "M513_2";
const char VO_AMBULANCE04_ORIENT[]		= "M521_2";
const char VO_AMBULANCE05_ORIENT[]		= "M522_2";
const char VO_EMS_SUP_ORIENT[]			= "EMS5_2";

const char VO_PATROL01_ORIENT[]			= "7A1_2";
const char VO_PATROL02_ORIENT[]			= "7A2_2";
const char VO_PATROL03_ORIENT[]			= "7A3_2";
const char VO_PATROL04_ORIENT[]			= "7A4_2";
const char VO_PATROL05_ORIENT[]			= "7A5_2";
const char VO_PATROL06_ORIENT[] 		= "7A6_2";
const char VO_UMPCPATROL_ORIENT[] 		= "umpc_2";
const char VO_SUVPATROL_ORIENT[] 		= "7S1_2";
const char VO_SWATUMPC_ORIENT[] 		= "tac1_2";
const char VO_SWATRESCUE_ORIENT[] 		= "tac2_2";
const char VO_BOMBSQUAD_ORIENT[] 		= "eod_2";
const char VO_TRANSPORTVAN_ORIENT[] 	= "tac3_2";

//Personnel Prototype Declarations
const char PROTO_[]			= "mod:Prototypes/Vehicles/01 LA Ambulance/ambulance01.e4p";

//Misc declaration
const char UNNAMED[]					= "Unnamed";

object SpawnVehiclesSP_FireEms : CommandScript
{
	SpawnVehiclesSP_FireEms()
	{
		//Nothing to do here
	}

	bool CheckPossible(GameObject *Caller)
	{
		return true;
	}

	bool CheckTarget(GameObject *Caller, Actor *Target, int childID)
	{
		return true;
	}

	void PushActions(GameObject *Caller, Actor *Target, int childID)
	{

		SpawnVehicle(PROTO_ENGINE01, VO_ENGINE01, 1);
		SpawnVehicle(PROTO_ENGINE02, VO_ENGINE02, 1);
      /*
		SpawnVehicle(PROTO_RENGINE01, VO_RENGINE01, 2);
		SpawnVehicle(PROTO_RENGINE02, VO_RENGINE02, 2);
		SpawnVehicle(PROTO_BC, VO_BC, 3);
		SpawnVehicle(PROTO_HEAVYRESCUE, VO_HEAVYRESCUE, 4);
		SpawnVehicle(PROTO_RESCUECRANE, VO_RESCUECRANE, 5);
		SpawnVehicle(PROTO_HAZMAT, VO_HAZMAT, 6);
		SpawnVehicle(PROTO_SQUAD, VO_SQUAD, 7);
		SpawnVehicle(PROTO_BRUSH, VO_BRUSH, 8);
		SpawnVehicle(PROTO_TANKER, VO_TANKER, 9);
	  */

	}

	void SpawnVehicle( const char *VehicleProto, const char *VehicleVO, int VehicleTypeID = -1 )
	{

		ActorList spawnList = Game::GetActors(VehicleVO);
		for(int i = 0; i < spawnList.GetNumActors(); i++)
		{
			Vector spawnLoc = spawnList.GetActor(0)->GetPosition();
			
			Vehicle v = Game::CreateVehicle(VehicleProto, UNNAMED);
			v.EnableBlueLights(false);
			v.SetPosition(spawnLoc);
			v.UpdatePlacement();

			switch( VehicleTypeID )	
			{
				case 1:
					v.SetMaxPassengers(6);
					v.SetSpeed(12.0f);
					v.SetCommandable(true);
					v.AssignCommand("MoveTo");
					v.AssignCommand("GoHome");
				break;
				default:
					v.EnableBlueLights(true); //Visually tell me that I missed you
			}
		}
	}
	
};

 

As for the Switch statement...I know it's working since the spawned vehicles have the correct number of seats set meaning the v.SetMaxPassengers(6); is being called.

 

Thanks for the help!

Featured Replies

  • Author

In an attempt to further figure out what the heck is going on I decided to remove the SpawnVehicle() function I made and try running things sequentially.

 

If I spawn the first vehicle, and only the first vehicle, then the vehicle appears with all of its commands. If I try and spawn more vehicles, it breaks and none of the spawned vehicles have commands.

 

	void PushActions(GameObject *Caller, Actor *Target, int childID)
	{

		//SpawnVehicle(PROTO_ENGINE01, VO_ENGINE01, 1);
		/*
		SpawnVehicle(PROTO_ENGINE02, VO_ENGINE02, 1);
		SpawnVehicle(PROTO_RENGINE01, VO_RENGINE01, 2);
		SpawnVehicle(PROTO_RENGINE02, VO_RENGINE02, 2);
		SpawnVehicle(PROTO_BC, VO_BC, 3);
		SpawnVehicle(PROTO_HEAVYRESCUE, VO_HEAVYRESCUE, 4);
		SpawnVehicle(PROTO_RESCUECRANE, VO_RESCUECRANE, 5);
		SpawnVehicle(PROTO_HAZMAT, VO_HAZMAT, 6);
		SpawnVehicle(PROTO_SQUAD, VO_SQUAD, 7);
		SpawnVehicle(PROTO_BRUSH, VO_BRUSH, 8);
		SpawnVehicle(PROTO_TANKER, VO_TANKER, 9);
		*/

		//This Block if ran by itself works just fine!
		ActorList spawnList01 = Game::GetActors(VO_ENGINE01);
		for(int i = 0; i < spawnList01.GetNumActors(); i++)
		{
			Vector spawnLoc = spawnList01.GetActor(0)->GetPosition();
			
			Vehicle v = Game::CreateVehicle(PROTO_ENGINE01, UNNAMED);
			v.EnableBlueLights(false);
			v.SetPosition(spawnLoc);
			v.UpdatePlacement();
			v.SetMaxPassengers(3);
			v.SetSpeed(12.0f);
			v.SetCommandable(true);
			v.AssignCommand("MoveTo");
			v.AssignCommand("GoHome");
		}
		//End
		ActorList spawnList02 = Game::GetActors(VO_ENGINE02);
		for(int i = 0; i < spawnList02.GetNumActors(); i++)
		{
			Vector spawnLoc = spawnList02.GetActor(0)->GetPosition();
			
			Vehicle v = Game::CreateVehicle(PROTO_ENGINE02, UNNAMED);
			v.EnableBlueLights(false);
			v.SetPosition(spawnLoc);
			v.UpdatePlacement();
			v.SetMaxPassengers(3);
			v.SetSpeed(12.0f);
			v.SetCommandable(true);
			v.AssignCommand("MoveTo");
			v.AssignCommand("GoHome");
		}

		ActorList spawnList03 = Game::GetActors(VO_RENGINE01);
		for(int i = 0; i < spawnList03.GetNumActors(); i++)
		{
			Vector spawnLoc = spawnList03.GetActor(0)->GetPosition();
			
			Vehicle v = Game::CreateVehicle(PROTO_RENGINE01, UNNAMED);
			v.EnableBlueLights(false);
			v.SetPosition(spawnLoc);
			v.UpdatePlacement();
			v.SetMaxPassengers(3);
			v.SetSpeed(12.0f);
			v.SetCommandable(true);
			v.AssignCommand("MoveTo");
			v.AssignCommand("GoHome");
		}

		ActorList spawnList04 = Game::GetActors(VO_RENGINE02);
		for(int i = 0; i < spawnList04.GetNumActors(); i++)
		{
			Vector spawnLoc = spawnList04.GetActor(0)->GetPosition();
			
			Vehicle v = Game::CreateVehicle(PROTO_RENGINE02, UNNAMED);
			v.EnableBlueLights(false);
			v.SetPosition(spawnLoc);
			v.UpdatePlacement();
			v.SetMaxPassengers(3);
			v.SetSpeed(12.0f);
			v.SetCommandable(true);
			v.AssignCommand("MoveTo");
			v.AssignCommand("GoHome");
		}

	}

 

  • Author

So, as it turns out...I'm really a bit of an idiot. I solved my issue, and it had nothing to do with my code.

 

The code works fine. I was making changes and reloading the mod without restarting Emergency 4 in between trials....which we all know causes weird behavior.

Give me a break though...I haven't done this in over a year!

I'm a bit rusty but its a lesson well learned. I also managed to remove some unnecessary clutter so the code is leaner and cleaner than before.

Thats fine dude, sometimes simple bugs get the best of us http://www.emergency-planet.com/uploads/emoticons/default_wink.png

Im open to continuing your paramedics mod. Bama has supplied me with information to create a more in depth treatment system that might make it into the upcoming iteration of Montana mod. If we can get a simple version working then its possible to get a complex one in.

I find that your use of a spawn function is interesting. I prefer to use the original LA command script to spawn things in missionscript. My reasoning is that the missionscript will have a smaller filesize if misc. code is kept to the command script portion. Its the same deal with my LWS. I was able to find a hybrid between missionscript and command that allowed me to have the script be kept in the commands to save lines, but Im still able to have the water gauge GUI work on my missionscript.

  • Author

I really want to come back to that mod but its a matter of free time. This is my last week off before a very tough year of classes for me. I really only found the time to update my current mod. The "Quick" update was suppsoed to take 1 day....2 days later and its still not done. The spawn script took all day for me to get working, then I discovered that creating a person and making them a passenger directly in a vehicle causes a bug where clicking on their portrait doesn't make them exit the vehicle. I solved that with a workaround...then today I spent figuring out how to animate ladder support legs. So I got that sorted out.

 

Long story short...quick updates = never as quick as you think.

 

Thats fine my dude, Im at the first semester of junior year college and the time crunch has kept me from working on Montana as I had hoped Id be able to. We all understand the struggle and Im more than happy to carry over where you leave off.

Guest
Reply to this topic...

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.