Functions (Generic)
Client API Documentation
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
UI & Text Display
Vehicle Management
Notifications
Inventory
Progress Bars
Location Services
Audio
Dimensions
Teleportation
Position & Movement
cAPI.GetPosition()
cAPI.GetPosition()Gets the current player position coordinates.
Returns:
x(number): X coordinatey(number): Y coordinatez(number): Z coordinate
Example:
local x, y, z = cAPI.GetPosition()
print("Player is at:", x, y, z)cAPI.GetSpeed
cAPI.GetSpeedGets the current player movement speed (magnitude of velocity vector).
Returns:
speed(number): Current speed in game units
Example:
local currentSpeed = cAPI.GetSpeed()
print("Player speed:", currentSpeed)cAPI.GetCoords
cAPI.GetCoordsGets coordinates and heading of any entity.
Parameters:
entity(number): Entity handle
Returns:
table: Contains x, y, z coordinates and heading (a)
Example:
local coords = cAPI.GetCoords(PlayerPedId())
print("Coords:", coords.x, coords.y, coords.z, "Heading:", coords.a)Camera & Targeting
cAPI.GetCoordsFromCam
cAPI.GetCoordsFromCamCalculates world coordinates from camera position at specified distance.
Parameters:
distance(number): Distance from camera
Returns:
x(number): X coordinatey(number): Y coordinatez(number): Z coordinate
Example:
local x, y, z = cAPI.GetCoordsFromCam(10.0)
print("Point 10 units from camera:", x, y, z)cAPI.Target
cAPI.TargetPerforms raycast targeting from camera to detect entities.
Parameters:
Distance(number): Maximum raycast distancePed(number): Ped entity to ignore in raycast
Returns:
Entity(number): Hit entity (0 if none)x(number): Hit point X coordinatey(number): Hit point Y coordinatez(number): Hit point Z coordinate
Example:
local entity, x, y, z = cAPI.Target(50.0, PlayerPedId())
if entity ~= 0 then
print("Hit entity:", entity, "at", x, y, z)
endPlayer State
cAPI.ToggleInvinsible
cAPI.ToggleInvinsibleToggles player invincibility state.
Example:
cAPI.ToggleInvinsible() -- Player becomes invincible
cAPI.ToggleInvinsible() -- Player becomes vulnerable againcAPI.IsPlayingAnimation
cAPI.IsPlayingAnimationChecks if player is currently playing a specific animation.
Parameters:
dict(string): Animation dictionaryanim(string): Animation name
Returns:
boolean: True if animation is playing
Example:
if cAPI.IsPlayingAnimation("amb_rest_drunk", "enter_left") then
print("Player is playing drunk animation")
endcAPI.ClientConnected
cAPI.ClientConnectedHandles client connection state and loading screen.
Parameters:
bool(boolean): Connection status
Example:
cAPI.ClientConnected(true) -- Shuts down loading screenVisual Effects
cAPI.ForceLightningFlashAtCoords
cAPI.ForceLightningFlashAtCoordsCreates a lightning flash effect at specified coordinates.
Parameters:
x(number): X coordinatey(number): Y coordinatez(number): Z coordinate
Returns:
boolean: Success status
Example:
cAPI.ForceLightningFlashAtCoords(100.0, 200.0, 50.0)cAPI.PlaySkyCameraAnimationAtCoords
cAPI.PlaySkyCameraAnimationAtCoordsPlays a cinematic sky camera animation sequence ending with teleportation.
Parameters:
coords(table): Array with [x, y, z] coordinates
Example:
cAPI.PlaySkyCameraAnimationAtCoords({100.0, 200.0, 50.0})UI & Text Display
cAPI.DrawText
cAPI.DrawTextDraws 2D text on screen with customizable properties.
Parameters:
x(number): Screen X position (0.0 to 1.0)y(number): Screen Y position (0.0 to 1.0)width(number): Text widthheight(number): Text heightscale(number): Text scale multiplierr(number): Red color component (0-255)g(number): Green color component (0-255)b(number): Blue color component (0-255)a(number): Alpha transparency (0-255)text(string): Text to display
Example:
cAPI.DrawText(0.5, 0.5, 0.0, 0.0, 0.5, 255, 255, 255, 255, "Hello World")cAPI.DrawText3D
cAPI.DrawText3DDraws 3D text in world space with background.
Parameters:
x(number): World X coordinatey(number): World Y coordinatez(number): World Z coordinatetext(string): Text to display
Example:
local x, y, z = cAPI.GetPosition()
cAPI.DrawText3D(x, y, z + 2.0, "Player Location")cAPI.DisplayHelpText
cAPI.DisplayHelpTextDisplays help text in the game's native help system.
Parameters:
helpText(string): Help message to display
Example:
cAPI.DisplayHelpText("Press E to interact")Vehicle Management
cAPI.SpawnVehicle
cAPI.SpawnVehicleSpawns a vehicle with specified parameters.
Parameters:
model(string/number): Vehicle model name or hashcb(function, optional): Callback function receiving vehicle handlecoords(table, optional): Spawn coordinates {x, y, z, a}isnetworked(boolean, optional): Whether vehicle should be networked (default: true)
Example:
cAPI.SpawnVehicle("wagon02x", function(vehicle)
print("Vehicle spawned:", vehicle)
-- Set player into vehicle
SetPedIntoVehicle(PlayerPedId(), vehicle, -1)
end, {x = 100.0, y = 200.0, z = 50.0, a = 90.0})Notifications
cAPI.NotifySimple
cAPI.NotifySimpleShows a simple notification message.
Parameters:
text(string): Notification texttimeout(number): Display duration in milliseconds
Example:
cAPI.NotifySimple("Welcome to the server!", 5000)cAPI.Notify
cAPI.NotifyShows a notification with type and quantity.
Parameters:
type(string): Notification typetext(string): Notification textquantity(number): Quantity to display
Example:
cAPI.Notify("success", "Item received", 1)cAPI.NotifyToast
cAPI.NotifyToastShows a toast-style notification.
Parameters:
type(string): Toast type (defaults to "dev" if only text provided)text(string): Toast textquantity(number, optional): Quantity to display
Example:
cAPI.NotifyToast("info", "New quest available", 1)
-- Or simplified:
cAPI.NotifyToast("Simple toast message")Inventory
cAPI.HasItem
cAPI.HasItemChecks if player has specified item and amount.
Parameters:
item(string): Item identifieramount(number, optional): Required amount (default: 1)
Returns:
boolean: True if player has required amount
Example:
if cAPI.HasItem("apple", 5) then
print("Player has at least 5 apples")
endProgress Bars
cAPI.Progressbar
cAPI.ProgressbarCreates a progress bar with customizable options.
Parameters:
name(string): Progress bar identifierlabel(string): Display labelduration(number): Duration in millisecondsuseWhileDead(boolean): Allow while deadcanCancel(boolean): Can be cancelleddisableControls(table): Controls to disableanimation(table): Animation settingsprop(table): Primary prop settingspropTwo(table): Secondary prop settingsonFinish(function): Completion callbackonCancel(function): Cancellation callback
Example:
cAPI.Progressbar("eating", "Eating food...", 5000, false, true, {}, {}, {}, {},
function()
print("Finished eating!")
end,
function()
print("Eating cancelled")
end
)Location Services
cAPI.GetCurrentStateName
cAPI.GetCurrentStateNameGets the current state/region name.
Returns:
string: State name ("Ambarino", "Lemoyne", "West Elizabeth", "New Austin", "New Hanover", "Guarma")
Example:
local state = cAPI.GetCurrentStateName()
print("Current state:", state)cAPI.GetCurrentTownName
cAPI.GetCurrentTownNameGets the current town/settlement name.
Returns:
string: Town name or "Cidade Fantasma" if unknown
Example:
local town = cAPI.GetCurrentTownName()
print("Current town:", town)Audio
cAPI.PlayAmbientSpeech
cAPI.PlayAmbientSpeechPlays ambient speech for a ped.
Parameters:
ped(number): Ped entity handlespeech(string): Speech identifier
Example:
cAPI.PlayAmbientSpeech(PlayerPedId(), "GREET_GENERAL")Dimensions
cAPI.enterDimension
cAPI.enterDimensionEnters a specific dimension, including any transport vehicle.
Parameters:
dimensionId(number): Target dimension ID
Example:
cAPI.enterDimension(1) -- Enter dimension 1cAPI.leaveDimension
cAPI.leaveDimensionLeaves a specific dimension, including any transport vehicle.
Parameters:
dimensionId(number): Dimension ID to leave
Example:
cAPI.leaveDimension(1) -- Leave dimension 1Utility Functions
cAPI.GetUserIdFromServerId
cAPI.GetUserIdFromServerIdConverts server ID to user ID.
Parameters:
serverid(number): Server ID
Returns:
number: User ID (0 if not found)
cAPI.GetServerIdFromUserId
cAPI.GetServerIdFromUserIdConverts user ID to server ID.
Parameters:
userid(number): User ID
Returns:
number: Server ID (0 if not found)
cAPI.GetFromCoordsFromPlayer
cAPI.GetFromCoordsFromPlayerCalculates coordinates at a specific radius from a player/ped position.
Parameters:
position(vector3): Base positionped(number, optional): Ped entity (defaults to PlayerPedId())radius(number, optional): Distance radius (default: 0.8)
Returns:
vector3: Calculated coordinates with ground Z adjustment
Error Handling and Best Practices
Thread Safety
Most functions are safe to call from any thread
Camera and teleportation functions may require main thread execution
Performance Considerations
Use
DrawText3Dsparingly in loopsCache entity handles when possible
Avoid calling expensive functions like
GetCurrentTownName()every frame
Common Patterns
-- Check if player has item before using
if cAPI.HasItem("bandage") then
cAPI.Progressbar("healing", "Using bandage...", 3000, false, true, {}, {}, {}, {},
function()
-- Heal player
cAPI.NotifySimple("Bandage used successfully!", 3000)
end
)
else
cAPI.NotifySimple("You don't have any bandages!", 3000)
end
-- Safe teleportation with notification
local targetCoords = {x = 100.0, y = 200.0, z = 50.0}
cAPI.NotifySimple("Teleporting...", 2000)
handleTpNormally(targetCoords)This framework provides a comprehensive set of tools for RedM server development, focusing on player interaction, world manipulation, and user interface elements.
Last updated