Static methods

@:native("AddConvarChangeListener")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.

@:native("AddStateBagChangeHandler")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:NetID

    or 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

@:native("CancelEvent")staticcancelEvent():Dynamic

Cancels the currently executing event.

@:native("DeleteFunctionReference")staticdeleteFunctionReference(referenceIdentity:String):Dynamic

@:native("DeleteResourceKvp")staticdeleteResourceKvp(key:String):Dynamic

@:native("DeleteResourceKvpNoSync")staticdeleteResourceKvpNoSync(key:String):Dynamic

Nonsynchronous DELETE_RESOURCE_KVP operation; see FLUSH_RESOURCE_KVP.

@:native("DoesTrainStopAtStations")staticdoesTrainStopAtStations(train:Dynamic):Bool

@:native("DuplicateFunctionReference")staticduplicateFunctionReference(referenceIdentity:String):String

@:native("EndFindKvp")staticendFindKvp(handle:Int):Dynamic

@:native("EnsureEntityStateBag")staticensureEntityStateBag(entity:Dynamic):Dynamic

Internal function for ensuring an entity has a state bag.

@:native("ExecuteCommand")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.

@:native("FindKvp")staticfindKvp(handle:Int):String

@:native("FormatStackTrace")staticformatStackTrace(traceData:Dynamic):String

An internal function for converting a stack trace object to a string.

@:native("GetConvar")staticgetConvar(varName:String, default_:String):String

Can be used to get a console variable of type char*, for example a string.

@:native("GetConvarBool")staticgetConvarBool(varName:String, defaultValue:Bool):Bool

Can be used to get a console variable casted back to bool.

@:native("GetConvarFloat")staticgetConvarFloat(varName:String, defaultValue:Float):Float

This will have floating point inaccuracy.

@:native("GetConvarInt")staticgetConvarInt(varName:String, default_:Int):Int

Can be used to get a console variable casted back to int (an integer value).

@:native("GetCurrentResourceName")staticgetCurrentResourceName():String

Returns the name of the currently executing resource.

@:native("GetEntitiesInRadius")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

@:native("GetEntityFromStateBagName")staticgetEntityFromStateBagName(bagName:String):Dynamic

Returns the entity handle for the specified state bag name. For use with ADD_STATE_BAG_CHANGE_HANDLER.

@:native("GetGameBuildNumber")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

@:native("GetGameName")staticgetGameName():String

Returns the current game being executed.

Possible values:

Return valueMeaning
------------------------------------------
fxserverServer-side code ('Duplicity')
fivemFiveM for GTA V
libertymLibertyM for GTA IV
redmRedM for Red Dead Redemption 2

@:native("GetGamePool")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 objects
  • CVehicle: Vehicles.
  • CPickup: Pickups.

@:native("GetInstanceId")staticgetInstanceId():Int

@:native("GetInvokingResource")staticgetInvokingResource():String

@:native("GetNumResourceMetadata")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

@:native("GetNumResources")staticgetNumResources():Int

@:native("GetPlayerFromStateBagName")staticgetPlayerFromStateBagName(bagName:String):Int

On the server this will return the players source, on the client it will return the player handle.

@:native("GetPlayerMeleeWeaponDamageModifier")staticgetPlayerMeleeWeaponDamageModifier(playerId:Dynamic):Float

@:native("GetPlayerWeaponDamageModifier")staticgetPlayerWeaponDamageModifier(playerId:Dynamic):Float

@:native("GetPlayerWeaponDefenseModifier")staticgetPlayerWeaponDefenseModifier(playerId:Dynamic):Float

@:native("GetPlayerWeaponDefenseModifier_2")staticgetPlayerWeaponDefenseModifier2(playerId:Dynamic):Float

@:native("GetRegisteredCommands")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,

}

]

@:native("GetResourceByFindIndex")staticgetResourceByFindIndex(findIndex:Int):String

@:native("GetResourceCommands")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,

}

]

@:native("GetResourceKvpFloat")staticgetResourceKvpFloat(key:String):Float

@:native("GetResourceKvpInt")staticgetResourceKvpInt(key:String):Int

A getter for SET_RESOURCE_KVP_INT.

@:native("GetResourceKvpString")staticgetResourceKvpString(key:String):String

A getter for SET_RESOURCE_KVP.

@:native("GetResourceMetadata")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

@:native("GetResourceState")staticgetResourceState(resourceName:String):String

Returns the current state of the specified resource.

@:native("GetStateBagKeys")staticgetStateBagKeys(bagName:String):Dynamic

@:native("GetStateBagValue")staticgetStateBagValue(bagName:String, key:String):Dynamic

Returns the value of a state bag key.

@:native("GetTrainCruiseSpeed")staticgetTrainCruiseSpeed(train:Dynamic):Float

Gets the trains desired speed.

@:native("GetTrainDirection")staticgetTrainDirection(train:Dynamic):Bool

Gets the direction the train is facing

@:native("GetTrainState")staticgetTrainState(train:Dynamic):Int

@:native("GetTrainTrackIndex")staticgetTrainTrackIndex(train:Dynamic):Int

@:native("GetVehicleHandbrake")staticgetVehicleHandbrake(vehicle:Dynamic):Bool

@:native("GetVehicleSteeringAngle")staticgetVehicleSteeringAngle(vehicle:Dynamic):Float

@:native("GetVehicleType")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

@:native("IsAceAllowed")staticisAceAllowed(object:String):Bool

@:native("IsDuplicityVersion")staticisDuplicityVersion():Bool

Gets whether or not this is the CitizenFX server.

@:native("IsEntityPositionFrozen")staticisEntityPositionFrozen(entity:Dynamic):Dynamic

@:native("IsPrincipalAceAllowed")staticisPrincipalAceAllowed(principal:String, object:String):Bool

@:native("IsVehicleEngineStarting")staticisVehicleEngineStarting(vehicle:Dynamic):Bool

@:native("LoadResourceFile")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")

@:native("NetworkGetEntityOwner")staticnetworkGetEntityOwner(entity:Dynamic):Int

Returns the owner ID of the specified entity.

@:native("ProfilerEnterScope")staticprofilerEnterScope(scopeName:String):Dynamic

Scope entry for profiler.

@:native("ProfilerExitScope")staticprofilerExitScope():Dynamic

Scope exit for profiler.

@:native("ProfilerIsRecording")staticprofilerIsRecording():Bool

Returns true if the profiler is active.

@:native("RegisterCommand")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:

@:native("RegisterResourceAsEventHandler")staticregisterResourceAsEventHandler(eventName:String):Dynamic

An internal function which allows the current resource's HLL script runtimes to receive state for the specified event.

@:native("RemoveConvarChangeListener")staticremoveConvarChangeListener(cookie:Int):Dynamic

@:native("RemoveStateBagChangeHandler")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.

@:native("SetResourceKvp")staticsetResourceKvp(key:String, value:String):Dynamic

@:native("SetResourceKvpFloat")staticsetResourceKvpFloat(key:String, value:Float):Dynamic

@:native("SetResourceKvpFloatNoSync")staticsetResourceKvpFloatNoSync(key:String, value:Float):Dynamic

Nonsynchronous SET_RESOURCE_KVP_FLOAT operation; see FLUSH_RESOURCE_KVP.

@:native("SetResourceKvpInt")staticsetResourceKvpInt(key:String, value:Int):Dynamic

A setter for GET_RESOURCE_KVP_INT.

@:native("SetResourceKvpIntNoSync")staticsetResourceKvpIntNoSync(key:String, value:Int):Dynamic

Nonsynchronous SET_RESOURCE_KVP_INT operation; see FLUSH_RESOURCE_KVP.

@:native("SetResourceKvpNoSync")staticsetResourceKvpNoSync(key:String, value:String):Dynamic

Nonsynchronous SET_RESOURCE_KVP operation; see FLUSH_RESOURCE_KVP.

@:native("SetStateBagValue")staticsetStateBagValue(bagName:String, keyName:String, valueData:String, valueLength:Int, replicated:Bool):Dynamic

Internal function for setting a state bag value.

@:native("StartFindKvp")staticstartFindKvp(prefix:String):Int

@:native("StateBagHasKey")staticstateBagHasKey(bagName:String, key:String):Dynamic

@:native("TriggerEventInternal")statictriggerEventInternal(eventName:String, eventPayload:String, payloadLength:Int):Dynamic

The backing function for TriggerEvent.

@:native("WasEventCanceled")staticwasEventCanceled():Bool

Returns whether or not the currently executing event was canceled.