I need something like this: Iprint - Multi Theft Auto: Wiki
You probably want json.encode
Hi @Gaimo
Maybe the code below can help you:
dump = function(table, nb)
if nb == nil then
nb = 0
end
if type(table) == 'table' then
local s = ''
for i = 1, nb + 1, 1 do
s = s .. " "
end
s = '{\n'
for k,v in pairs(table) do
if type(k) ~= 'number' then k = '"'..k..'"' end
for i = 1, nb, 1 do
s = s .. " "
end
s = s .. '['..k..'] = ' .. ESX.dump(v, nb + 1) .. ',\n'
end
for i = 1, nb, 1 do
s = s .. " "
end
return s .. '}'
else
return tostring(table)
end
end
local vehicles = {
name = "police",
label = "Police",
siren = true,
damage = 1000
}
print(vehicles)
print(json.encode(vehicles))
print(dump(vehicles))
1 Like
local function tprint (tbl, indent)
if not indent then indent = 0 end
for k, v in pairs(tbl) do
formatting = string.rep(" ", indent) .. k .. ": "
if type(v) == "table" then
print(formatting)
tprint(v, indent+1)
elseif type(v) == 'boolean' then
print(formatting .. tostring(v))
else
print(formatting .. v)
end
end
end
Iām using this one, thanks for the answers!
Or you could just use json.encode(table, {indent = true})
This will format it for you and does not require any dump functions.
2 Likes
But dude, an entire dump function.