-
-
Notifications
You must be signed in to change notification settings - Fork 2
Library: Networker
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.
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"))()
-
✨ Retrieve's instance's type.
local string: type = self:getType()
-
✨ Creates a new network.
local network: cNetwork = assetify.network:create( string: name, bool: isCallback )
-
✨ Destroys an existing network.
local bool: result = self:destroy()
-
✨ Fetches network from name.
local network: cNetwork = assetify.network:fetch( string: name, bool: isRemote )
-
✨ 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 } )
-
✨ Unsubscribes a subscribed handler from the network.
local bool: result = self:off( function: exec )
-
✨ 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 )
-
-
✨ 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 )
-