Not all plans offer loans, you definately need to check whether your plan does or not. If your plan offers loans, you are not eligible for a hardship withdrawal if you are currently eligible to take a loan from the plan. You would have to take the loan first. If the amount you need exceeds your maximum loan available, you may be able to take a hardship in addition to the loan.
Loans come first.
This assumes your plans allows loans and hardship withdrawals.