Почему не работает скрипт?

Sanchez.

Известный
Автор темы
705
188
Что с скриптом не так? (Не пишите что говнокод, я новичок).
Lua:
script_name('UniversalHelperARZ')
script_author('Sanchez.')
script_description('Universal Helper for Arizona Role Play.')



local tag = "{DC143C}Universal{FFFFFF}Helper: "

local timestampcolor = 0x7B68EE



require "lib.moonloader"

local encoding = require 'encoding'

local inicfg = require 'inicfg'

local imgui = require 'imgui'

encoding.default = 'CP1251'

u8 = encoding.UTF8


local directIni = "moonloader\\settings.ini"

local mainIni = inicfg.load(nil, directIni)


if mainIni.hotkey == nil then

    mainIni.hotkey = {

        bindTime = "[18,82]",
        bindStyle = "[18,83]",
        bindLock = "[18,81]"
    }

end

local rkeys = require 'rkeys'

imgui.HotKey = require('imgui_addons').HotKey

local tLastKeys = {}

local ActiveTimeMenu = {

    v = decodeJson(mainIni.hotkey.bindTime)

}

local ActiveStyleMenu = {

    v = decodeJson(mainIni.hotkey.bindStyle)

}

local ActiveLockMenu = {

    v = decodeJson(mainIni.hotkey.bindLock)

}

imgui.SwitchContext()
local style = imgui.GetStyle()
local colors = style.Colors
local clr = imgui.Col
local ImVec4 = imgui.ImVec4
local ImVec2 = imgui.ImVec2

style.WindowPadding = ImVec2(15, 15)
style.WindowRounding = 6.0
style.FramePadding = ImVec2(5, 5)
style.FrameRounding = 4.0
style.ItemSpacing = ImVec2(12, 8)
style.ItemInnerSpacing = ImVec2(8, 6)
style.IndentSpacing = 25.0
style.ScrollbarSize = 15.0
style.ScrollbarRounding = 9.0
style.GrabMinSize = 5.0
style.GrabRounding = 3.0

colors[clr.Text] = ImVec4(0.80, 0.80, 0.83, 1.00)
colors[clr.TextDisabled] = ImVec4(0.24, 0.23, 0.29, 1.00)
colors[clr.WindowBg] = ImVec4(0.06, 0.05, 0.07, 1.00)
colors[clr.ChildWindowBg] = ImVec4(0.07, 0.07, 0.09, 1.00)
colors[clr.PopupBg] = ImVec4(0.07, 0.07, 0.09, 1.00)
colors[clr.Border] = ImVec4(0.80, 0.80, 0.83, 0.88)
colors[clr.BorderShadow] = ImVec4(0.92, 0.91, 0.88, 0.00)
colors[clr.FrameBg] = ImVec4(0.10, 0.09, 0.12, 1.00)
colors[clr.FrameBgHovered] = ImVec4(0.24, 0.23, 0.29, 1.00)
colors[clr.FrameBgActive] = ImVec4(0.56, 0.56, 0.58, 1.00)
colors[clr.TitleBg] = ImVec4(0.76, 0.31, 0.00, 1.00)
colors[clr.TitleBgCollapsed] = ImVec4(1.00, 0.98, 0.95, 0.75)
colors[clr.TitleBgActive] = ImVec4(0.80, 0.33, 0.00, 1.00)
colors[clr.MenuBarBg] = ImVec4(0.10, 0.09, 0.12, 1.00)
colors[clr.ScrollbarBg] = ImVec4(0.10, 0.09, 0.12, 1.00)
colors[clr.ScrollbarGrab] = ImVec4(0.80, 0.80, 0.83, 0.31)
colors[clr.ScrollbarGrabHovered] = ImVec4(0.56, 0.56, 0.58, 1.00)
colors[clr.ScrollbarGrabActive] = ImVec4(0.06, 0.05, 0.07, 1.00)
colors[clr.ComboBg] = ImVec4(0.19, 0.18, 0.21, 1.00)
colors[clr.CheckMark] = ImVec4(1.00, 0.42, 0.00, 0.53)
colors[clr.SliderGrab] = ImVec4(1.00, 0.42, 0.00, 0.53)
colors[clr.SliderGrabActive] = ImVec4(1.00, 0.42, 0.00, 1.00)
colors[clr.Button] = ImVec4(0.10, 0.09, 0.12, 1.00)
colors[clr.ButtonHovered] = ImVec4(0.24, 0.23, 0.29, 1.00)
colors[clr.ButtonActive] = ImVec4(0.56, 0.56, 0.58, 1.00)
colors[clr.Header] = ImVec4(0.10, 0.09, 0.12, 1.00)
colors[clr.HeaderHovered] = ImVec4(0.56, 0.56, 0.58, 1.00)
colors[clr.HeaderActive] = ImVec4(0.06, 0.05, 0.07, 1.00)
colors[clr.ResizeGrip] = ImVec4(0.00, 0.00, 0.00, 0.00)
colors[clr.ResizeGripHovered] = ImVec4(0.56, 0.56, 0.58, 1.00)
colors[clr.ResizeGripActive] = ImVec4(0.06, 0.05, 0.07, 1.00)
colors[clr.CloseButton] = ImVec4(0.40, 0.39, 0.38, 0.16)
colors[clr.CloseButtonHovered] = ImVec4(0.40, 0.39, 0.38, 0.39)
colors[clr.CloseButtonActive] = ImVec4(0.40, 0.39, 0.38, 1.00)
colors[clr.PlotLines] = ImVec4(0.40, 0.39, 0.38, 0.63)
colors[clr.PlotLinesHovered] = ImVec4(0.25, 1.00, 0.00, 1.00)
colors[clr.PlotHistogram] = ImVec4(0.40, 0.39, 0.38, 0.63)
colors[clr.PlotHistogramHovered] = ImVec4(0.25, 1.00, 0.00, 1.00)
colors[clr.TextSelectedBg] = ImVec4(0.25, 1.00, 0.00, 0.43)
colors[clr.ModalWindowDarkening] = ImVec4(1.00, 0.98, 0.95, 0.73)

local main_window_state = imgui.ImBool(false)

local text_buffer = imgui.ImBuffer(256)


local sw, sh = getScreenResolution()

function main()

    if not isSampLoaded() or not isSampfuncsLoaded() then return end

    while not isSampAvailable() do wait(100) end

    sampRegisterChatCommand("arzhelper", cmd_arzhelper)

    sampAddChatMessage(tag .. "{7B68EE}Скрипт успешно запущен!", timestampcolor)
    wait(300)
    sampAddChatMessage(tag .. "{7B68EE}Автор скрипта: {FFFFFF}Sanchez.", timestampcolor)
    sampAddChatMessage(tag .. "{7B68EE}Меню хелпера: {FFFFFF}/arzhelper", timestampcolor)

    imgui.Process = false

    bindTime = rkeys.registerHotKey(ActiveTimeMenu.v, true, timeFunc)
    bindStyle = rkeys.registerHotKey(ActiveStyleMenu.v, true, styleFunc)
    bindLock = rkeys.registerHotKey(ActiveLockMenu.v, true, lockFunc)

    while true do
        wait(0)

        if main_window_state.v == false then

            imgui.Process = false

        end

    end

end



function cmd_arzhelper()

    main_window_state.v = not main_window_state.v

    imgui.Process = main_window_state.v



end



function timeFunc()

    sampSendChat("/time")

end

function styleFunc()

    sampSendChat("/style")

end

function lockFunc()

    sampSendChat("/lock")

end



function imgui.TextQuestion(label, description)

    imgui.TextDisabled(label)

    if imgui.IsItemHovered() then

        imgui.BeginTooltip()
            imgui.PushTextWrapPos(600)
                imgui.TextUnformatted(description)
            imgui.PopTextWrapPos()
        imgui.EndTooltip()
    end
end



function imgui.OnDrawFrame()

    imgui.SetNextWindowSize(imgui.ImVec2(700, 300), imgui.Cond.FirstUseEver)

    imgui.SetNextWindowPos(imgui.ImVec2((sw / 2), sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))

    

    imgui.Begin(u8"Универсальный Helper для Arizona RP", main_window_state, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse)

    imgui.BeginChild('Select', imgui.ImVec2(200, -1), true)

    if imgui.Button(u8'Быстрые команды', imgui.ImVec2(176, 40), selected == 1) then selected = 1 end

    if imgui.Button(u8'Функции', imgui.ImVec2(176, 40), selected == 2) then selected = 2 end

    if imgui.Button(u8'Сокращенные команды', imgui.ImVec2(176, 40), selected == 3) then selected = 3 end

    if imgui.Button(u8'Информация о скрипте', imgui.ImVec2(176, 40), selected == 4) then selected = 4 end

    imgui.EndChild()

    imgui.SameLine()

    imgui.BeginChild("Main", imgui.ImVec2(-1, -1), true)

    if selected == 0 then

    elseif selected == 1 then

        -- Время --

        imgui.Text(u8'Посмотреть время:')

        imgui.SameLine()

        if imgui.HotKey("##1", ActiveTimeMenu, tLastKeys, 100) then

            rkeys.changeHotKey(bindTime, ActiveTimeMenu.v)

            sampAddChatMessage(tag .. "Успешно!", -1)

            mainIni.hotkey.bindTime = encodeJson(ActiveTimeMenu.v)
            inicfg.save(mainIni, directIni)

        end

        -- Время --

        imgui.Separator()
        -- Стиль езды --
        imgui.Text(u8'Изменить стиль езды:')
        
        imgui.SameLine()

        if imgui.HotKey("##2", ActiveStyleMenu, tLastKeys, 100) then

            rkeys.changeHotKey(bindStyle, ActiveStyleMenu.v)

            sampAddChatMessage(tag .. "Успешно!", -1)

            mainIni.hotkey.bindStyle = encodeJson(ActiveStyleMenu.v)
            inicfg.save(mainIni, directIni)

        end

        -- Стиль езды --
        imgui.Separator()
        -- Открыть/закрыть личное т.с --

        imgui.Text(u8'Открыть/закрыть личное т.с:')

        imgui.SameLine()

        if imgui.HotKey("##3", ActiveLockMenu, tLastKeys, 100) then

            rkeys.changeHotKey(bindLock, ActiveLockMenu.v)

            sampAddChatMessage(tag .. "Успешно!", -1)

            mainIni.hotkey.bindLock = encodeJson(ActiveLockMenu.v)
            inicfg.save(mainIni, directIni)

        end

        -- Открыть/закрыть личное т.с --



        

    elseif selected == 2 then imgui.Text(u8'Скоро...')

    elseif selected == 3 then imgui.Text(u8'Что-то ещё')

    elseif selected == 4 then
        imgui.SameLine(150) imgui.Text(u8"Информация о скрипте")
        imgui.Separator() imgui.Text(u8"") imgui.SameLine(150) imgui.Text(u8"Автор скрипта: Sanchez.")
        imgui.Text(u8"Если вы нашли недочёт в скрипте или хотите предложить идею,")
        imgui.Text(u8"то пишите мне в ВК: @maxlordeditz")
        imgui.Separator() imgui.Text(u8"") imgui.SameLine(150) imgui.Text(u8"Версия скрипта: 1.0")

end

imgui.EndChild()

    imgui.End()

end
Выдает такую ошибку:
UniversalHelperARZ: D:\GTA San Andreas\moonloader\UniversalHelperARZ.lua:31: attempt to index local 'mainIni' (a nil value)
stack traceback:
Что делать?