Utils Methods

Utils Methods

Overview

This documentation covers the Client API (cAPI) functions available in the FRP Framework. The API provides essential functionality for player interactions, world manipulation, UI elements, and game mechanics.

Table of Contents

  • Position & Movement

  • Camera & Targeting

  • Player State

  • Visual Effects


Position & Movement

cAPI.Prompt

Shows an input prompt dialog and waits for user input.

Parameters:

  • title (string): Prompt dialog title

  • default_text (string): Default input text

Returns:

  • string: User input text (or nil if cancelled)

Features:

  • Sets NUI focus for text input

  • Waits for user completion

  • Returns actual user input

  • Handles cancellation gracefully

Example:


Resource Management

cAPI.RequestModel

Safely requests and loads a model with validation.

Parameters:

  • hash (number/string): Model hash or name

Features:

  • Validates model before requesting

  • Waits for complete loading

  • Handles invalid models gracefully

  • Automatic hash conversion

Example:

cAPI.RequestAnimDict

Safely requests and loads an animation dictionary.

Parameters:

  • dictionary (string): Animation dictionary name

Features:

  • Checks if already loaded

  • Waits for complete loading

  • Prevents duplicate requests

  • Thread-safe loading

Example:


Screen Effects

cAPI.StartFade

Initiates a screen fade-out with optional storm effect.

Parameters:

  • timer (number): Fade duration in milliseconds

  • effect (boolean, optional): Enable storm visual effect

Features:

  • Smooth screen fade transition

  • Optional atmospheric storm effect

  • Waits for fade completion

  • Thread-safe execution

Example:

cAPI.EndFade

Initiates a screen fade-in and cleans up effects.

Parameters:

  • timer (number): Fade duration in milliseconds

  • effect (boolean, optional): Clean up storm effect

Features:

  • Shuts down loading screen

  • Smooth screen fade-in

  • Automatic effect cleanup

  • Waits for fade completion

Example:

Complete Fade Sequence Example


Animation Helpers

cAPI.PlayAnim

Plays an animation with automatic dictionary loading.

Parameters:

  • dict (string): Animation dictionary name

  • anim (string): Animation name within dictionary

  • speed (number): Animation playback speed

Features:

  • Checks if animation is already playing

  • Automatically loads animation dictionary

  • Waits for dictionary loading

  • Starts animation with proper parameters

Example:


Advanced Usage Patterns

Request/Prompt Flow Control

Resource Loading with Error Handling

Smooth Scene Transitions

Animation Sequences


Integration with Other Systems

UI + Teleportation

Resource Management Best Practices


Error Handling and Performance

UI Interaction Safety

  • Request and Prompt functions include automatic cleanup

  • Use reasonable timeouts to prevent infinite waiting

  • Handle nil returns from cancelled prompts

Resource Loading Optimization

  • Load frequently used models/animations at startup

  • Use SetModelAsNoLongerNeeded() after use

  • Batch load resources when possible

Screen Effect Performance

  • Minimize fade frequency to avoid visual fatigue

  • Use effects sparingly for better performance

  • Always pair StartFade() with EndFade()

Animation Management

  • Check if animations are already playing to avoid conflicts

  • Use appropriate speeds for realistic movement

  • Clear ped tasks when switching between different animations

Last updated