помогите исправить код скрипта

XRLM

Известный
Автор темы
2,540
859
Версия MoonLoader
.026-beta
взял скрипт формуса с его группы с 18 урока, чтобы на его примере уже писать свое. выдает такую хуйню:
Код:
[ML] (error) Imgui Addons Hotkey: ... gta\REBUILT BLIN GTA\moonloader\imgui_lesson_18 (1).lua:18: attempt to index local 'mainIni' (a nil value)
stack traceback:
    ... gta\REBUILT BLIN GTA\moonloader\imgui_lesson_18 (1).lua:18: in main chunk
[ML] (error) Imgui Addons Hotkey: Script died due to an error. (186ABFF4)
код скрипта:
Lua:
script_name('Imgui Addons Hotkey') -- название скрипта
script_author('FORMYS') -- автор скрипта
script_description('Imgui Addons Hotkey Review') -- описание скрипта

require "lib.moonloader" -- подключение библиотеки
local keys = require "vkeys"
local imgui = require 'imgui'
local inicfg = require 'inicfg'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

local themes = import "resource/imgui_themes.lua"
local directIni = "moonloader\\settings.ini"

local mainIni = inicfg.load(nil, directIni)

if mainIni.hotkey == nil then -- если отсутствует секция hotkey в ини файле
    mainIni.hotkey = {
        bindClock = "[18,82]", -- alt + r
        bindPass = "[18,83]" -- alt + s
    }
end

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

local tLastKeys = {} -- тут будут храниться предыдущие хоткеи при переактивации

local ActiveClockMenu = {
    v = decodeJson(mainIni.hotkey.bindClock)
}

local ActivePassMenu = {
    v = decodeJson(mainIni.hotkey.bindPass)
}

main_window_state = imgui.ImBool(false)

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    sampRegisterChatCommand("hotkey", cmd_hotkey)

    _, id = sampGetPlayerIdByCharHandle(PLAYER_PED)
    nick = sampGetPlayerNickname(id)

    imgui.Process = false

    imgui.SwitchContext()
    themes.SwitchColorTheme()

    bindClock = rkeys.registerHotKey(ActiveClockMenu.v, true, clockFunc) -- создаем объект хоткея и регистрируем коллбэк функцию
    bindPass = rkeys.registerHotKey(ActivePassMenu.v, true, passFunc)

    while true do
        wait(0)

        -- Блок выполняющийся бесконечно (пока самп активен)

    end
end

function cmd_hotkey(arg)
    main_window_state.v = not main_window_state.v
    imgui.Process = main_window_state.v
end

function clockFunc()
    sampSendChat("/c 60")
end

function passFunc()
    sampSendChat("/pass " .. id)
end

function imgui.OnDrawFrame()

    if not main_window_state.v then
        imgui.Process = false
    end

    if main_window_state.v then
        local sw, sh = getScreenResolution()

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

        imgui.Begin('Imgui Hotkey Review', main_window_state, imgui.WindowFlags.NoCollapse)

        imgui.Text(u8"Посмотреть время")
        imgui.SameLine()
        if imgui.HotKey("##1", ActiveClockMenu, tLastKeys, 100) then
            rkeys.changeHotKey(bindClock, ActiveClockMenu.v)
            sampAddChatMessage("Успешно! Старое значение: {F4A460}" .. table.concat(rkeys.getKeysName(tLastKeys.v), " + ") .. "{ffffff} | Новое: {F4A460}" .. table.concat(rkeys.getKeysName(ActiveClockMenu.v), " + "), -1)
            sampAddChatMessage("Строчное значение: {F4A460}" .. encodeJson(ActiveClockMenu.v), -1)

            mainIni.hotkey.bindClock = encodeJson(ActiveClockMenu.v)
            inicfg.save(mainIni, directIni)
        end

        imgui.Text(u8"Посмотреть паспорт")
        imgui.SameLine()
        if imgui.HotKey("##2", ActivePassMenu, tLastKeys, 100) then
            rkeys.changeHotKey(bindPass, ActivePassMenu.v)
            sampAddChatMessage("Успешно! Старое значение: {F4A460}" .. table.concat(rkeys.getKeysName(tLastKeys.v), " + ") .. "{ffffff} | Новое: {F4A460}" .. table.concat(rkeys.getKeysName(ActivePassMenu.v), " + "), -1)
            sampAddChatMessage("Строчное значение: {F4A460}" .. encodeJson(ActivePassMenu.v), -1)

            mainIni.hotkey.bindPass = encodeJson(ActivePassMenu.v)
            inicfg.save(mainIni, directIni)
        end

        imgui.End()
    end
end
 

Hideme Flow

Известный
555
193
Lua:
script_name('Imgui Addons Hotkey') -- название скрипта
script_author('FORMYS') -- автор скрипта
script_description('Imgui Addons Hotkey Review') -- описание скрипта
require "lib.moonloader" -- подключение библиотеки
local keys = require "vkeys"
local imgui = require 'imgui'
local inicfg = require 'inicfg'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local themes = import "resource/imgui_themes.lua"
local directIni = "moonloader\\settings.ini"
local mainIni = inicfg.load(nil, directIni)
if mainIni == nil then -- если отсутствует вообще ini файо
    if mainIni.hotkey == nil then -- если отсутствует секция hotkey в ини файле
        mainIni.hotkey = {
            bindClock = "[18,82]", -- alt + r
            bindPass = "[18,83]" -- alt + s
        }
    end
end
local rkeys = require 'rkeys'
imgui.HotKey = require('imgui_addons').HotKey
local tLastKeys = {} -- тут будут храниться предыдущие хоткеи при переактивации
local ActiveClockMenu = {
    v = decodeJson(mainIni.hotkey.bindClock)
}
local ActivePassMenu = {
    v = decodeJson(mainIni.hotkey.bindPass)
}
main_window_state = imgui.ImBool(false)
function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    sampRegisterChatCommand("hotkey", cmd_hotkey)
    _, id = sampGetPlayerIdByCharHandle(PLAYER_PED)
    nick = sampGetPlayerNickname(id)
    imgui.Process = false
    imgui.SwitchContext()
    themes.SwitchColorTheme()
    bindClock = rkeys.registerHotKey(ActiveClockMenu.v, true, clockFunc) -- создаем объект хоткея и регистрируем коллбэк функцию
    bindPass = rkeys.registerHotKey(ActivePassMenu.v, true, passFunc)
    while true do
        wait(0)
        -- Блок выполняющийся бесконечно (пока самп активен)
    end
end
function cmd_hotkey(arg)
    main_window_state.v = not main_window_state.v
    imgui.Process = main_window_state.v
end
function clockFunc()
    sampSendChat("/c 60")
end
function passFunc()
    sampSendChat("/pass " .. id)
end
function imgui.OnDrawFrame()
    if not main_window_state.v then
        imgui.Process = false
    end
    if main_window_state.v then
        local sw, sh = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(300, 200), imgui.Cond.FirstUseEver)
        imgui.Begin('Imgui Hotkey Review', main_window_state, imgui.WindowFlags.NoCollapse)
        imgui.Text(u8"Посмотреть время")
        imgui.SameLine()
        if imgui.HotKey("##1", ActiveClockMenu, tLastKeys, 100) then
            rkeys.changeHotKey(bindClock, ActiveClockMenu.v)
            sampAddChatMessage("Успешно! Старое значение: {F4A460}" .. table.concat(rkeys.getKeysName(tLastKeys.v), " + ") .. "{ffffff} | Новое: {F4A460}" .. table.concat(rkeys.getKeysName(ActiveClockMenu.v), " + "), -1)
            sampAddChatMessage("Строчное значение: {F4A460}" .. encodeJson(ActiveClockMenu.v), -1)
            mainIni.hotkey.bindClock = encodeJson(ActiveClockMenu.v)
            inicfg.save(mainIni, directIni)
        end
        imgui.Text(u8"Посмотреть паспорт")
        imgui.SameLine()
        if imgui.HotKey("##2", ActivePassMenu, tLastKeys, 100) then
            rkeys.changeHotKey(bindPass, ActivePassMenu.v)
            sampAddChatMessage("Успешно! Старое значение: {F4A460}" .. table.concat(rkeys.getKeysName(tLastKeys.v), " + ") .. "{ffffff} | Новое: {F4A460}" .. table.concat(rkeys.getKeysName(ActivePassMenu.v), " + "), -1)
            sampAddChatMessage("Строчное значение: {F4A460}" .. encodeJson(ActivePassMenu.v), -1)
            mainIni.hotkey.bindPass = encodeJson(ActivePassMenu.v)
            inicfg.save(mainIni, directIni)
        end
        imgui.End()
    end
end
 

XRLM

Известный
Автор темы
2,540
859
Lua:
script_name('Imgui Addons Hotkey') -- название скрипта
script_author('FORMYS') -- автор скрипта
script_description('Imgui Addons Hotkey Review') -- описание скрипта
require "lib.moonloader" -- подключение библиотеки
local keys = require "vkeys"
local imgui = require 'imgui'
local inicfg = require 'inicfg'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local themes = import "resource/imgui_themes.lua"
local directIni = "moonloader\\settings.ini"
local mainIni = inicfg.load(nil, directIni)
if mainIni == nil then -- если отсутствует вообще ini файо
    if mainIni.hotkey == nil then -- если отсутствует секция hotkey в ини файле
        mainIni.hotkey = {
            bindClock = "[18,82]", -- alt + r
            bindPass = "[18,83]" -- alt + s
        }
    end
end
local rkeys = require 'rkeys'
imgui.HotKey = require('imgui_addons').HotKey
local tLastKeys = {} -- тут будут храниться предыдущие хоткеи при переактивации
local ActiveClockMenu = {
    v = decodeJson(mainIni.hotkey.bindClock)
}
local ActivePassMenu = {
    v = decodeJson(mainIni.hotkey.bindPass)
}
main_window_state = imgui.ImBool(false)
function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    sampRegisterChatCommand("hotkey", cmd_hotkey)
    _, id = sampGetPlayerIdByCharHandle(PLAYER_PED)
    nick = sampGetPlayerNickname(id)
    imgui.Process = false
    imgui.SwitchContext()
    themes.SwitchColorTheme()
    bindClock = rkeys.registerHotKey(ActiveClockMenu.v, true, clockFunc) -- создаем объект хоткея и регистрируем коллбэк функцию
    bindPass = rkeys.registerHotKey(ActivePassMenu.v, true, passFunc)
    while true do
        wait(0)
        -- Блок выполняющийся бесконечно (пока самп активен)
    end
end
function cmd_hotkey(arg)
    main_window_state.v = not main_window_state.v
    imgui.Process = main_window_state.v
end
function clockFunc()
    sampSendChat("/c 60")
end
function passFunc()
    sampSendChat("/pass " .. id)
end
function imgui.OnDrawFrame()
    if not main_window_state.v then
        imgui.Process = false
    end
    if main_window_state.v then
        local sw, sh = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(300, 200), imgui.Cond.FirstUseEver)
        imgui.Begin('Imgui Hotkey Review', main_window_state, imgui.WindowFlags.NoCollapse)
        imgui.Text(u8"Посмотреть время")
        imgui.SameLine()
        if imgui.HotKey("##1", ActiveClockMenu, tLastKeys, 100) then
            rkeys.changeHotKey(bindClock, ActiveClockMenu.v)
            sampAddChatMessage("Успешно! Старое значение: {F4A460}" .. table.concat(rkeys.getKeysName(tLastKeys.v), " + ") .. "{ffffff} | Новое: {F4A460}" .. table.concat(rkeys.getKeysName(ActiveClockMenu.v), " + "), -1)
            sampAddChatMessage("Строчное значение: {F4A460}" .. encodeJson(ActiveClockMenu.v), -1)
            mainIni.hotkey.bindClock = encodeJson(ActiveClockMenu.v)
            inicfg.save(mainIni, directIni)
        end
        imgui.Text(u8"Посмотреть паспорт")
        imgui.SameLine()
        if imgui.HotKey("##2", ActivePassMenu, tLastKeys, 100) then
            rkeys.changeHotKey(bindPass, ActivePassMenu.v)
            sampAddChatMessage("Успешно! Старое значение: {F4A460}" .. table.concat(rkeys.getKeysName(tLastKeys.v), " + ") .. "{ffffff} | Новое: {F4A460}" .. table.concat(rkeys.getKeysName(ActivePassMenu.v), " + "), -1)
            sampAddChatMessage("Строчное значение: {F4A460}" .. encodeJson(ActivePassMenu.v), -1)
            mainIni.hotkey.bindPass = encodeJson(ActivePassMenu.v)
            inicfg.save(mainIni, directIni)
        end
        imgui.End()
    end
end
можешь объяснить в чем там ошибка была?
 

XRLM

Известный
Автор темы
2,540
859
Lua:
script_name('Imgui Addons Hotkey') -- название скрипта
script_author('FORMYS') -- автор скрипта
script_description('Imgui Addons Hotkey Review') -- описание скрипта
require "lib.moonloader" -- подключение библиотеки
local keys = require "vkeys"
local imgui = require 'imgui'
local inicfg = require 'inicfg'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local themes = import "resource/imgui_themes.lua"
local directIni = "moonloader\\settings.ini"
local mainIni = inicfg.load(nil, directIni)
if mainIni == nil then -- если отсутствует вообще ini файо
    if mainIni.hotkey == nil then -- если отсутствует секция hotkey в ини файле
        mainIni.hotkey = {
            bindClock = "[18,82]", -- alt + r
            bindPass = "[18,83]" -- alt + s
        }
    end
end
local rkeys = require 'rkeys'
imgui.HotKey = require('imgui_addons').HotKey
local tLastKeys = {} -- тут будут храниться предыдущие хоткеи при переактивации
local ActiveClockMenu = {
    v = decodeJson(mainIni.hotkey.bindClock)
}
local ActivePassMenu = {
    v = decodeJson(mainIni.hotkey.bindPass)
}
main_window_state = imgui.ImBool(false)
function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    sampRegisterChatCommand("hotkey", cmd_hotkey)
    _, id = sampGetPlayerIdByCharHandle(PLAYER_PED)
    nick = sampGetPlayerNickname(id)
    imgui.Process = false
    imgui.SwitchContext()
    themes.SwitchColorTheme()
    bindClock = rkeys.registerHotKey(ActiveClockMenu.v, true, clockFunc) -- создаем объект хоткея и регистрируем коллбэк функцию
    bindPass = rkeys.registerHotKey(ActivePassMenu.v, true, passFunc)
    while true do
        wait(0)
        -- Блок выполняющийся бесконечно (пока самп активен)
    end
end
function cmd_hotkey(arg)
    main_window_state.v = not main_window_state.v
    imgui.Process = main_window_state.v
end
function clockFunc()
    sampSendChat("/c 60")
end
function passFunc()
    sampSendChat("/pass " .. id)
end
function imgui.OnDrawFrame()
    if not main_window_state.v then
        imgui.Process = false
    end
    if main_window_state.v then
        local sw, sh = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(300, 200), imgui.Cond.FirstUseEver)
        imgui.Begin('Imgui Hotkey Review', main_window_state, imgui.WindowFlags.NoCollapse)
        imgui.Text(u8"Посмотреть время")
        imgui.SameLine()
        if imgui.HotKey("##1", ActiveClockMenu, tLastKeys, 100) then
            rkeys.changeHotKey(bindClock, ActiveClockMenu.v)
            sampAddChatMessage("Успешно! Старое значение: {F4A460}" .. table.concat(rkeys.getKeysName(tLastKeys.v), " + ") .. "{ffffff} | Новое: {F4A460}" .. table.concat(rkeys.getKeysName(ActiveClockMenu.v), " + "), -1)
            sampAddChatMessage("Строчное значение: {F4A460}" .. encodeJson(ActiveClockMenu.v), -1)
            mainIni.hotkey.bindClock = encodeJson(ActiveClockMenu.v)
            inicfg.save(mainIni, directIni)
        end
        imgui.Text(u8"Посмотреть паспорт")
        imgui.SameLine()
        if imgui.HotKey("##2", ActivePassMenu, tLastKeys, 100) then
            rkeys.changeHotKey(bindPass, ActivePassMenu.v)
            sampAddChatMessage("Успешно! Старое значение: {F4A460}" .. table.concat(rkeys.getKeysName(tLastKeys.v), " + ") .. "{ffffff} | Новое: {F4A460}" .. table.concat(rkeys.getKeysName(ActivePassMenu.v), " + "), -1)
            sampAddChatMessage("Строчное значение: {F4A460}" .. encodeJson(ActivePassMenu.v), -1)
            mainIni.hotkey.bindPass = encodeJson(ActivePassMenu.v)
            inicfg.save(mainIni, directIni)
        end
        imgui.End()
    end
end
[ML] (error) Imgui Addons Hotkey: ... gta\REBUILT BLIN GTA\moonloader\imgui_lesson_18 (1).lua:15: attempt to index local 'mainIni' (a nil value)
stack traceback:
... gta\REBUILT BLIN GTA\moonloader\imgui_lesson_18 (1).lua:15: in main chunk
[ML] (error) Imgui Addons Hotkey: Script died due to an error. (103131D4)
все равно такая ошибка, мне кажется из-за nil в 15 строке

если меняю nil на
Lua:
{hotkey = {
    bindClock = "[18,82]", -- alt + r
    bindPass = "[18,83]" -- alt + s
}
то без ошибки работает