Initial commit

This commit is contained in:
Sticks
2024-06-09 20:24:22 -05:00
committed by GitHub
commit f16a32b63e
27 changed files with 845 additions and 0 deletions

25
client/client.lua Normal file
View 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
View 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