class Cfx
package fivem.shared.natives
Static methods
staticaddConvarChangeListener(conVarFilter:String, handler:Function):Int
Adds a listener for Console Variable changes.
The function called expects to match the following signature:
function ConVarChangeListener(conVarName: string, reserved: any);- conVarName: The ConVar that changed.
- reserved: Currently unused.
staticaddStateBagChangeHandler(keyFilter:String, bagFilter:String, handler:Function):Int
Adds a handler for changes to a state bag.
The function called expects to match the following signature:
function StateBagChangeHandler(bagName: string, key: string, value: any, reserved: number, replicated: boolean);-
bagName: The internal bag ID for the state bag which changed. This is usually
player:Source,entity:NetIDor
localEntity:Handle. - key: The changed key.
- value: The new value stored at key. The old value is still stored in the state bag at the time this callback executes.
- reserved: Currently unused.
- replicated: Whether the set is meant to be replicated.
At this time, the change handler can't opt to reject changes.
If bagName refers to an entity, use GET_ENTITY_FROM_STATE_BAG_NAME to get the entity handle
If bagName refers to a player, use GET_PLAYER_FROM_STATE_BAG_NAME to get the player handle
staticdeleteFunctionReference(referenceIdentity:String):Dynamic
staticdeleteResourceKvp(key:String):Dynamic
staticdeleteResourceKvpNoSync(key:String):Dynamic
Nonsynchronous DELETE_RESOURCE_KVP operation; see FLUSH_RESOURCE_KVP.
staticdoesTrainStopAtStations(train:Dynamic):Bool
staticduplicateFunctionReference(referenceIdentity:String):String
staticendFindKvp(handle:Int):Dynamic
staticensureEntityStateBag(entity:Dynamic):Dynamic
Internal function for ensuring an entity has a state bag.
staticexecuteCommand(commandString:String):Dynamic
Depending on your use case you may need to use add_acl resource.<your_resource_name> command.<command_name> allow to use this native in your resource.
staticfindKvp(handle:Int):String
staticformatStackTrace(traceData:Dynamic):String
An internal function for converting a stack trace object to a string.
staticgetConvar(varName:String, default_:String):String
Can be used to get a console variable of type char*, for example a string.
staticgetConvarBool(varName:String, defaultValue:Bool):Bool
Can be used to get a console variable casted back to bool.
staticgetConvarFloat(varName:String, defaultValue:Float):Float
This will have floating point inaccuracy.
staticgetConvarInt(varName:String, default_:Int):Int
Can be used to get a console variable casted back to int (an integer value).
staticgetEntitiesInRadius(x:Float, y:Float, z:Float, radius:Float, entityType:Int, sortByDistance:Bool, models:Dynamic):Dynamic
Supported types
- [1] : Peds (including animals) and players.
- [2] : Vehicles.
- [3] : Objects (props), doors, and projectiles.
Coordinates need to be send unpacked (x,y,z)
-- Define the allowed model hashes
local allowedModelHashes = { GetHashKey("p_crate03x"), GetHashKey("p_crate22x") }
-- Get the player's current coordinates
local playerCoords = GetEntityCoords(PlayerPedId())
-- Retrieve all entities of type Object (type 3) within a radius of 10.0 units
-- that match the allowed model hashes
-- and sort output entities by distance
local entities = GetEntitiesInRadius(playerCoords.x, playerCoords.y, playerCoords.z, 10.0, 3, true, allowedModelHashes)
-- Iterate through the list of entities and print their ids
for i = 1, #entities do
local entity = entities[i]
print(entity)
end
staticgetEntityFromStateBagName(bagName:String):Dynamic
Returns the entity handle for the specified state bag name. For use with ADD_STATE_BAG_CHANGE_HANDLER.
staticgetGameBuildNumber():Int
Returns the internal build number of the current game being executed.
Possible values:
- FiveM 1604 2060 2189 2372 2545 2612 2699 2802 2944 3095 3258 3323 3407 3570 3751 3788
- RedM 1311 1355 1436 1491
- LibertyM * 43
- FXServer * 0
staticgetGameName():String
Returns the current game being executed.
Possible values:
| Return value | Meaning |
|---|
| ------------ | ------------------------------ |
|---|
fxserver | Server-side code ('Duplicity') |
|---|
fivem | FiveM for GTA V |
|---|
libertym | LibertyM for GTA IV |
|---|
redm | RedM for Red Dead Redemption 2 |
|---|
staticgetGamePool(poolName:String):Dynamic
Returns a list of entity handles (script GUID) for all entities in the specified pool - the data returned is an array as
follows:
[ 770, 1026, 1282, 1538, 1794, 2050, 2306, 2562, 2818, 3074, 3330, 3586, 3842, 4098, 4354, 4610, ...]
Supported pools
CPed: Peds (including animals) and players.CObject: Objects (props), doors, and projectiles.CNetObject: Networked objectsCVehicle: Vehicles.CPickup: Pickups.
staticgetInstanceId():Int
staticgetInvokingResource():String
staticgetNumResourceMetadata(resourceName:String, metadataKey:String):Int
Gets the amount of metadata values with the specified key existing in the specified resource's manifest.
See also: Resource manifest
staticgetNumResources():Int
staticgetPlayerFromStateBagName(bagName:String):Int
On the server this will return the players source, on the client it will return the player handle.
staticgetPlayerMeleeWeaponDamageModifier(playerId:Dynamic):Float
A getter for SET_PLAYER_MELEE_WEAPON_DAMAGE_MODIFIER.
staticgetPlayerWeaponDamageModifier(playerId:Dynamic):Float
A getter for SET_PLAYER_WEAPON_DAMAGE_MODIFIER.
staticgetPlayerWeaponDefenseModifier(playerId:Dynamic):Float
A getter for SET_PLAYER_WEAPON_DEFENSE_MODIFIER.
staticgetPlayerWeaponDefenseModifier2(playerId:Dynamic):Float
A getter for _SET_PLAYER_WEAPON_DEFENSE_MODIFIER_2.
staticgetRegisteredCommands():Dynamic
Returns all commands that are registered in the command system.
The data returned adheres to the following layout:
[
{
"name": "cmdlist",
"resource": "resource",
"arity" = -1,
},
{
"name": "command1"
"resource": "resource_2",
"arity" = -1,
}
]staticgetResourceByFindIndex(findIndex:Int):String
staticgetResourceCommands(resource:String):Dynamic
Returns all commands registered by the specified resource.
The data returned adheres to the following layout:
[
{
"name": "cmdlist",
"resource": "example_resource",
"arity" = -1,
},
{
"name": "command1"
"resource": "example_resource2",
"arity" = -1,
}
]staticgetResourceMetadata(resourceName:String, metadataKey:String, index:Int):String
Gets the metadata value at a specified key/index from a resource's manifest.
See also: Resource manifest
staticgetResourceState(resourceName:String):String
Returns the current state of the specified resource.
staticgetStateBagKeys(bagName:String):Dynamic
staticgetTrainState(train:Dynamic):Int
staticgetTrainTrackIndex(train:Dynamic):Int
staticgetVehicleHandbrake(vehicle:Dynamic):Bool
staticgetVehicleSteeringAngle(vehicle:Dynamic):Float
staticgetVehicleType(vehicle:Dynamic):String
Returns the type of the passed vehicle.
For client scripts, reference the more detailed GET_VEHICLE_TYPE_RAW native.
Vehicle types
- automobile
- bike
- boat
- heli
- plane
- submarine
- trailer
- train
staticisAceAllowed(object:String):Bool
staticisPrincipalAceAllowed(principal:String, object:String):Bool
staticisVehicleEngineStarting(vehicle:Dynamic):Bool
staticloadResourceFile(resourceName:String, fileName:String):String
Reads the contents of a text file in a specified resource.
If executed on the client, this file has to be included in files in the resource manifest.
Example: local data = LoadResourceFile("devtools", "data.json")
staticregisterCommand(commandName:String, handler:Function, restricted:Bool):Dynamic
Registered commands can be executed by entering them in the client console (this works for client side and server side registered commands). Or by entering them in the server console/through an RCON client (only works for server side registered commands). Or if you use a supported chat resource, like the default one provided in the cfx-server-data repository, then you can enter the command in chat by prefixing it with a /.
Commands registered using this function can also be executed by resources, using the ExecuteCommand native.
The restricted bool is not used on the client side. Permissions can only be checked on the server side, so if you want to limit your command with an ace permission automatically, make it a server command (by registering it in a server script).
Example result:

staticregisterResourceAsEventHandler(eventName:String):Dynamic
An internal function which allows the current resource's HLL script runtimes to receive state for the specified event.
staticremoveConvarChangeListener(cookie:Int):Dynamic
staticremoveStateBagChangeHandler(cookie:Int):Dynamic
Experimental: This native may be altered or removed in future versions of CitizenFX without warning.
Removes a handler for changes to a state bag.
staticsetResourceKvpFloatNoSync(key:String, value:Float):Dynamic
Nonsynchronous SET_RESOURCE_KVP_FLOAT operation; see FLUSH_RESOURCE_KVP.
staticsetResourceKvpIntNoSync(key:String, value:Int):Dynamic
Nonsynchronous SET_RESOURCE_KVP_INT operation; see FLUSH_RESOURCE_KVP.
staticsetResourceKvpNoSync(key:String, value:String):Dynamic
Nonsynchronous SET_RESOURCE_KVP operation; see FLUSH_RESOURCE_KVP.
staticsetStateBagValue(bagName:String, keyName:String, valueData:String, valueLength:Int, replicated:Bool):Dynamic
Internal function for setting a state bag value.
staticstartFindKvp(prefix:String):Int
staticstateBagHasKey(bagName:String, key:String):Dynamic
statictriggerEventInternal(eventName:String, eventPayload:String, payloadLength:Int):Dynamic
The backing function for TriggerEvent.