Shared Functions
This page will explain all exported functions from the SonoranCAD Core that can be used on the client and server side
isPluginLoaded
Checks if a specific plugin is loaded by searching through the submodules table.
exports.sonorancad.isPluginLoaded(submoduleName)submoduleName
string
The name of the submodule to check for in the submodules table.
boolean
true if the specified submodule (pluginName) is found in the submodules table. false otherwise.
submodules = { "callcommands", "dispatchnotify", "civintegration" }
local isLoaded = isPluginLoaded("dispatchnotify")
print(isLoaded) -- Output: true
local isLoaded2 = isPluginLoaded("vehreg")
print(isLoaded2) -- Output: falseshallowcopy
Creates a shallow copy of a table or directly returns non-table values.
exports.sonorancad.shallowcopy(data)orig
any
The value or table to copy. Can be of any type: table, string, number, etc.
any
If orig is a table: Returns a new table with the same key-value pairs as orig. If orig is not a table (e.g., a number, string, boolean): Returns the value directly.
-- Example 1: Shallow copying a table
local original = { a = 1, b = 2, c = { 3, 4 } }
local copy = exports.sonorancad.shallowcopy(original)
print(copy.a) -- Output: 1
print(copy.b) -- Output: 2
print(copy.c) -- Output: table: 0x... (same reference as original.c in shallow copy)
-- Example 2: Copying a non-table value
local value = 42
local valueCopy = exports.sonorancad.shallowcopy(value)
print(valueCopy) -- Output: 42
stringsplit
Splits a string into substrings based on a specified delimiter.
exports.sonorancad.stringsplit(inputstr, sep)inputstr
string
The input string that will be split into substrings based on a specified delimiter (sep)
sep
string
(Optional) If not provided, the default is "%s", which matches any whitespace character
table
The table contains the substrings of inputstr split by the delimiter sep. The substrings are stored sequentially starting at index 1
local result = exports.sonorancad.stringsplit("Hello,World,Lua", ",")
-- result = { "Hello", "World", "Lua" }
local result2 = exports.sonorancad.stringsplit("One Two Three")
-- result2 = { "One", "Two", "Three" } (uses default separator: whitespace)
findIndex
Searches for a specific identifier in the LocationCache table and returns the index of the first matching entry.
exports.sonorancad.findIndex(identifier)identifier
any
The identifier to search for, compared against the apiId field of each entry in LocationCache.
number or nil
The index (i) of the first entry in LocationCache whose apiId matches identifier. nil if no matching entry is found
-- Example: Searching for an identifier in LocationCache
LocationCache = {
{ apiId = 101, name = "LocationA" },
{ apiId = 202, name = "LocationB" },
{ apiId = 303, name = "LocationC" },
}
local index = exports.sonorancad.findIndex(202)
print(index) -- Output: 2
local notFound = exports.sonorancad.findIndex(404)
print(notFound) -- Output: nilGetIdentifiers
Extracts and organizes player identifiers into a key-value table format.
exports.sonorancad.GetIdentifiers(player)player
PlayerSource
The player source ID for whom the identifiers are being retrieved.
table
A key-value table where the keys are identifier types (e.g., steam, license, discord) and the values are the corresponding identifier strings.
local playerIdentifiers = exports.sonorancad.GetIdentifiers(1)
-- Output
-- playerIdentifiers = {
-- steam = "110000112345678",
-- license = "abcdef1234567890",
-- discord = "123456789012345678"
-- }
print(playerIdentifiers.steam) -- Output: 110000112345678
print(playerIdentifiers.license) -- Output: abcdef1234567890
print(playerIdentifiers.discord) -- Output: 123456789012345678
PerformHttpRequestS
Simplifies making HTTP requests by providing a wrapper around exports["sonorancad"]:HandleHttpRequest.
exports.sonorancad.PerformHttpRequestS(url, cb, method, data, headers)url
string
The URL to which the HTTP request is sent.
cb
function
The callback function executed when the HTTP request completes.
method
string
The HTTP method to use (e.g., GET, POST, PUT, DELETE).
data
string
(Optional) The data to send with the HTTP request. Defaults to an empty string.
headers
table
(Optional) A table containing custom headers for the HTTP request. Defaults to include X-User-Agent.
none
This function does not directly return a value. Results are handled asynchronously via the cb callback function.
-- Example: Performing a POST request with custom data
local function callback(statusCode, response)
print("Status:", statusCode)
print("Response:", response)
end
exports.sonorancad.PerformHttpRequestS(
"https://api.example.com/data",
callback,
"POST",
'{"key": "value"}',
{ ["Content-Type"] = "application/json" }
)
has_value
Checks if a specific value exists in a table.
exports.sonorancad.has_value(tab, val)tab
table
The table to search for the value.
val
any
The value to search for within the table.
boolean
true if val is found in the table tab. false if val is not found, or if tab is nil.
-- Example 1: Checking if a value exists in a table
local myTable = { "apple", "banana", "cherry" }
local exists = exports.sonorancad.has_value(myTable, "banana")
print(exists) -- Output: true
local notExists = exports.sonorancad.has_value(myTable, "grape")
print(notExists) -- Output: false
-- Example 2: Handling a nil table
local nilTable = nil
local result = exports.sonorancad.has_value(nilTable, "value")
print(result) -- Output: false (with debugLog: "nil passed to has_value, ignore")compareVersions
Compares two semantic version strings.
exports.sonorancad.compareVersions(version1, version2)version1
string
The first version string (e.g., 1.0.0).
version2
string
The second version string (e.g., 1.0.1).
table
result:trueifversion1is greater thanversion2,falseotherwise.
parsedVersion1: The weighted numeric representation ofversion1.parsedVersion2: The weighted numeric representation ofversion2.version1: The originalversion1string.version2: The originalversion2string.
-- Example: Comparing two versions
local comparison = exports.sonorancad.compareVersions("1.2.3", "1.1.10")
print(comparison.result) -- Output: true
print(comparison.parsedVersion1) -- Output: 10203
print(comparison.parsedVersion2) -- Output: 10110Last updated
Was this helpful?

