PromptBuilder

A fluent API for creating and managing UI prompts in RedM with method chaining support.

Overview

The PromptBuilder provides a simple, chainable interface for creating interactive UI prompts. It automatically handles prompt registration, cleanup, and provides various configuration options through a fluent API pattern.

Basic Usage

local promptId = PromptBuilder:new()
    :setText("Press to interact")
    :setControl(`INPUT_CONTEXT`)
    :setVisible(true)
    :setEnabled(true)
    :build()

API Reference

PromptBuilder:new()

Creates a new prompt instance with default settings.

Returns: PromptBuilderChain - A chainable prompt builder instance

Default Settings:

  • Text: "Sem nome {promptId}"

  • Enabled: true

  • Visible: true

  • Mode: Standard

Methods

setControl

Sets the control input(s) for the prompt.

Parameters:

  • controlHashLike - Primary control hash or input

  • secondControlHashLike (optional) - Secondary control hash

Returns: PromptBuilderChain - For method chaining

setText

Sets the display text for the prompt.

Parameters:

  • text (string|number) - Text to display or text hash

Returns: PromptBuilderChain - For method chaining

setVisible

Controls prompt visibility.

Parameters:

  • visible (boolean) - Whether the prompt should be visible

Returns: PromptBuilderChain - For method chaining

setMode

Sets the prompt interaction mode.

Parameters:

  • mode ('Standard'|'Hold'|'AutoFill') - Interaction mode

  • ...params - Additional parameters for specific modes

Modes:

  • 'Standard' - Single press interaction

  • 'Hold' - Hold button interaction (requires hold duration)

  • 'AutoFill' - Auto-filling hold interaction

Returns: PromptBuilderChain - For method chaining

setGroup

Assigns the prompt to a specific group.

Parameters:

  • groupHash - Group identifier hash

Returns: PromptBuilderChain - For method chaining

setPoint

Sets a 3D world position for the prompt context.

Parameters:

  • point ({x: number, y: number, z: number}) - World coordinates

Returns: PromptBuilderChain - For method chaining

setRadius

Sets the interaction radius for 3D prompts.

Parameters:

  • radius (number) - Interaction radius in game units

Returns: PromptBuilderChain - For method chaining

setVolume

Sets the interaction volume for 3D prompts.

Parameters:

  • volume (number) - Volume identifier

Returns: PromptBuilderChain - For method chaining

setEnabled

Controls whether the prompt can be interacted with.

Parameters:

  • enabled (boolean) - Whether the prompt is enabled

Returns: PromptBuilderChain - For method chaining

build

Finalizes the prompt creation and registers it with the game.

Returns: number - The prompt ID for further manipulation

Complete Example

Memory Management

The PromptBuilder automatically handles cleanup when the resource stops. All created prompts are tracked and properly deleted to prevent memory leaks.

Automatic Cleanup:

  • Prompts are automatically deleted when the resource stops

  • Manual deletion is supported via PromptDelete(promptId)

  • Deleted prompts are removed from the tracking pool

Advanced Usage

Custom Prompt Groups

3D World Prompts

Notes

  • All methods return the chain instance, allowing for fluent method chaining

  • Prompts are automatically cleaned up on resource stop

  • The system handles both hash-based and string-based text inputs

  • 3D prompts require both point and radius to function properly

Last updated