Shared Helper
The methods of the shared helper are available for and inherited to both client and server side.
In the following you will find the methods of the shared helper used for example on the server side via imported SERVER_HELPER
variable.
Methods
copyThisTo()
copyThisTo()
Note: This method is used to copy the methods of the shared helper to another table (e.g. a class like client helper or server helper).
table
(table) - The table to copy the methods of the shared helper to.unique_id_prefix
(string, optional) - The unique id prefix to use for the table.
Returns nothing.
getHashKey()
getHashKey()
name_or_hash
(string or number) - The name get the hash key from. If a hash is given it will be returned as is.
Returns the hash key as number
.
hasTableEntries()
hasTableEntries()
obj
(table or any) - The value to check if it is a table and has entries.
Returns true
if the value is a table and has entries. Otherwise false
.
toFloat()
toFloat()
value
(number) - The value to convert to float.
Returns the floated value as number
.
toInt()
toInt()
value
(number) - The value to convert to integer.
Returns the integer value as number
.
round()
round()
num
(number) - The number to round.decimals
(number) - The number of decimals to round.
Returns the rounded number as number
.
getDecimalCount()
getDecimalCount()
num
(number) - The number to get the decimal count from.
Returns the decimal count as number
.
inlineError()
inlineError()
message
(string) - The error message.traceback
(string, optional) - The traceback string.
Returns nothing.
inlineWarning()
inlineWarning()
message
(string) - The warning message.traceback
(string, optional) - The traceback string.
Returns nothing.
getEmptyFunction()
getEmptyFunction()
This method is useful if you have to use an empty function as a default value.
Returns an empty function.
strTrim()
strTrim()
str
(string or number) - The string to trim.
Returns the trimmed string as string
.
strSplit()
strSplit()
str
(string) - The string to split.separator
(string, optional) - The separator to split the string. Default is (space).max_times
(number, optional) - The maximum times to split the string. Default is-1
(infinite).
Returns a table with the split strings (table<string>
).
isSteamWebApiKeyAvailable()
isSteamWebApiKeyAvailable()
Checks the convar steam_webApiKey` if it is available. See convar documentation for more information.
Returns true
if the Steam Web API key is available. Otherwise false
.
getKeysFromTable()
getKeysFromTable()
tbl
(table) - The table to get the keys from.
Returns a table with the keys of the given table (table<string|number>
).
cleanFunctions()
cleanFunctions()
In case you want use json.encode
on an object that contains functions you can use this method to clean the functions.
obj
(any) - The object to clean the functions from.
Returns the cleaned object.
getDayMonthYearFromString()
getDayMonthYearFromString()
str
(string) - The date string.format
(string, optional) - The format of the date string. Available placeholders are D (day), M (month), Y ( year). Default seeConfig.DefaultDateFormat
.
Returns the date object NssLibsSharedHelperDateObject.
escapeMagicChars()
escapeMagicChars()
Escape the magic characters from a string which should be used as find pattern in string:gsub
.
str
(string) - The string to escape the magic characters from.
Returns the escaped string
.
debouncedClock()
debouncedClock()
In contrast to debounced()
, the cb
is called at least every delay_in_ms
value if the function is called continuously at shorter intervals than the delay_in_ms
value. The delay is therefore not reset with every call.
delay_in_ms
(number) - The delay in milliseconds.cb
(function) - The callback function.
Returns the debounced function
.
debounced()
debounced()
This is useful if you want to debounce a function. E.g. if you want to call a function only once after multiple calls in a short time.
delay_in_ms
(number) - The delay in milliseconds.cb
(function) - The callback function.
Returns the debounced function
.
isFloat()
isFloat()
value
(any) - The value to check if it is a float.
Returns true
if the value is a float. Otherwise false
.
isFunction()
isFunction()
value
(any) - The value to check if it is a function.
Returns true
if the value is a function. Otherwise false
.
isTable()
isTable()
value
(any) - The value to check if it is a table.
Returns true
if the value is a table. Otherwise false
.
isTableArray()
isTableArray()
This method uses a cache to prevent multiple checks of the same table with high cost of performance.
value
(any) - The value to check if it is a table array.prevent_cache
(boolean, optional) - Iftrue
the cache will be prevented.
Returns true
if the value is a table array. Otherwise false
.
createThreadSafeMonitor()
createThreadSafeMonitor()
Creates a new thread with a while loop that is thread safe. It can be started multiple times - but it will be started only once if it was already started. This is important if different sources triggers the monitor to start or stop.
interval_in_ms
(number) - The interval of the loop in milliseconds.cb_function
(function) - The callback function. See NssLibsSharedHelperMonitorCallback.The
cb_function
has no arguments and no return value.
Returns the monitor NssLibsSharedHelperMonitor
. See NssLibsSharedHelperMonitor for more information.
unixTimestampToDate()
unixTimestampToDate()
unix_timestamp
(number) - The unix timestamp to convert to date.
Returns the date as year
, month
, day
, hour
, minute
, second
as number
.
dateToUnixTimestamp()
dateToUnixTimestamp()
year
(number) - The year.month
(number) - The month.day
(number) - The day.hour
(number) - The hour.minute
(number) - The minute.second
(number) - The second.
Returns the unix timestamp as number
.
padWithZeros()
padWithZeros()
number
(number) - The number to pad with zeros.length
(number) - The length of the number.
Returns the padded number as string
.
createResourceEventName()
createResourceEventName()
This is useful if you have to create event names dynamically in the same way as the server and client does.
This method is for internal use primary.
resource_name
(string) - The resource name.event_name
(string) - The event name.
Returns the resource event name as string
.
isTableEqual()
isTableEqual()
table1
(table) - The first table to compare.table2
(table) - The second table to compare.deep
(boolean, optional) - If true the nested tables will be compared too. Default isfalse
.
Returns true
if the tables are equal. Otherwise false
.
createCallbackApi()
createCallbackApi()
Creates a simple callback handler.
callback
(function) - The callback which will be handled by the callback api.resource_name
(function) - The owning resource of the callback.
If the resource of the given resource_name
is stopped the callback will be disabled/destroyed automatically.
Returns NssLibsSharedHelperCallbackHandlerCbApi.
Objects
NssLibsSharedHelperDateObject
NssLibsSharedHelperDateObject
day
(number) - The day of the date.month
(number) - The month of the date.year
(number) - The year of the date.
NssLibsSharedHelperMonitorCallback
NssLibsSharedHelperMonitorCallback
Has no parameters and no return value.
NssLibsSharedHelperMonitor
NssLibsSharedHelperMonitor
Api for the monitor.
isRunning()
isRunning()
Returns true
if the monitor is running. Otherwise false
.
start()
start()
Starts the monitor (if not already started).
Returns the monitor NssLibsSharedHelperMonitor
.
stop()
stop()
Stops the monitor (if not already stopped).
Returns the monitor NssLibsSharedHelperMonitor
.
NssLibsSharedHelperEventHandlerApi
NssLibsSharedHelperEventHandlerApi
The following methods uses the following base structure for the examples:
getResourceName()
getResourceName()
New since version 0.35.0
Returns the resource name of the event handler api as string
.
setCustomData()
setCustomData()
New since version 0.35.0
key
(string or number) - The key to set.value
(any) - The value to set.
Returns the event handler NssLibsSharedHelperEventHandlerApi
.
getCustomData()
getCustomData()
New since version 0.35.0
key
(string or number) - The key to set.
Returns the value of the custom data as any
.
addSourceToCallback()
addSourceToCallback()
New since version 0.35.0
For server side only. Adds the source as first argument to the callback.
Returns the event handler NssLibsSharedHelperEventHandlerApi
.
doNotAddSourceToCallback()
doNotAddSourceToCallback()
New since version 0.35.0
For server side only. Do not add the source as first argument to the callback (default).
Returns the event handler NssLibsSharedHelperEventHandlerApi
.
enable()
enable()
Enables the event handler so all registered callbacks will be called when the event is triggered.
Returns the event handler NssLibsSharedHelperEventHandlerApi
.
disable()
disable()
Do the opposite of enable()
.
Disabled event handlers are still existing and are registered in the system but will not be called when the event is triggered.
Returns the event handler NssLibsSharedHelperEventHandlerApi
.
isEnabled()
isEnabled()
Returns true
if the event handler is enabled. Otherwise false
.
isDisabled()
isDisabled()
Returns true
if the event handler is disabled. Otherwise false
.
destroy()
destroy()
Removes the event handler from the system.
Destroyed event handlers does not exist anymore and are not registered in the system anymore. They can not be re-enabled.
Returns nothing.
addAdditionalCallback(callback)
addAdditionalCallback(callback)
callback
(function) - The additional callback to add.If the callback returns
false
other additional callbacks registered after this callback will not be called.
Returns the event handler NssLibsSharedHelperEventHandlerApi
.
getEventHandlerReference()
getEventHandlerReference()
Returns the original event handler reference of type any
.
getUid()
getUid()
Returns the unique id of the event handler api instance as number
.
NssLibsSharedHelperCallbackHandlerCbApi
NssLibsSharedHelperCallbackHandlerCbApi
The following methods uses the following base structure for the examples:
enable()
enable()
Enables the callback so if called it will be executed (except the callback was destroyed).
Returns the callback api NssLibsSharedHelperCallbackHandlerCbApi
.
disable()
disable()
Disables the callback so if called it will not be executed.
Disabled callback apis are still existing and are registered in the system but will not be called when the callback api is called.
Returns the callback api NssLibsSharedHelperCallbackHandlerCbApi
.
isEnabled()
isEnabled()
Returns true
if the callback api is enabled (and not destroyed).
isDisabled()
isDisabled()
Returns true
if the callback api is disabled (or destroyed).
isDestroyed()
isDestroyed()
Returns true
if the callback api is destroyed.
getResourceName()
getResourceName()
Returns the resource name of the callback api as string
.
getUid()
getUid()
Returns the unique identifier of the callback api as number
.
destroy()
destroy()
Destroys the callback api, so it can not be used anymore.
Returns the callback api NssLibsSharedHelperCallbackHandlerCbApi
.
onDestroy(on_destroy_callback)
onDestroy(on_destroy_callback)
on_destroy_callback
(function) - The callback to call when the callback api is destroyed. If the callback returnstrue
the destroy process will be canceled.
Returns the callback api NssLibsSharedHelperCallbackHandlerCbApi
.
call(...)
call(...)
...
(varargs, optional) - The variable arguments to pass to the callback.
Calls the original callback with the given arguments. If the callback api is disabled or destroyed the callback will not be called.
Returns the result of the callback.
Last updated