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.
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
GetIdentifiers
Extracts and organizes player identifiers into a key-value table format.
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.
PerformHttpRequestS
Simplifies making HTTP requests by providing a wrapper around exports["sonorancad"]:HandleHttpRequest.
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.
has_value
Checks if a specific value exists in a table.
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.
compareVersions
Compares two semantic version strings.
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.
Last updated
Was this helpful?

