-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathclient.lua
More file actions
69 lines (58 loc) · 1.66 KB
/
client.lua
File metadata and controls
69 lines (58 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
local isTableViewerOpen = false
local currentTableData = nil
local resourceVersion = GetResourceMetadata(GetCurrentResourceName(), 'version', 0) or '1.0.0'
---@param table any The table to be viewed
---@param title string Optional title for the table view
---@return boolean Success status
local function viewTable(table, title)
if type(table) ~= "table" then
print("bs-tableviewer: Input is not a table")
return false
end
local success, result = pcall(function()
return json.encode(table)
end)
if not success then
print("bs-tableviewer: Failed to encode table to JSON")
return false
end
currentTableData = result
isTableViewerOpen = true
SendNUIMessage({
action = 'openTableViewer',
data = result,
title = title,
version = resourceVersion
})
SetNuiFocus(true, true)
return true
end
RegisterNUICallback('closeTableViewer', function(_, cb)
isTableViewerOpen = false
SetNuiFocus(false, false)
currentTableData = nil
cb('ok')
end)
exports('debugTable', viewTable)
RegisterCommand('testviewer', function()
local testTable = {
name = "Test Table",
nested = {
value = 123,
array = {1, 2, 3, 4, 5},
deep = {
deeper = {
deepest = "Hello World"
}
}
},
array = {"a", "b", "c"},
boolean = true,
number = 42
}
viewTable(testTable, "Test Table Viewer")
end, false)
RegisterNetEvent('debugTable')
AddEventHandler('debugTable', function(tableData, title)
viewTable(tableData, title)
end)