ProgressBar

The progress bar system provides visual feedback for long-running operations with smooth animations. Progress bars automatically animate from 0% to 100% over the specified duration.

Dark Circular Progress
Dark Linear Progress

progress

Display a progress bar with automatic animation and professional styling.

Parameters:

  • playerId (number, server-side only): Player server ID to send the progress bar to

  • options (table): Progress bar configuration options

    • duration (number): Duration in milliseconds for the progress to complete

    • label (string, optional): Text label to display (default: 'Loading...')

    • type (string, optional): Progress type - 'circular' or 'linear' (default: 'circular')

    • position (string, optional): Position on screen (default: from config)

    • showPercentage (boolean, optional): Whether to show percentage text (default: from config)

    • color (string, optional): Progress bar color - hex color or theme color (default: from config)

    • canCancel (boolean, optional): Whether the progress can be cancelled (default: false)

    • cancelKey (string, optional): Key to cancel progress (default: 'X')

    • id (string, optional): Custom progress bar ID (default: auto-generated)

    • size (string, optional): Progress bar size - 'small', 'medium', 'large' (default: 'medium')

    • thickness (number, optional): Progress bar thickness for circular type (default: 8)

    • backgroundColor (string, optional): Background color override

    • textColor (string, optional): Text color override

    • gradient (boolean, optional): Enable gradient effect (default: true)

    • animation (string, optional): Animation style - 'smooth', 'pulse', 'glow' (default: 'smooth')

Returns: number|boolean - Progress bar ID on success, false on failure

Example:

hideProgress

Hide the currently active progress bar immediately.

Returns: boolean - Success status

Example:

getProgressState

Get the current state of active progress bars.

Returns: table - Progress state information

  • active (boolean): Whether a progress bar is currently active

  • id (string): Current progress bar ID

  • progress (number): Current progress percentage (0-100)

  • duration (number): Total duration in milliseconds

  • elapsed (number): Elapsed time in milliseconds

  • canCancel (boolean): Whether current progress can be cancelled

  • label (string): Current progress label

Example:

progressAll (Server-side only)

Send a progress bar to all online players simultaneously.

Parameters:

  • options (table): Progress bar configuration options (same as progress function)

Returns: boolean - Success status

Example:

hideProgressPlayer (Server-side only)

Hide progress bar for a specific player from server-side.

Parameters:

  • playerId (number): Player server ID

Returns: boolean - Success status

Example:

Progress Types

Circular Progress

Ideal for indeterminate operations and loading states.

Linear Progress

Perfect for file operations and step-by-step processes.

Positioning System

Progress bars support a comprehensive 9-position grid system:

Recommended Positions:

  • 'center' - Screen center (default for circular)

  • 'top-center' - Top center

  • 'bottom-center' - Bottom center (default for linear)

Corner Positions:

  • 'top-left' - Upper left corner

  • 'top-right' - Upper right corner

  • 'bottom-left' - Lower left corner

  • 'bottom-right' - Lower right corner

Side Positions:

  • 'center-left' - Left side center

  • 'center-right' - Right side center

Size and Styling Options

Size Variants

Color Customization

Animation Styles

Smooth Animation (Default)

Pulse Animation

Glow Animation

Cancellation Handling

Basic Cancellation

Advanced Cancellation with Callback

Server-Side Usage

Progress for Specific Player

Progress for All Players

Sequential Server Operations

Conditional Progress Operations

Configuration

Configure progress bar defaults in config.lua:

Advanced Examples

Multi-Step Progress with Updates

Progress with Real-time Updates

Progress with State Persistence

Server-Side Batch Operations

Events

The progress system triggers the following events:

Client-Side Events

  • b2lib:progress:started - Triggered when a progress bar starts

  • b2lib:progress:updated - Triggered during progress updates

  • b2lib:progress:completed - Triggered when progress completes

  • b2lib:progress:cancelled - Triggered when progress is cancelled

Server-Side Events

  • b2lib:server:progress - Internal event for server-to-client progress

  • b2lib:server:progressAll - Internal event for broadcasting progress

Best Practices

  1. Choose Appropriate Types - Use circular for indeterminate operations, linear for measurable progress

  2. Provide Clear Labels - Use descriptive labels that inform users what's happening

  3. Consider Duration - Match progress duration to actual operation time when possible

  4. Use Cancellation Wisely - Allow cancellation for long operations that users might want to abort

  5. Position Strategically - Place progress bars where they won't obstruct important UI elements

  6. Customize for Context - Use appropriate colors and sizes for different operation types

  7. Handle Edge Cases - Always validate parameters and handle failures gracefully

  8. Test Performance - Ensure progress animations don't impact game performance

  9. Provide Feedback - Show completion notifications after progress finishes

  10. Use Server-Side for Critical Operations - Important progress should be managed server-side

Troubleshooting

Progress Not Showing

  1. Check Duration Parameter: Ensure duration is provided and is a positive number

  2. Verify B2Lib Initialization: Confirm B2Lib is properly initialized

  3. Validate Position: Ensure position value is valid

  4. Check Console Errors: Look for error messages in the console

  5. Test with Simple Example: Try a basic progress bar without optional parameters

Progress Animation Issues

  1. Check Update Interval: Verify updateInterval in config is appropriate (16ms for 60fps)

  2. Monitor Performance: Ensure other scripts aren't causing frame drops

  3. Test Different Types: Try both circular and linear types

  4. Disable Effects: Temporarily disable gradient and animation effects

Cancellation Not Working

  1. Verify canCancel Setting: Ensure canCancel is set to true

  2. Check Cancel Key: Verify the cancel key is properly configured

  3. Test Key Binding: Ensure the cancel key isn't bound to other functions

  4. Monitor State: Use getProgressState() to check cancellation status

Server-Side Issues

  1. Check Player Validity: Ensure player ID is valid before sending progress

  2. Handle Disconnections: Account for players disconnecting during progress

  3. Validate Permissions: Check player permissions before showing progress

  4. Test Event Triggering: Verify server events are properly registered

Performance Issues

  1. Limit Concurrent Progress: Avoid multiple progress bars simultaneously

  2. Optimize Update Frequency: Adjust update interval based on needs

  3. Use Appropriate Sizes: Smaller progress bars have better performance

  4. Monitor Memory Usage: Check for memory leaks with long-running progress


Last updated