Technical / ACR Data Persistence

Data persistence API

The following functions are available for use in scripts to store persistent data (available across server resets). Be sure to delete any data that is no longer needed or to set expiration on data that you know will only be relevant for a fixed duration. This will help keep the size of the database down and minimize latency on queries (that can lag the game).

Note: NWNx4 must be installed and configured properly? on the host server for these functions to work.

This function executes an SQL statement. - sSQL: The SQL string to execute - Returns: Nothing void ACR_SQLQuery(string sSQL)

This function retrieves the next row of the result set returned by the most recent query. Call this before using ACR_SQLGetData(). - mode: Selects a result set in a multi set result
Leave the parameter empty to advance to the next row in the resultset.
Pass "NEXT" as parameter to fetch the first row of the next resultset. - Returns: SQL_SUCCESS if there is a row, SQL_ERROR if there are no more rows. int ACR_SQLFetch(string mode = " ")

This function retrieves the data in a specific column within the current row of the result set. - nCol: The index of the column to retrieve (max column size 65K) in the result row - Returns: The data in column nCol string ACR_SQLGetData(int nCol = 0)

This function returns the number of rows that were affected by the last INSERT, UPDATE, or DELETE operation. - Returns: Number of rows affected int ACR_SQLGetAffectedRows()

This function handles special characters (like ') for database storage. Problems can arise with SQL commands if variables or values have single or double quotes in their names. This function encodes these quotes so the underlying database can safely store them. - sString: The string to encode string ACR_SQLEncodeSpecialChars(string sString)

This function stores a persistent string. - oObject: The object for which the data is being stored - sVarName: The unique variable name - sValue: The value to record Optional parameters: - iExpiration: The number of days the persistent variable should be kept in database (default: 0=forever) void ACR_SetPersistentString(object oObject, string sVarName, string sValue, int iExpiration = 0)

This function stores a persistent integer. - oObject: The object for which the data is being stored - sVarName: The unique variable name - iValue: The value to record Optional parameters: - iExpiration: The number of days the persistent variable should be kept in database (default: 0=forever) void ACR_SetPersistentInt(object oObject, string sVarName, int iValue, int iExpiration = 0)

This function stores a persistent float. - oObject: The object for which the data is being stored - sVarName: The unique variable name - fValue: The value to record Optional parameters: - iExpiration: The number of days the persistent variable should be kept in database (default: 0=forever) void ACR_SetPersistentFloat(object oObject, string sVarName, float fValue, int iExpiration = 0)

This function stores a persistent location. - oObject: The object for which the data is being stored - sVarName: The unique variable name - lValue: The value to record Optional parameters: - iExpiration: The number of days the persistent variable should be kept in database (default: 0=forever) void ACR_SetPersistentLocation(object oObject, string sVarName, location lValue, int iExpiration = 0)

This function stores a persistent vector. - oObject: The object for which the data is being stored - sVarName: The unique variable name - vValue: The value to record Optional parameters: - iExpiration: The number of days the persistent variable should be kept in database (default: 0=forever) void ACR_SetPersistentVector(object oObject, string sVarName, vector vValue, int iExpiration = 0)

This function stores a persistent object. - oObject: The object for which the data is being stored - sVarName: The unique variable name - oItem: The object to record Optional parameters: - iExpiration: The number of days the persistent variable should be kept in database (default: 0=forever) void ACR_SetPersistentObject(object oObject, string sVarName, object oItem, int iExpiration = 0)

This function retrieves a persistent string. - oObject: The object for which the data is being retrieved - sVarName: The unique variable name - Returns: '' on error string ACR_GetPersistentString(object oObject, string sVarName)

This function retrieves a persistent int. - oObject: The object for which the data is being retrieved - sVarName: The unique variable name - Returns: 0 on error int ACR_GetPersistentInt(object oObject, string sVarName)

This function retrieves a persistent float. - oObject: The object for which the data is being retrieved - sVarName: The unique variable name - Returns: 0 on error float ACR_GetPersistentFloat(object oObject, string sVarName)

This function retrieves a persistent location. - oObject: The object for which the data is being retrieved - sVarName: The unique variable name - Returns: 0 on error location ACR_GetPersistentLocation(object oObject, string sVarname)

This function retrieves a persistent vector. - oObject: The object for which the data is being retrieved - sVarName: The unique variable name - Returns: 0 on error vector ACR_GetPersistentVector(object oObject, string sVarName)

This function retrieves a persistent object. - oObject: The object for which the data is being retrieved - sVarName: The unique variable name - Returns: 0 on error object ACR_GetPersistentObject(object oObject, string sVarName)

This function deletes a persistent record. - oObject: The object for which the data is being deleted - sVarName: The unique variable name void ACR_DeletePersistentVariable(object oObject, string sVarName)

This function converts a location to a string. - lLocation: The location to convert - Returns: A string equivalent string ACR_LocationToString(location lLocation)

This function converts a string to a location. - sLocation: The string to convert - Returns: A location location ACR_StringToLocation(string sLocation)

This function converts a vector to a string. - vVector: The vector to convert - Returns: A string equivalent string ACR_VectorToString(vector vVector)

This function converts a string to a vector. - sVector: The string to convert - Returns: A vector vector ACR_StringToVector(string sVector)

This function retrieves the CD Key of the player - always use this with exit events in place of the normal NWScript function (it returns null). - oPC: player whose CD Key to retrieve - Returns: oPC's CD Key string ACR_GetPCPublicCDKey(object oPC)

This function retrieves the database ID of the character (useful for direct queries using ACR_SQLQuery()). - oPC: player whose character ID to retrieve - Returns: oPC's character ID int ACR_GetCharacterID(object oPC)

 

Auxiliary database connections

There is support for creating "auxiliary" database connections (to other MySQL servers), though this support is not recommended for most usage.  Use the standard data persistence API instead in nearly all cases.

Auxiliary database connection documentation page.