Json проблема

auf.exe

Участник
Автор темы
41
12
Версия MoonLoader
.026-beta
Здравствуйте, сегодня решил изучить таблицы в json, проблема в том что не могу понять, можно ли сохранять в джсон массивы без ключей и как их потом читать и найти их в списке, загружаю свой скрипт
Луа:
require 'lib.moonloader'
local imgui = require 'imgui'


local windowState = imgui.ImBool(false)
local x,y = getScreenResolution()

local combo_test = imgui.ImInt(0)
local textBuffer = imgui.ImBuffer(256)

local places = {"Ацтек", "Groove", "Rifa"}
local placesX = {2512,2498,2189}
local placesY = {-2004,-1683,-1795}
local placesZ = {13,13,13}

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('fgps', cmd_find)
    sampRegisterChatCommand('fgpsmenu', cmd_findmenu)
    while true do
        wait(0)
        imgui.Process = windowState.v
    end
end

function cmd_find(place)
    for i in ipairs(places) do
        if place:find(places[i]) then
            sampAddChatMessage(places[i] .. " = " .. placesX[i] .." ".. placesY[i] .." "..  placesZ[i], -1)
            checkpoint = addBlipForCoord(placesX[i], placesY[i], placesZ[i])
            marker = createCheckpoint(1, placesX[i], placesY[i], placesZ[i], 1, 1, 1, 10)
            lua_thread.create(function()
                repeat
                    wait(0)
                    local x,y,z = getCharCoordinates(PLAYER_PED)
                until getDistanceBetweenCoords3d(x,y,z, placesX[i], placesY[i], placesZ[i]) < 10 or not doesBlipExist(checkpoint)
                deleteCheckpoint(marker)
                removeBlip(checkpoint)
            end)
        end
    end
end

function cmd_findmenu()
    windowState.v = not windowState.v
end

function imgui.OnDrawFrame()
    imgui.SetNextWindowPos(imgui.ImVec2(x / 2, y / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
    imgui.SetNextWindowSize(imgui.ImVec2(500, 400), imgui.Cond.FirstUseEver)
    imgui.Begin("FGPS", windowState, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoMove + imgui.WindowFlags.NoTitleBar)
    imgui.Combo('test', combo_test, places, #places)
    imgui.InputText('Текст для поиска', textBuffer)
    if imgui.Button('Save', imgui.ImVec2(40, 20)) then
        places[combo_test.v + 1] = textBuffer.v
    end
    imgui.End()
end
Подсвеченые строки это те которые нужно сохранить в файл джсон
 

хуега)

РП игрок
Модератор
2,576
2,279
Здравствуйте, сегодня решил изучить таблицы в json, проблема в том что не могу понять, можно ли сохранять в джсон массивы без ключей и как их потом читать и найти их в списке, загружаю свой скрипт
Луа:
require 'lib.moonloader'
local imgui = require 'imgui'


local windowState = imgui.ImBool(false)
local x,y = getScreenResolution()

local combo_test = imgui.ImInt(0)
local textBuffer = imgui.ImBuffer(256)

local places = {"Ацтек", "Groove", "Rifa"}
local placesX = {2512,2498,2189}
local placesY = {-2004,-1683,-1795}
local placesZ = {13,13,13}

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('fgps', cmd_find)
    sampRegisterChatCommand('fgpsmenu', cmd_findmenu)
    while true do
        wait(0)
        imgui.Process = windowState.v
    end
end

function cmd_find(place)
    for i in ipairs(places) do
        if place:find(places[i]) then
            sampAddChatMessage(places[i] .. " = " .. placesX[i] .." ".. placesY[i] .." "..  placesZ[i], -1)
            checkpoint = addBlipForCoord(placesX[i], placesY[i], placesZ[i])
            marker = createCheckpoint(1, placesX[i], placesY[i], placesZ[i], 1, 1, 1, 10)
            lua_thread.create(function()
                repeat
                    wait(0)
                    local x,y,z = getCharCoordinates(PLAYER_PED)
                until getDistanceBetweenCoords3d(x,y,z, placesX[i], placesY[i], placesZ[i]) < 10 or not doesBlipExist(checkpoint)
                deleteCheckpoint(marker)
                removeBlip(checkpoint)
            end)
        end
    end
end

function cmd_findmenu()
    windowState.v = not windowState.v
end

function imgui.OnDrawFrame()
    imgui.SetNextWindowPos(imgui.ImVec2(x / 2, y / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
    imgui.SetNextWindowSize(imgui.ImVec2(500, 400), imgui.Cond.FirstUseEver)
    imgui.Begin("FGPS", windowState, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoMove + imgui.WindowFlags.NoTitleBar)
    imgui.Combo('test', combo_test, places, #places)
    imgui.InputText('Текст для поиска', textBuffer)
    if imgui.Button('Save', imgui.ImVec2(40, 20)) then
        places[combo_test.v + 1] = textBuffer.v
    end
    imgui.End()
end
Подсвеченые строки это те которые нужно сохранить в файл джсон
Покажу на одном примере:
Lua:
local placesY = {-2004,-1683,-1795}
print(placesY[1])

local json = encodeJson(placesY)
print(json)

local placesY1 = decodeJson(json)
print(placesY1[1])
 

auf.exe

Участник
Автор темы
41
12
Покажу на одном примере:
Lua:
local placesY = {-2004,-1683,-1795}
print(placesY[1])

local json = encodeJson(placesY)
print(json)

local placesY1 = decodeJson(json)
print(placesY1[1])
Ещё такой вопрос, как добавить в существующей массив ещё одну переменную, и также добавить пустую ячейку
 
  • Грустно
Реакции: qdIbp