Text UI

The Text UI system provides contextual text displays with optional keybind hints and icons. Perfect for showing interaction prompts, status information, and helpful hints that appear at specific screen positions.

Dark Text UI

textUI

Display a contextual text UI element with customizable styling and positioning.

Parameters:

  • playerId (number, server-side only): Player server ID to show text UI to

  • options (table|string): Text UI configuration object or simple text string

    • text (string, required): Text content to display

    • keybind (string, optional): Keybind to display (e.g., 'E', 'F', 'ENTER', 'SPACE', 'TAB')

    • key (string, optional): Alternative parameter name for keybind (same as keybind)

    • icon (string, optional): Lucide icon name to display alongside text

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

    • showBackground (boolean, optional): Show background panel (default: from config)

    • fadeTime (number, optional): Fade animation duration in milliseconds (default: from config)

    • backgroundColor (string, optional): Custom background color override (CSS color)

    • textColor (string, optional): Custom text color override (CSS color)

    • borderColor (string, optional): Custom border color override (CSS color)

    • id (string, optional): Custom text UI identifier for tracking and management

Returns: boolean - Success status

Example:

hideTextUI

Hide the currently active text UI element with fade animation.

Parameters:

  • playerId (number, server-side only): Player server ID to hide text UI for

Returns: boolean - Success status

Example:

isTextUIVisible

Check if text UI is currently visible and get active text UI information.

Returns: boolean|table - False if no text UI is active, or table with active text UI data

  • text (string): Current text content

  • keybind (string): Current keybind

  • icon (string): Current icon

  • position (string): Current position

  • id (string): Text UI identifier

Example:

Position Options

Text UI supports 9 different screen positions for optimal placement:

  • 'top-left' - Top left corner of screen

  • 'top-center' - Top center of screen

  • 'top-right' - Top right corner of screen

  • 'center-left' - Middle left of screen

  • 'center' - Center of screen

  • 'center-right' - Middle right of screen

  • 'bottom-left' - Bottom left corner of screen

  • 'bottom-center' - Bottom center of screen (default)

  • 'bottom-right' - Bottom right corner of screen

Example:

Server-Side Usage

The Text UI module provides comprehensive server-side functionality for managing player-specific text displays:

Configuration

Complete Text UI configuration options in config.lua:

Advanced Examples

Interactive Object System

Vehicle Interaction System

Dynamic Status Display System

Mission Objective System

Dynamic Help System

Events

The Text UI module provides comprehensive event handling for monitoring and responding to text UI interactions:

Client Events

Server Events

Event Usage Examples

Best Practices

  1. Use Strategic Positioning - Choose positions that complement gameplay flow and don't obstruct critical UI elements like minimap, health bars, or chat

  2. Keep Text Concise and Clear - Use short, actionable messages that players can quickly understand at a glance

  3. Implement Meaningful Keybinds - Display the actual keys players need to press, using consistent keybind conventions across your resource

  4. Leverage Visual Hierarchy - Use icons, colors, and positioning to create clear visual hierarchy and importance levels

  5. Handle State Management Properly - Always hide text UI when conditions change to prevent UI pollution and confusion

  6. Test Across Resolutions - Ensure text UI displays correctly on different screen sizes and aspect ratios

  7. Maintain Visual Consistency - Use consistent styling, colors, and positioning patterns throughout your resource

  8. Implement Context Awareness - Show relevant information based on player state, location, and current activities

  9. Optimize Update Frequency - Use appropriate update intervals to balance responsiveness with performance

  10. Use Server-Side Strategically - Leverage server-side text UI for administrative tools, events, and player-specific content

  11. Implement Priority Systems - Use priority-based systems to manage multiple text UI contexts and prevent conflicts

  12. Provide Accessibility Options - Consider colorblind users and provide high contrast options when needed

Troubleshooting

Text UI Not Showing

  1. Check that the text parameter is provided and not empty

  2. Verify B2Lib is properly initialized

  3. Check console for error messages from B2Lib.Debug

  4. Ensure no other modal dialogs are blocking the display

Text UI Not Hiding

  1. Verify hideTextUI() is being called correctly

  2. Check that the text UI was successfully shown first

  3. Ensure no other scripts are showing text UI simultaneously

  4. Test with manual hideTextUI() calls

Positioning Issues

  1. Check that position values are valid strings

  2. Test with default position first

  3. Verify screen resolution compatibility

  4. Check for CSS conflicts in custom styling

Performance Issues

  1. Avoid showing/hiding text UI too frequently

  2. Use reasonable update intervals in loops

  3. Clean up event handlers when no longer needed

  4. Limit the number of active text UI elements


Last updated