For the complete documentation index, see llms.txt. This page is also available as Markdown.

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)
Parameter
Type
Description

submoduleName

string

The name of the submodule to check for in the submodules table.

Type
Description

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: false

shallowcopy

Creates a shallow copy of a table or directly returns non-table values.

exports.sonorancad.shallowcopy(data)
Parameter
Type
Description

orig

any

The value or table to copy. Can be of any type: table, string, number, etc.

Type
Description

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)
Parameter
Type
Description

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

Type
Description

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.

Parameter
Type
Description

identifier

any

The identifier to search for, compared against the apiId field of each entry in LocationCache.

Type
Description

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.

Parameter
Type
Description

player

PlayerSource

The player source ID for whom the identifiers are being retrieved.

Type
Description

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.

Parameter
Type
Description

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.

Type
Description

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.

Parameter
Type
Description

tab

table

The table to search for the value.

val

any

The value to search for within the table.

Type
Description

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.

Parameter
Type
Description

version1

string

The first version string (e.g., 1.0.0).

version2

string

The second version string (e.g., 1.0.1).

Type
Description

table

  • result: true if version1 is greater than version2, false otherwise.

  • parsedVersion1: The weighted numeric representation of version1.

  • parsedVersion2: The weighted numeric representation of version2.

  • version1: The original version1 string.

  • version2: The original version2 string.

Last updated

Was this helpful?