Key/value storage
The key/value storage allows storing arbitrary data on the client side. It can be accessed with standard natives exposed to the CitizenFX scripting component, however no example usage from Lua this time around, no updated natives.lua yet either so you’ll have to guess the definition for now.
The functions are (among others that aren’t exposed as they were ill-designed):
GET_RESOURCE_KVP_INT
Gets a KVP value for the current resource.
Arguments:
- key (string): the key to fetch
Return value:
An integer containing the integer value stored in the key.
Example:
int kvpValue = GET_RESOURCE_KVP_INT(“bananabread”);
GET_RESOURCE_KVP_FLOAT
Gets a float KVP value for the current resource.
Arguments:
- key (string): the key to fetch
Return value:
A float containing the floating-point value stored in the key.
Example:
float kvpValue = GET_RESOURCE_KVP_FLOAT(“codfish”);
GET_RESOURCE_KVP_STRING
Gets a string KVP value for the current resource.
Arguments:
key (string): the key to fetch
Return value:
A string containing the value stored in the key.
Example:
const char* kvpValue = GET_RESOURCE_KVP_STRING(“mollis”);
SET_RESOURCE_KVP
Sets a string KVP value for the current resource.
Arguments:
key (string): the key to set
value (string): the value to write
Return value:
None.
Example:
SET_RESOURCE_KVP(“mollis”, “vesuvius citrate”);
SET_RESOURCE_KVP_INT
Sets an integer KVP value for the current resource.
Arguments:
key (string): the key to set
value (int): the value to write
Return value:
None.
Example:
int lickMy = 42;
SET_RESOURCE_KVP_INT(“bananabread”, lickMy);
SET_RESOURCE_KVP_FLOAT
Sets a float KVP value for the current resource.
Arguments:
key (string): the key to set
value (float): the value to write
Return value:
None.
Example:
float curseBuster = 0xBC * 2.5f;
SET_RESOURCE_KVP_INT(“codfish”, curseBuster);
DELETE_RESOURCE_KVP
Removes a KVP value.
Arguments:
key (string): the key to delete
Return value:
None.
Example:
DELETE_RESOURCE_KVP(“liberty_city”); // it’s over!
START_FIND_KVP
Opens a find handle for scanning KVP entries that begin with a specific prefix.
Arguments:
prefix (string): a prefix match
Return value:
A KVP find handle to use with FIND_KVP and close with END_FIND_KVP once completed. -1 if unlucky.
Example:
SET_RESOURCE_KVP(“mollis:2”, “should be taken with alcohol”);
SET_RESOURCE_KVP(“mollis:1”, “vesuvius citrate”);
SET_RESOURCE_KVP(“mollis:manufacturer”, “Betta Pharmaceuticals”);
int kvpHandle = START_FIND_KVP(“mollis:”);
if (kvpHandle != -1)
{
const char* key = nullptr;
do
{
key = FIND_KVP(kvpHandle);
if (key)
{
trace("%s: %s\n", key, GET_RESOURCE_KVP_STRING(key));
}
} while (key);
END_FIND_KVP(kvpHandle);
}
Potential output:
mollis:1: vesuvius citrate
mollis:2: should be taken with alcohol
mollis:manufacturer: Betta Pharmaceuticals
FIND_KVP
Returns the current key a KVP find handle is pointing to, then increments the cursor.
Arguments:
handle (int): the KVP find handle returned from START_FIND_KVP.
Return value:
A string containing the current key, or null if the end of the iteration has been reached.
Example:
See START_FIND_KVP.
END_FIND_KVP
Closes a KVP find handle.
Arguments:
handle (int): the KVP find handle returned from START_FIND_KVP.
Return value:
None.
Example:
See START_FIND_KVP.