if not SERVER then return end

-- MRP Fix: Disable entering LVS vehicles if health is below 0 or destroyed
hook.Add( "LVS.CanPlayerDrive", "MRP_LVS_HealthFix", function( ply, vehicle )
    if not IsValid( vehicle ) then return end

    -- Check if vehicle is destroyed or has negative health
    if vehicle.IsDestroyed and vehicle:IsDestroyed() then
        if not ply:IsAdmin() then
            ply:Notify("Техника уничтожена и не может управляться!")
            return false
        end
    end

    if vehicle.GetHP and vehicle:GetHP() <= 0 then
        if not ply:IsAdmin() then
            ply:Notify("Техника слишком сильно повреждена для эксплуатации!")
            return false
        end
    end
end )

-- Prevents sitting in passenger seats of destroyed LVS vehicles
hook.Add( "CanPlayerEnterVehicle", "MRP_LVS_SeatSafety", function( ply, vehicle )
    local lvsVehicle = vehicle.lvsGetVehicle and vehicle:lvsGetVehicle() or vehicle:GetParent()

    if IsValid( lvsVehicle ) and lvsVehicle.LVS then
        if (lvsVehicle.IsDestroyed and lvsVehicle:IsDestroyed()) or (lvsVehicle.GetHP and lvsVehicle:GetHP() <= 0) then
            if not ply:IsAdmin() then
                ply:Notify("Техника уничтожена!")
                return false
            end
        end
    end
end )
