hook.Add( "PlayerButtonDown", "!!!lvsSeatSwitcherButtonDown", function( ply, button )
	local vehicle = ply:lvsGetVehicle()

	if not IsValid( vehicle ) then return end

	local CurPod = ply:GetVehicle()

	if button == KEY_1 then
		if ply == vehicle:GetDriver() then
			if vehicle:GetlvsLockedStatus() then
				vehicle:UnLock()
			else
				vehicle:Lock()
			end
		else
			if IsValid( vehicle:GetDriver() ) then return end

			if vehicle:GetAI() then
				vehicle:SetAI( false )
				vehicle:SetAIGunners( true )
			end

			if hook.Run( "LVS.CanPlayerDrive", ply, vehicle ) == false then
				hook.Run( "LVS.OnPlayerCannotDrive", ply, vehicle )
				return
			end

			ply:ExitVehicle()

			local DriverSeat = vehicle:GetDriverSeat()

			if not IsValid( DriverSeat ) then return end

			if hook.Run( "LVS.OnPlayerRequestSeatSwitch", ply, vehicle, CurPod, DriverSeat ) == false then return end

			timer.Simple( 0, function()
				if not IsValid( vehicle ) or not IsValid( ply ) then return end
				if IsValid( vehicle:GetDriver() ) or not IsValid( DriverSeat ) or vehicle:GetAI() then return end

				ply:EnterVehicle( DriverSeat )
				vehicle:AlignView( ply )
				vehicle:OnSwitchSeat( ply, CurPod, DriverSeat )
			end)
		end
	else
		for _, Pod in pairs( vehicle:GetPassengerSeats() ) do
			if not IsValid( Pod ) or Pod:GetNWInt( "pPodIndex", 3 ) ~= LVS.pSwitchKeys[ button ] then continue end

			local Driver = Pod:GetDriver()

			if IsValid( Driver ) then
				if Driver == ply then
					for _, DoorHandler in ipairs( vehicle:GetDoorHandlers() ) do
						if DoorHandler:GetLinkedSeat() ~= Pod or not DoorHandler:IsOpen() then continue end

						DoorHandler:Close( ply )
					end
				end

				continue
			end

			if hook.Run( "LVS.OnPlayerRequestSeatSwitch", ply, vehicle, CurPod, Pod ) == false then continue end

			ply:ExitVehicle()

			timer.Simple( 0, function()
				if not IsValid( Pod ) or not IsValid( ply ) then return end
				if IsValid( Pod:GetDriver() ) then return end

				ply:EnterVehicle( Pod )
				vehicle:AlignView( ply, true )
				vehicle:OnSwitchSeat( ply, CurPod, Pod )
			end)
		end
	end
end )
