Initial commit
This commit is contained in:
25
client/client.lua
Normal file
25
client/client.lua
Normal file
@ -0,0 +1,25 @@
|
||||
local function toggleNuiFrame(shouldShow)
|
||||
SetNuiFocus(shouldShow, shouldShow)
|
||||
SendReactMessage('setVisible', shouldShow)
|
||||
end
|
||||
|
||||
RegisterCommand('show-nui', function()
|
||||
toggleNuiFrame(true)
|
||||
debugPrint('Show NUI frame')
|
||||
end)
|
||||
|
||||
RegisterNUICallback('hideFrame', function(_, cb)
|
||||
toggleNuiFrame(false)
|
||||
debugPrint('Hide NUI frame')
|
||||
cb({})
|
||||
end)
|
||||
|
||||
RegisterNUICallback('getClientData', function(data, cb)
|
||||
debugPrint('Data sent by React', json.encode(data))
|
||||
|
||||
-- Lets send back client coords to the React frame for use
|
||||
local curCoords = GetEntityCoords(PlayerPedId())
|
||||
|
||||
local retData <const> = { x = curCoords.x, y = curCoords.y, z = curCoords.z }
|
||||
cb(retData)
|
||||
end)
|
30
client/utils.lua
Normal file
30
client/utils.lua
Normal file
@ -0,0 +1,30 @@
|
||||
--- A simple wrapper around SendNUIMessage that you can use to
|
||||
--- dispatch actions to the React frame.
|
||||
---
|
||||
---@param action string The action you wish to target
|
||||
---@param data any The data you wish to send along with this action
|
||||
function SendReactMessage(action, data)
|
||||
SendNUIMessage({
|
||||
action = action,
|
||||
data = data
|
||||
})
|
||||
end
|
||||
|
||||
local currentResourceName = GetCurrentResourceName()
|
||||
|
||||
local debugIsEnabled = GetConvarInt(('%s-debugMode'):format(currentResourceName), 0) == 1
|
||||
|
||||
--- A simple debug print function that is dependent on a convar
|
||||
--- will output a nice prettfied message if debugMode is on
|
||||
function debugPrint(...)
|
||||
if not debugIsEnabled then return end
|
||||
local args <const> = { ... }
|
||||
|
||||
local appendStr = ''
|
||||
for _, v in ipairs(args) do
|
||||
appendStr = appendStr .. ' ' .. tostring(v)
|
||||
end
|
||||
local msgTemplate = '^3[%s]^0%s'
|
||||
local finalMsg = msgTemplate:format(currentResourceName, appendStr)
|
||||
print(finalMsg)
|
||||
end
|
Reference in New Issue
Block a user