ServerEvent
Communication example
client.lua
-- Gets the server event api.
---@type ServerEventApi
server_event_api = exports.nss_gta_libs:getServerEventApi(GetCurrentResourceName())
Citizen.CreateThread(function()
local times = 3
-- Example awaits result and blocks the thread as long as no result response is received.
-- The server event works like a synchronous function call.
local data = server_event_api:await("test", times)
print('Client Result', table.unpack(data))
-- The callback is executed async on server response.
-- Example does not await result and does not block the thread.
---@param response_data any|table
server_event_api:async("test", function(response_data)
print('Client Result', table.unpack(response_data))
end, times)
-- Example fires a global server event and does not wait for a result.
-- Example does not await result and does not block the thread.
server_event_api:fire("test", times)
end)server.lua
"on server ready" example
client.lua
server.lua
How it works
Last updated
Was this helpful?