-
-
Notifications
You must be signed in to change notification settings - Fork 0
Feature: Networker
Tron edited this page Jan 13, 2023
·
2 revisions
Creating plenty of custom events creates unknowingly alot of issues on performance side. Moreover even the exports
provided by FiveM is slower and isn't asper our taste. With our networking solution, you can ditch default events and exports & use await/callbacks. Beyond that we had to do this primarily for our vEngine's network implementation.
Add the below code once in either of the shared .lua
script of the resource you want to use within:
--Declare it globally only once
loadstring(exports.assetify_library:import("networker"))()
local string: type = self:getType()
local network: cNetwork = assetify.network:create(
string: name,
bool: isCallback
)
local bool: result = self:destroy()
local network: cNetwork = assetify.network:fetch(
string: name,
bool: isRemote
)
--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
}
)
local bool: result = self:off(
function: exec
)
--Syntax #1:
--#Local
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 Only):
local bool: result = self:emit(...arguments)
⚠️ This method is only executable inside a valid thread
--Syntax #1:
--Local
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 Only):
local bool: result = self:emitCallback(
~: ...arguments
)