Page MenuHomeFeedback Tracker

"Failed Engine start" sounds not working on Vehicles
Closed, ResolvedPublic

Description

Vehicles used to have different sounds if the Engine failed to start, depending on if a Spark Plug, a Battery or fuel was missing.
This is not the case anymore, but i think it's not intended as the functionality is still there, just never executes since it's getting called on Server only.
I already made a fix for that, but maybe you guys can come up with a better or more slick solution.

	override bool OnBeforeEngineStart()
	{
		EntityAI item = null;
		CarEngineSoundState state;
		Param1<int> newState;
		
		if ( IsVitalAttachmentDamaged() )
		{
			state = CarEngineSoundState.NONE;
			newState = new Param1<int>( state );
			GetGame().RPCSingleParam(this, RPC_CARFAIL, newState, true);
			return false;
		}
		
		if (GetFluidFraction(CarFluid.FUEL) <= 0)
		{
			state = CarEngineSoundState.START_NO_FUEL;
			newState = new Param1<int>( state );
			GetGame().RPCSingleParam(this, RPC_CARFAIL, newState, true);
			return false;
		}
		
		if (IsVitalCarBattery() || IsVitalTruckBattery())
		{
			item = GetBattery();
			if (!item || (item && (item.IsRuined() || item.GetCompEM().GetEnergy() < m_BatteryEnergyStartMin)))
			{
				state = CarEngineSoundState.START_NO_BATTERY;
				newState = new Param1<int>( state );
				GetGame().RPCSingleParam(this, RPC_CARFAIL, newState, true);
				return false;
			}
		}

		if (IsVitalSparkPlug())
		{
			item = FindAttachmentBySlotName("SparkPlug");
			if (!item || (item && item.IsRuined()))
			{
				state = CarEngineSoundState.START_NO_SPARKPLUG;
				newState = new Param1<int>( state );
				GetGame().RPCSingleParam(this, RPC_CARFAIL, newState, true);
				return false;
			}
		}
	
		if (IsVitalGlowPlug())
		{
			item = FindAttachmentBySlotName("GlowPlug");
			if (!item || (item && item.IsRuined()))
			{
				state = CarEngineSoundState.START_NO_SPARKPLUG;
				newState = new Param1<int>( state );
				GetGame().RPCSingleParam(this, RPC_CARFAIL, newState, true);
				return false;
			}
		}
		
		if (!m_EngineBeforeStart)
		{
			m_EngineBeforeStart = true;
			HandleEngineSound(CarEngineSoundState.STARTING);
		}

		return true;
	}



	override void OnRPC(PlayerIdentity sender, int rpc_type,ParamsReadContext ctx) 
	{
		super.OnRPC(sender, rpc_type,ctx);
		
		switch (rpc_type)
        {
            case RPC_CARFAIL:
            {
                Param1<int> carfail_params;
                if (!ctx.Read(carfail_params))
                {
                    break;
                }
                switch (carfail_params.param1)
                {
                    case CarEngineSoundState.START_NO_FUEL:
						PlayCarFailNoFuel();
					break;
						
					case CarEngineSoundState.START_NO_BATTERY:
						PlayCarFailNoBattery();
					break;
						
					case CarEngineSoundState.START_NO_SPARKPLUG:
						PlayCarFailNoSparkPlug();
					break;
					
					case CarEngineSoundState.NONE:
						PlayCarFailNoSparkPlug();
					break;
				}
			}
		}
    }

On top of that i found that almost all Vanilla Vehicles have their

engine_failed_start_battery_SoundShader

volume=0

Details

Severity
Trivial
Resolution
Open
Reproducibility
Always
Operating System
Windows 10 x64
Category
Sound
Steps To Reproduce

Try to start any Vehicle without either a Spark Plug (or Glow Plug), a Battery or empty Fuel tank.
No "failed starting sound"

Event Timeline

Tyson created this task.Nov 28 2023, 2:08 PM
lava76 added a subscriber: lava76.Nov 28 2023, 2:28 PM
Lad added a subscriber: Lad.Nov 28 2023, 9:07 PM
Geez changed the task status from New to Awaiting internal Testing.Nov 29 2023, 12:35 PM
lava76 added a comment.Dec 5 2023, 1:18 PM

Interim solution

modded class ActionStartEngine
{
	override void OnStartClient(ActionData action_data)
	{
		super.OnStartClient(action_data);

		HumanCommandVehicle vehCommand = action_data.m_Player.GetCommand_Vehicle();
		if (vehCommand)
		{
			Transport trans = vehCommand.GetTransport();
			if (trans)
			{
				CarScript car;
				if (Class.CastTo(car, trans))
				{
					GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(car.OnBeforeEngineStart, 500);  // slight delay to sync sound with hand animation
				}
			}
		}
	}
}

modded class CarScript
{
	override bool OnBeforeEngineStart()
	{
		bool ret = super.OnBeforeEngineStart();

		m_EngineStartDoOnce = false;  // make engine start fail sounds play reliably, not just every other time engine is attempted to start

		return ret;
	}
}
Geez closed this task as Resolved.Wed, Apr 3, 11:18 AM
Geez claimed this task.
Geez added a subscriber: Geez.

Resolved for the 1.26 update.