Skip to content

Library: Networker

ᴏᴠ ━ ᴀɴɪꜱᴀ edited this page Dec 5, 2024 · 15 revisions

» Overview

The creation of numerous custom events can inadvertently lead to significant performance issues. Additionally, the exports provided by MTA are often slower in comparison to call, which, while faster, may not align with our preferences. Our networking solution allows you to move away from the default events and exports, enabling the use of asynchronous operations such as await/callbacks similar to those in FiveM.

» Importing

Add the below code globally once in either of the shared .lua script of the resource you want to use within:

loadstring(exports.assetify_library:import("networker"))()

» APIs

  • assetify.network:getType() - shared

    Retrieve's instance's type.

    local string: type = self:getType()
  • assetify.network:create() - shared

    Creates a new network.

    local network: cNetwork = assetify.network:create(
       string: name,
       bool: isCallback
    )
  • assetify.network:destroy() - shared

    Destroys an existing network.

    local bool: result = self:destroy()
  • assetify.network:fetch() - shared

    Fetches network from name.

    local network: cNetwork = assetify.network:fetch(
       string: name,
       bool: isRemote
    )
  • assetify.network:on() - shared

    Subscribes a handler on a valid network.

    --Note #1: Non callback networks can have multiple handlers while callback supports only 1 handler
    --Note #2: When Async handling is enabled, first parameter is always a thread instance 
    local bool: result = self:on(
       function: exec,
       table: {
          bool: isAsync = true, --Enabling this makes the handler to run asynchronously
          bool: isPrioritized = true, --Enabling this prioritizes the handler to execute in the order they were registered
          int: subscriptionLimit = 5 --Enabling this limits the number of subscription
       }
    )
  • assetify.network:off() - shared

    Unsubscribes a subscribed handler from the network.

    local bool: result = self:off(
       function: exec
    )
  • assetify.network:emit() - shared

    Emits to a network.

    • Syntax #1

      --Local (Client -> Client / Server -> Server)
      local bool: result = assetify.network:emit(
         string: name,
         bool: isRemote = false,
         ~: ...arguments
      )
      
      --Client -> Server
      local bool: result = assetify.network:emit(
         string: name,
         bool: isRemote = true,
         bool: isLatent,
         ~: ...arguments
      )
      
      --Server -> Client
      local bool: result = assetify.network:emit(
         string: name,
         bool: isRemote = true,
         bool: isLatent,
         player: isReceiver,
         ~: ...arguments
      )
    • Syntax #2

      --Local (Client -> Client / Server -> Server)
      local bool: result = self:emit(
         ~: ...arguments
      )
  • assetify.network:emitCallback() - shared

    Emits to a network and awaits for its result.
    🚨API only executable inside a valid thread.

    • Syntax #1

      --Local (Client -> Client / Server -> Server)
      local bool: result = assetify.network:emitCallback(
         string: name,
         bool: isRemote = false,
         ~: ...arguments
      )
      
      --Client -> Server
      local bool: result = assetify.network:emitCallback(
         string: name,
         bool: isRemote = true,
         bool: isLatent,
         ~: ...arguments
      )
      
      --Server -> Client
      local bool: result = assetify.network:emitCallback(
         string: name,
         bool: isRemote = true,
         bool: isLatent,
         player: isReceiver,
         ~: ...arguments
      )
    • Syntax #2

      --Local (Client -> Client / Server -> Server)
      local bool: result = self:emitCallback(
         ~: ...arguments
      )