Server Helper

Server helper contains all methods of inherited Shared helper.


Import server helper

server.lua
---@type NssLibsServerHelper
SERVER_HELPER = exports.nss_libs:getServerHelper(GetCurrentResourceName())

Methods

getUniqueId()

Returns a unique id as string.

local unique_id = SERVER_HELPER:getUniqueId()
print(unique_id)

doUntilTimeout()

This call is synchronous and will block the server thread until the timeout is reached.

  • callback (function) - The function to call repeatedly until the timeout is reached.

  • timeout_in_ms (integer) - The timeout in milliseconds. 0 for infinite.

  • tick_in_ms (integer) - The tick (or duration) of the loop in milliseconds. 0 each frame.

Returns the optional return value of the callback if not nil or false. Otherwise nil.


waitUntilStarted()

This call is synchronous and will block the server thread until the timeout is reached.

  • resource_name (string) - The name of the resource that has to be started.

  • timeout_in_ms (integer) - The timeout in milliseconds. 0 for infinite.

  • tick_in_ms (integer) - The tick (or duration) of the loop in milliseconds. 0 each frame.

Returns true if the resource is started otherwise false if the timeout is reached.


waitUntilFirstStarted()

This call is synchronous and will block the server thread until the timeout is reached.

  • resource_names (table) - The names of the resources that one of them has to be started first.

  • timeout_in_ms (integer) - The timeout in milliseconds. 0 for infinite.

  • tick_in_ms (integer) - The tick (or duration) of the loop in milliseconds. 0 each frame.

Returns the name of the resource that is started first otherwise false if the timeout is reached.


createWrapperFinder()

For internal use only.

Note: This method is very complex and is used to find the correct wrapper/bridge for a framework like VORP or REDEM. But this solution is to complex and will be removed in the future.

Returns a new NssLibsWrapperFinder instance.


getCurrentTimestamp()

Returns the current timestamp derived from the system time of the server host in seconds as number (integer).


getInGameDate()

  • format (string, optional) - The format of the date string. Available placeholders are D (day), M (month), Y ( year). Default see Config.DefaultDateFormat.

Returns the current in-game date as formatted string or nilof no player is currently in-game.


getAllActivePlayerIds()

Returns a table with all active player ids integer[].


eachActivePlayer()

  • each_callback (function(BREAK_EACH_LOOP, server_player_id)) - The function to call for each active player.

    • BREAK_EACH_LOOP (boolean) - Constant: Return this value to break the loop.

    • server_player_id (integer) - The server player id.

Returns nothing.


hasPlayers()

Returns true if there are active players otherwise false.


dateToTimestamp()

  • date_string (string) - The date string to convert.

  • format (string, optional) - The format of the date string. Available placeholders are D (day), M (month), Y ( year). Default see Config.DefaultDateFormat.

Returns the timestamp derived from the date string in seconds as number (integer).


getInGameDateTimestamp()

  • format (string, optional) - The format of the date string. Available placeholders are D (day), M (month), Y ( year). Default see Config.DefaultDateFormat.

Returns the current in-game date as timestamp in seconds as number (integer) or nil if no player is currently in-game.


addEventHandler()

Important: If the related resource is stopped, the event will be removed automatically.

  • event_name (string) - The name of the event.

  • callback (function) - The function to call when the event is triggered.

    • If the callback returns false other additional callbacks registered after this callback will not be called.

  • resource_name (string) - The name of the resource that is listening to the event.

  • on_destroy_callback (function, optional) - Called before the event handler is destroyed. If the callback returns false the event handler will not be destroyed.

Returns a NssLibsSharedHelperEventHandlerApi instance.


requireFiles()

  • resource_name (string) - The name or filepath of the resource that requires the files.

  • filenames (string | string[]) - The name of the file or a list of file names to require.

  • additional_error_message (string, optional) - Additional error message which replaces the default error message.

  • silent (boolean, optional) - If true no error message will be printed by this method itself.

Returns true if all files are required otherwise false.


Last updated

Was this helpful?