mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 15:36:02 +01:00
refactor(init): lib.notify server function
Client handler attempts to translate the notification if locales are loaded.
This commit is contained in:
26
init.lua
26
init.lua
@@ -58,6 +58,8 @@ end
|
|||||||
-- API
|
-- API
|
||||||
-----------------------------------------------------------------------------------------------
|
-----------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
local export = exports[ox_lib]
|
||||||
|
|
||||||
local function call(self, index, ...)
|
local function call(self, index, ...)
|
||||||
local module = rawget(self, index)
|
local module = rawget(self, index)
|
||||||
if not module then
|
if not module then
|
||||||
@@ -65,7 +67,7 @@ local function call(self, index, ...)
|
|||||||
|
|
||||||
if not module then
|
if not module then
|
||||||
local function method(...)
|
local function method(...)
|
||||||
return exports[ox_lib][index](nil, ...)
|
return export[index](nil, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
if not ... then
|
if not ... then
|
||||||
@@ -147,7 +149,7 @@ local ox = GetResourceState('ox_core') ~= 'missing' and setmetatable({}, {
|
|||||||
|
|
||||||
local _cache = setmetatable({}, {
|
local _cache = setmetatable({}, {
|
||||||
__index = function(self, key)
|
__index = function(self, key)
|
||||||
return rawset(self, key, exports[ox_lib].cache(nil, key) or false)[key]
|
return rawset(self, key, export.cache(nil, key) or false)[key]
|
||||||
end,
|
end,
|
||||||
|
|
||||||
__call = function(self)
|
__call = function(self)
|
||||||
@@ -172,8 +174,28 @@ cache = setmetatable({
|
|||||||
})
|
})
|
||||||
|
|
||||||
if service == 'client' then
|
if service == 'client' then
|
||||||
|
RegisterNetEvent(('%s:notify'):format(cache.resource), function(data)
|
||||||
|
if locale then
|
||||||
|
if data.title then
|
||||||
|
data.title = locale(data.title) or data.title
|
||||||
|
end
|
||||||
|
|
||||||
|
if data.description then
|
||||||
|
data.description = locale(data.description) or data.description
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return export:notify(data)
|
||||||
|
end)
|
||||||
|
|
||||||
cache.playerId = PlayerId()
|
cache.playerId = PlayerId()
|
||||||
cache.serverId = GetPlayerServerId(cache.playerId)
|
cache.serverId = GetPlayerServerId(cache.playerId)
|
||||||
|
else
|
||||||
|
local notify = ('%s:notify'):format(cache.resource)
|
||||||
|
|
||||||
|
function lib.notify(source, data)
|
||||||
|
TriggerClientEvent(notify, source, data)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Citizen.CreateThreadNow(function()
|
Citizen.CreateThreadNow(function()
|
||||||
|
|||||||
Reference in New Issue
Block a user