помощь с hotkey

tonytt

Новичок
Автор темы
13
1
Версия MoonLoader
.026-beta
нужно чтоб меню Imgui открывалось по назначенной клавише из settings.ini
при изменении клавиши ini файл меняет кнопку, но я не понимаю, как прописать кнопку из конфига в сам lua
Lua:
require 'moonloader'
require 'imgui'
local spawned = false
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

local imgui = require 'imgui'
local inicfg = require 'inicfg'
local key = require 'vkeys'
local directIni = "moonloader\\settings.ini"
local mainIni = inicfg.load(nil, directIni)
local tLastKeys = {}
local vk = require 'vkeys'
local sampev = require 'lib.samp.events'
if mainIni.hotkey == nil then
    mainIni.hotkey = {
        bindClock = "49"
    }
end

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

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

main_window_state = imgui.ImBool(false)

function main()
    sampRegisterChatCommand("kd", function() main_window_state.v = not main_window_state.v end)
    while not isSampAvailable() do wait(100) end
    bindClock = rkeys.registerHotKey(ActiveClockMenu.v, true, clockFunc)
    if wasKeyPressed(mainIni.hotkey.bindClock) then
        main_window_state.v = not main_window_state.v
    end
    while true do wait(1)
        if sampIsLocalPlayerSpawned() and not spawned then
            local ip, port = sampGetCurrentServerAddress()
                if ip == "185.169.134.3" or ip == "185.169.134.4"  or ip == "185.169.134.43" or ip == "185.169.134.44" or ip == "185.169.134.45" or ip == "185.169.134.5" or ip == "185.169.134.59" or ip == "185.169.134.61" or ip == "185.169.134.107" or ip == "185.169.134.109" or ip == "185.169.134.166" or ip == "185.169.134.171" or ip == "185.169.134.172" or ip == "185.169.134.173" or ip == "185.169.134.174" or ip =="80.66.82.191" or ip == "80.66.82.190" or ip == "80.66.82.188" or ip == "80.66.82.168" or ip == "80.66.82.159" or ip == "80.66.82.200" or ip == "" or ip == "80.66.82.144" then
            else
                sampAddChatMessage("{78b9ff}>> [Не любим перекупов!]{ffffff} Данный скрипт, работает только на серверах {db2e29}Arizona {ffffff}Role Play", -1)
                sampAddChatMessage("{78b9ff}>> [Не любим перекупов!]{ffffff} Данный скрипт, работает только на серверах {db2e29}Arizona {ffffff}Role Play", -1)
                sampAddChatMessage("{78b9ff}>> [Не любим перекупов!]{ffffff} Свяжитесь с разработчиком, если хотите уточнить возможность решения данной проблемы")
                sampShowDialog(6406, "Связь с разработчиком", "{78b9ff}ВКонтакте - {FFFFFF}https://vk.com/tony.everett/", "Понял", DIALOG_STYLE_INPUT)
                while sampIsDialogActive(6406) do wait(100) end
                local result, button, _, input = sampHasDialogRespond(6406)
                thisScript():unload()
                return
            end
            wait(0)
            name = sampGetCurrentServerName()
            sampAddChatMessage("{78b9ff}>> [Не любим перекупов!]{FFFFFF}: Проверка на сервер пройдена, вы сейчас на: {ff6a6a}"..name.."{FFFFFF}!", -1)
            sampAddChatMessage("{78b9ff}>> [Не любим перекупов!]{FFFFFF}: Приветствую, {FFFFFF}"..sampGetPlayerNickname(select(2, sampGetPlayerIdByCharHandle(PLAYER_PED))).."! {FFFFFF}Скрипт загружен и готов к работе", -1)
            sampAddChatMessage("{78b9ff}>> [Не любим перекупов!]{FFFFFF}: {FFFFFF}Разработчик скрипта - Администратор Page {FFFFFF}Tony Everett", -1)
            sampAddChatMessage("{78b9ff}>> [Не любим перекупов!]{FFFFFF}: {FFFFFF}Активация - {7eff39}/kd", -1)
            sampAddChatMessage("{78b9ff}>> [Не любим перекупов!]{FFFFFF}: {FFFFFF}Активная версия скрипта - {7eff39}1.0", -1)
            spawned = true
        end
    imgui.Process = main_window_state.v
    end
end

function clockFunc()
        main_window_state.v = not main_window_state.v
end


function sampev.onServerMessage(color, text)
    if isKeyDown(VK_F) then --LMENU = левый альт
        if text:find('{F345FC}[PREMIUM] {FFFFFF}%') then sampAddChatMessaget('/ot') end
    end
end
function imgui.OnDrawFrame()
    if main_window_state.v then
        imgui.SetNextWindowPos(imgui.ImVec2(imgui.GetIO().DisplaySize.x / 2, imgui.GetIO().DisplaySize.y / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(300, 100), imgui.Cond.FirstUseEver)
        imgui.Begin(u8"Не любим перекупов!", main_window_state, imgui.WindowFlags.NoResize)
        imgui.Text(u8'Клавиша открытия настроек:')
        imgui.SameLine()
        if imgui.HotKey("##1", ActiveClockMenu, tLastKeys, 100) then
            rkeys.changeHotKey(bindClock, ActiveClockMenu.v)
            sampAddChatMessage("{47ff7e}Клавиша успешно изменена, старая - {F4A460}" .. table.concat(rkeys.getKeysName(tLastKeys.v), " + "), -1)
            mainIni.hotkey.bindClock = encodeJson(ActiveClockMenu.v)
            inicfg.save(mainIni, directIni)
        
    end
        
        imgui.End()
    end
end

function imgui.TextColoredRGB(text)
  local style = imgui.GetStyle()
  local colors = style.Colors
  local ImVec4 = imgui.ImVec4
  local explode_argb = function(argb)
    local a = bit.band(bit.rshift(argb, 24), 0xFF)
    local r = bit.band(bit.rshift(argb, 16), 0xFF)
    local g = bit.band(bit.rshift(argb, 8), 0xFF)
    local b = bit.band(argb, 0xFF)
    return a, r, g, b
  end
  local getcolor = function(color)
    if color:sub(1, 6):upper() == 'SSSSSS' then
      local r, g, b = colors[1].x, colors[1].y, colors[1].z
      local a = tonumber(color:sub(7, 8), 16) or colors[1].w * 255
      return ImVec4(r, g, b, a / 255)
    end
    local color = type(color) == 'string' and tonumber(color, 16) or color
    if type(color) ~= 'number' then return end
    local r, g, b, a = explode_argb(color)
    return imgui.ImColor(r, g, b, a):GetVec4()
  end
  local render_text = function(text_)
    for w in text_:gmatch('[^\r\n]+') do
      local text, colors_, m = {}, {}, 1
      w = w:gsub('{(......)}', '{%1FF}')
      while w:find('{........}') do
        local n, k = w:find('{........}')
        local color = getcolor(w:sub(n + 1, k - 1))
        if color then
          text[#text], text[#text + 1] = w:sub(m, n - 1), w:sub(k + 1, #w)
          colors_[#colors_ + 1] = color
          m = n
        end
        w = w:sub(1, n - 1) .. w:sub(k + 1, #w)
      end
      if text[0] then
        for i = 0, #text do
          imgui.TextColored(colors_[i] or colors[1], text[i])
          imgui.SameLine(nil, 0)
        end
        imgui.NewLine()
      else imgui.Text(w) end
    end
  end
  render_text(text)
end

Код:
[hotkey]
bindClock=[49]
 
  • Эм
Реакции: qdIbp
Решение
нужно чтоб меню Imgui открывалось по назначенной клавише из settings.ini
при изменении клавиши ini файл меняет кнопку, но я не понимаю, как прописать кнопку из конфига в сам lua
Lua:
require 'moonloader'
require 'imgui'
local spawned = false
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

local imgui = require 'imgui'
local inicfg = require 'inicfg'
local key = require 'vkeys'
local directIni = "moonloader\\settings.ini"
local mainIni = inicfg.load(nil, directIni)
local tLastKeys = {}
local vk = require 'vkeys'
local sampev = require 'lib.samp.events'
if mainIni.hotkey == nil then
    mainIni.hotkey = {
        bindClock = "49"
    }
end

local rkeys = require 'rkeys'
imgui.HotKey =...

why ega

РП игрок
Модератор
2,522
2,184
нужно чтоб меню Imgui открывалось по назначенной клавише из settings.ini
при изменении клавиши ini файл меняет кнопку, но я не понимаю, как прописать кнопку из конфига в сам lua
Lua:
require 'moonloader'
require 'imgui'
local spawned = false
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

local imgui = require 'imgui'
local inicfg = require 'inicfg'
local key = require 'vkeys'
local directIni = "moonloader\\settings.ini"
local mainIni = inicfg.load(nil, directIni)
local tLastKeys = {}
local vk = require 'vkeys'
local sampev = require 'lib.samp.events'
if mainIni.hotkey == nil then
    mainIni.hotkey = {
        bindClock = "49"
    }
end

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

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

main_window_state = imgui.ImBool(false)

function main()
    sampRegisterChatCommand("kd", function() main_window_state.v = not main_window_state.v end)
    while not isSampAvailable() do wait(100) end
    bindClock = rkeys.registerHotKey(ActiveClockMenu.v, true, clockFunc)
    if wasKeyPressed(mainIni.hotkey.bindClock) then
        main_window_state.v = not main_window_state.v
    end
    while true do wait(1)
        if sampIsLocalPlayerSpawned() and not spawned then
            local ip, port = sampGetCurrentServerAddress()
                if ip == "185.169.134.3" or ip == "185.169.134.4"  or ip == "185.169.134.43" or ip == "185.169.134.44" or ip == "185.169.134.45" or ip == "185.169.134.5" or ip == "185.169.134.59" or ip == "185.169.134.61" or ip == "185.169.134.107" or ip == "185.169.134.109" or ip == "185.169.134.166" or ip == "185.169.134.171" or ip == "185.169.134.172" or ip == "185.169.134.173" or ip == "185.169.134.174" or ip =="80.66.82.191" or ip == "80.66.82.190" or ip == "80.66.82.188" or ip == "80.66.82.168" or ip == "80.66.82.159" or ip == "80.66.82.200" or ip == "" or ip == "80.66.82.144" then
            else
                sampAddChatMessage("{78b9ff}>> [Не любим перекупов!]{ffffff} Данный скрипт, работает только на серверах {db2e29}Arizona {ffffff}Role Play", -1)
                sampAddChatMessage("{78b9ff}>> [Не любим перекупов!]{ffffff} Данный скрипт, работает только на серверах {db2e29}Arizona {ffffff}Role Play", -1)
                sampAddChatMessage("{78b9ff}>> [Не любим перекупов!]{ffffff} Свяжитесь с разработчиком, если хотите уточнить возможность решения данной проблемы")
                sampShowDialog(6406, "Связь с разработчиком", "{78b9ff}ВКонтакте - {FFFFFF}https://vk.com/tony.everett/", "Понял", DIALOG_STYLE_INPUT)
                while sampIsDialogActive(6406) do wait(100) end
                local result, button, _, input = sampHasDialogRespond(6406)
                thisScript():unload()
                return
            end
            wait(0)
            name = sampGetCurrentServerName()
            sampAddChatMessage("{78b9ff}>> [Не любим перекупов!]{FFFFFF}: Проверка на сервер пройдена, вы сейчас на: {ff6a6a}"..name.."{FFFFFF}!", -1)
            sampAddChatMessage("{78b9ff}>> [Не любим перекупов!]{FFFFFF}: Приветствую, {FFFFFF}"..sampGetPlayerNickname(select(2, sampGetPlayerIdByCharHandle(PLAYER_PED))).."! {FFFFFF}Скрипт загружен и готов к работе", -1)
            sampAddChatMessage("{78b9ff}>> [Не любим перекупов!]{FFFFFF}: {FFFFFF}Разработчик скрипта - Администратор Page {FFFFFF}Tony Everett", -1)
            sampAddChatMessage("{78b9ff}>> [Не любим перекупов!]{FFFFFF}: {FFFFFF}Активация - {7eff39}/kd", -1)
            sampAddChatMessage("{78b9ff}>> [Не любим перекупов!]{FFFFFF}: {FFFFFF}Активная версия скрипта - {7eff39}1.0", -1)
            spawned = true
        end
    imgui.Process = main_window_state.v
    end
end

function clockFunc()
        main_window_state.v = not main_window_state.v
end


function sampev.onServerMessage(color, text)
    if isKeyDown(VK_F) then --LMENU = левый альт
        if text:find('{F345FC}[PREMIUM] {FFFFFF}%') then sampAddChatMessaget('/ot') end
    end
end
function imgui.OnDrawFrame()
    if main_window_state.v then
        imgui.SetNextWindowPos(imgui.ImVec2(imgui.GetIO().DisplaySize.x / 2, imgui.GetIO().DisplaySize.y / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(300, 100), imgui.Cond.FirstUseEver)
        imgui.Begin(u8"Не любим перекупов!", main_window_state, imgui.WindowFlags.NoResize)
        imgui.Text(u8'Клавиша открытия настроек:')
        imgui.SameLine()
        if imgui.HotKey("##1", ActiveClockMenu, tLastKeys, 100) then
            rkeys.changeHotKey(bindClock, ActiveClockMenu.v)
            sampAddChatMessage("{47ff7e}Клавиша успешно изменена, старая - {F4A460}" .. table.concat(rkeys.getKeysName(tLastKeys.v), " + "), -1)
            mainIni.hotkey.bindClock = encodeJson(ActiveClockMenu.v)
            inicfg.save(mainIni, directIni)
       
    end
       
        imgui.End()
    end
end

function imgui.TextColoredRGB(text)
  local style = imgui.GetStyle()
  local colors = style.Colors
  local ImVec4 = imgui.ImVec4
  local explode_argb = function(argb)
    local a = bit.band(bit.rshift(argb, 24), 0xFF)
    local r = bit.band(bit.rshift(argb, 16), 0xFF)
    local g = bit.band(bit.rshift(argb, 8), 0xFF)
    local b = bit.band(argb, 0xFF)
    return a, r, g, b
  end
  local getcolor = function(color)
    if color:sub(1, 6):upper() == 'SSSSSS' then
      local r, g, b = colors[1].x, colors[1].y, colors[1].z
      local a = tonumber(color:sub(7, 8), 16) or colors[1].w * 255
      return ImVec4(r, g, b, a / 255)
    end
    local color = type(color) == 'string' and tonumber(color, 16) or color
    if type(color) ~= 'number' then return end
    local r, g, b, a = explode_argb(color)
    return imgui.ImColor(r, g, b, a):GetVec4()
  end
  local render_text = function(text_)
    for w in text_:gmatch('[^\r\n]+') do
      local text, colors_, m = {}, {}, 1
      w = w:gsub('{(......)}', '{%1FF}')
      while w:find('{........}') do
        local n, k = w:find('{........}')
        local color = getcolor(w:sub(n + 1, k - 1))
        if color then
          text[#text], text[#text + 1] = w:sub(m, n - 1), w:sub(k + 1, #w)
          colors_[#colors_ + 1] = color
          m = n
        end
        w = w:sub(1, n - 1) .. w:sub(k + 1, #w)
      end
      if text[0] then
        for i = 0, #text do
          imgui.TextColored(colors_[i] or colors[1], text[i])
          imgui.SameLine(nil, 0)
        end
        imgui.NewLine()
      else imgui.Text(w) end
    end
  end
  render_text(text)
end

Код:
[hotkey]
bindClock=[49]
Вроде бы в этом видео объясняется, как сохранить хот-кеи в ини файл
 

VRush

https://t.me/vrushscript
Проверенный
2,349
1,093
INI:
[config]
key=74
Lua:
local inicfg = require('inicfg')
local imgui = require('imgui')


local mainIni = inicfg.load(nil, 'sw.ini')

function main()
    while not isSampAvailable() do wait(0) end
    while true do
        wait(0)
        if isKeyJustPressed(mainIni.config.key) then
            state = not state
            imgui.Process = state
        end
    end
end

function imgui.OnDrawFrame()
    imgui.Begin('')
    imgui.End()
end
я не про это, а про imgui hotkey
 

qdIbp

Автор темы
Проверенный
1,385
1,143
нужно чтоб меню Imgui открывалось по назначенной клавише из settings.ini
при изменении клавиши ini файл меняет кнопку, но я не понимаю, как прописать кнопку из конфига в сам lua
Lua:
require 'moonloader'
require 'imgui'
local spawned = false
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

local imgui = require 'imgui'
local inicfg = require 'inicfg'
local key = require 'vkeys'
local directIni = "moonloader\\settings.ini"
local mainIni = inicfg.load(nil, directIni)
local tLastKeys = {}
local vk = require 'vkeys'
local sampev = require 'lib.samp.events'
if mainIni.hotkey == nil then
    mainIni.hotkey = {
        bindClock = "49"
    }
end

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

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

main_window_state = imgui.ImBool(false)

function main()
    sampRegisterChatCommand("kd", function() main_window_state.v = not main_window_state.v end)
    while not isSampAvailable() do wait(100) end
    bindClock = rkeys.registerHotKey(ActiveClockMenu.v, true, clockFunc)
    if wasKeyPressed(mainIni.hotkey.bindClock) then
        main_window_state.v = not main_window_state.v
    end
    while true do wait(1)
        if sampIsLocalPlayerSpawned() and not spawned then
            local ip, port = sampGetCurrentServerAddress()
                if ip == "185.169.134.3" or ip == "185.169.134.4"  or ip == "185.169.134.43" or ip == "185.169.134.44" or ip == "185.169.134.45" or ip == "185.169.134.5" or ip == "185.169.134.59" or ip == "185.169.134.61" or ip == "185.169.134.107" or ip == "185.169.134.109" or ip == "185.169.134.166" or ip == "185.169.134.171" or ip == "185.169.134.172" or ip == "185.169.134.173" or ip == "185.169.134.174" or ip =="80.66.82.191" or ip == "80.66.82.190" or ip == "80.66.82.188" or ip == "80.66.82.168" or ip == "80.66.82.159" or ip == "80.66.82.200" or ip == "" or ip == "80.66.82.144" then
            else
                sampAddChatMessage("{78b9ff}>> [Не любим перекупов!]{ffffff} Данный скрипт, работает только на серверах {db2e29}Arizona {ffffff}Role Play", -1)
                sampAddChatMessage("{78b9ff}>> [Не любим перекупов!]{ffffff} Данный скрипт, работает только на серверах {db2e29}Arizona {ffffff}Role Play", -1)
                sampAddChatMessage("{78b9ff}>> [Не любим перекупов!]{ffffff} Свяжитесь с разработчиком, если хотите уточнить возможность решения данной проблемы")
                sampShowDialog(6406, "Связь с разработчиком", "{78b9ff}ВКонтакте - {FFFFFF}https://vk.com/tony.everett/", "Понял", DIALOG_STYLE_INPUT)
                while sampIsDialogActive(6406) do wait(100) end
                local result, button, _, input = sampHasDialogRespond(6406)
                thisScript():unload()
                return
            end
            wait(0)
            name = sampGetCurrentServerName()
            sampAddChatMessage("{78b9ff}>> [Не любим перекупов!]{FFFFFF}: Проверка на сервер пройдена, вы сейчас на: {ff6a6a}"..name.."{FFFFFF}!", -1)
            sampAddChatMessage("{78b9ff}>> [Не любим перекупов!]{FFFFFF}: Приветствую, {FFFFFF}"..sampGetPlayerNickname(select(2, sampGetPlayerIdByCharHandle(PLAYER_PED))).."! {FFFFFF}Скрипт загружен и готов к работе", -1)
            sampAddChatMessage("{78b9ff}>> [Не любим перекупов!]{FFFFFF}: {FFFFFF}Разработчик скрипта - Администратор Page {FFFFFF}Tony Everett", -1)
            sampAddChatMessage("{78b9ff}>> [Не любим перекупов!]{FFFFFF}: {FFFFFF}Активация - {7eff39}/kd", -1)
            sampAddChatMessage("{78b9ff}>> [Не любим перекупов!]{FFFFFF}: {FFFFFF}Активная версия скрипта - {7eff39}1.0", -1)
            spawned = true
        end
    imgui.Process = main_window_state.v
    end
end

function clockFunc()
        main_window_state.v = not main_window_state.v
end


function sampev.onServerMessage(color, text)
    if isKeyDown(VK_F) then --LMENU = левый альт
        if text:find('{F345FC}[PREMIUM] {FFFFFF}%') then sampAddChatMessaget('/ot') end
    end
end
function imgui.OnDrawFrame()
    if main_window_state.v then
        imgui.SetNextWindowPos(imgui.ImVec2(imgui.GetIO().DisplaySize.x / 2, imgui.GetIO().DisplaySize.y / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(300, 100), imgui.Cond.FirstUseEver)
        imgui.Begin(u8"Не любим перекупов!", main_window_state, imgui.WindowFlags.NoResize)
        imgui.Text(u8'Клавиша открытия настроек:')
        imgui.SameLine()
        if imgui.HotKey("##1", ActiveClockMenu, tLastKeys, 100) then
            rkeys.changeHotKey(bindClock, ActiveClockMenu.v)
            sampAddChatMessage("{47ff7e}Клавиша успешно изменена, старая - {F4A460}" .. table.concat(rkeys.getKeysName(tLastKeys.v), " + "), -1)
            mainIni.hotkey.bindClock = encodeJson(ActiveClockMenu.v)
            inicfg.save(mainIni, directIni)
     
    end
     
        imgui.End()
    end
end

function imgui.TextColoredRGB(text)
  local style = imgui.GetStyle()
  local colors = style.Colors
  local ImVec4 = imgui.ImVec4
  local explode_argb = function(argb)
    local a = bit.band(bit.rshift(argb, 24), 0xFF)
    local r = bit.band(bit.rshift(argb, 16), 0xFF)
    local g = bit.band(bit.rshift(argb, 8), 0xFF)
    local b = bit.band(argb, 0xFF)
    return a, r, g, b
  end
  local getcolor = function(color)
    if color:sub(1, 6):upper() == 'SSSSSS' then
      local r, g, b = colors[1].x, colors[1].y, colors[1].z
      local a = tonumber(color:sub(7, 8), 16) or colors[1].w * 255
      return ImVec4(r, g, b, a / 255)
    end
    local color = type(color) == 'string' and tonumber(color, 16) or color
    if type(color) ~= 'number' then return end
    local r, g, b, a = explode_argb(color)
    return imgui.ImColor(r, g, b, a):GetVec4()
  end
  local render_text = function(text_)
    for w in text_:gmatch('[^\r\n]+') do
      local text, colors_, m = {}, {}, 1
      w = w:gsub('{(......)}', '{%1FF}')
      while w:find('{........}') do
        local n, k = w:find('{........}')
        local color = getcolor(w:sub(n + 1, k - 1))
        if color then
          text[#text], text[#text + 1] = w:sub(m, n - 1), w:sub(k + 1, #w)
          colors_[#colors_ + 1] = color
          m = n
        end
        w = w:sub(1, n - 1) .. w:sub(k + 1, #w)
      end
      if text[0] then
        for i = 0, #text do
          imgui.TextColored(colors_[i] or colors[1], text[i])
          imgui.SameLine(nil, 0)
        end
        imgui.NewLine()
      else imgui.Text(w) end
    end
  end
  render_text(text)
end

Код:
[hotkey]
bindClock=[49]
Ты тут все подряд перемешал вызов дважды imgui, vkeys и попытка вытащить код из json в то время как у тебя идет подгрузка inicfg.load и так же его сохранение+ подк библиотеки смешать с переменными
Ты выбирай что нибудь одна ini или json
Lua:
require('moonloader')
local key = require('vkeys')
local sampev = require('lib.samp.events')
local imgui = require('imgui')

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

local encoding = require('encoding')
encoding.default = 'CP1251'
u8 = encoding.UTF8

local path = getGameDirectory()..'\\moonloader\\config\\settings.json'

local cfg = {
    bindClock = {
        v = {49}
    }
}
if not doesFileExist(path) then
    local f = io.open(path, 'w+')
    f:write(encodeJson(cfg)):close()
else
    local f = io.open(path, "r")
    a = f:read("*a")
    cfg = decodeJson(a)
    f:close()
end

local tLastKeys = {}
local window = imgui.ImBool(false)

local spawned = false
local ips = {
    "185.169.134.3",
    "185.169.134.4",
    "185.169.134.43",
    "185.169.134.44",
    "185.169.134.45",
    "185.169.134.5",
    "185.169.134.59",
    "185.169.134.61",
    "185.169.134.107",
    "185.169.134.109",
    "185.169.134.166",
    "185.169.134.171",
    "185.169.134.172",
    "185.169.134.173",
    "185.169.134.174",
    "80.66.82.191",
    "80.66.82.190",
    "80.66.82.188",
    "80.66.82.168",
    "80.66.82.159" ,
    "80.66.82.200",
    "80.66.82.144"
}

function main()
    while not isSampAvailable() do wait(100) end
        sampRegisterChatCommand("kd", function() window.v = not window.v end)
        if sampIsLocalPlayerSpawned() and not spawned then
            for i, k in pairs(ips) do
                local ip, port = sampGetCurrentServerAddress()
                if ip == k then
                    spawned = true
                    name = sampGetCurrentServerName()
                    sampAddChatMessage("{78b9ff}>> [Не любим перекупов!]{FFFFFF}: Проверка на сервер пройдена, вы сейчас на: {ff6a6a}"..name.."{FFFFFF}!", -1)
                    sampAddChatMessage("{78b9ff}>> [Не любим перекупов!]{FFFFFF}: Приветствую, {FFFFFF}"..sampGetPlayerNickname(select(2, sampGetPlayerIdByCharHandle(PLAYER_PED))).."! {FFFFFF}Скрипт загружен и готов к работе", -1)
                    sampAddChatMessage("{78b9ff}>> [Не любим перекупов!]{FFFFFF}: {FFFFFF}Разработчик скрипта - Администратор Page {FFFFFF}Tony Everett", -1)
                    sampAddChatMessage("{78b9ff}>> [Не любим перекупов!]{FFFFFF}: {FFFFFF}Активация - {7eff39}/kd", -1)
                    sampAddChatMessage("{78b9ff}>> [Не любим перекупов!]{FFFFFF}: {FFFFFF}Активная версия скрипта - {7eff39}1.0", -1)
                end
            end
            if not spawned then
                sampAddChatMessage(">> [Не любим перекупов!]{ffffff} Данный скрипт, работает только на серверах {db2e29}Arizona {ffffff}Role Play", 0x78b9ff)
                sampAddChatMessage(">> [Не любим перекупов!]{ffffff} Данный скрипт, работает только на серверах {db2e29}Arizona {ffffff}Role Play", 0x78b9ff)
                sampAddChatMessage(">> [Не любим перекупов!]{ffffff} Свяжитесь с разработчиком, если хотите уточнить возможность решения данной проблемы",0x78b9ff)
                sampShowDialog(6406, "Связь с разработчиком", "{78b9ff}ВКонтакте - {FFFFFF}https://vk.com/id666441368", "Открыть",'Понял', 0)
                while sampIsDialogActive(6406) do wait(100) end
                local res, butt, list, input = sampHasDialogRespond(6406)
                if butt == 1 then
                    os.execute('start https://vk.com/id666441368')
                    thisScript():unload()
                else
                    thisScript():unload()
                end
            end
        end
    while true do wait(0)
        if isKeyJustPressed(cfg.bindClock.v[1]) then
            window.v = not window.v
        end
        imgui.Process = window.v
        JSONSave()
    end
end

function sampev.onServerMessage(color, text)
    if isKeyDown(VK_F) then --LMENU = левый альт
        if text:find('{F345FC}[PREMIUM] {FFFFFF}%') then sampAddChatMessaget('/ot') end
    end
end
function imgui.OnDrawFrame()
    if window.v then
        imgui.SetNextWindowPos(imgui.ImVec2(imgui.GetIO().DisplaySize.x / 2, imgui.GetIO().DisplaySize.y / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(300, 100), imgui.Cond.FirstUseEver)
        imgui.Begin(u8"Не любим перекупов!", window, imgui.WindowFlags.NoResize)
            imgui.Text(u8'Клавиша открытия настроек:') imgui.SameLine()
            if imgui.HotKey("##1", cfg.bindClock, tLastKeys, 100) then
                rkeys.changeHotKey(bind, cfg.bindClock.v)
                JSONSave()
            end
        imgui.End()
    end
end

function imgui.TextColoredRGB(text)
    local style = imgui.GetStyle()
    local colors = style.Colors
    local ImVec4 = imgui.ImVec4
    local explode_argb = function(argb)
        local a = bit.band(bit.rshift(argb, 24), 0xFF)
        local r = bit.band(bit.rshift(argb, 16), 0xFF)
        local g = bit.band(bit.rshift(argb, 8), 0xFF)
        local b = bit.band(argb, 0xFF)
        return a, r, g, b
    end
    local getcolor = function(color)
        if color:sub(1, 6):upper() == 'SSSSSS' then
            local r, g, b = colors[1].x, colors[1].y, colors[1].z
            local a = tonumber(color:sub(7, 8), 16) or colors[1].w * 255
            return ImVec4(r, g, b, a / 255)
        end
        local color = type(color) == 'string' and tonumber(color, 16) or color
        if type(color) ~= 'number' then return end
        local r, g, b, a = explode_argb(color)
        return imgui.ImColor(r, g, b, a):GetVec4()
    end
    local render_text = function(text_)
        for w in text_:gmatch('[^\r\n]+') do
            local text, colors_, m = {}, {}, 1
            w = w:gsub('{(......)}', '{%1FF}')
            while w:find('{........}') do
                local n, k = w:find('{........}')
                local color = getcolor(w:sub(n + 1, k - 1))
                if color then
                    text[#text], text[#text + 1] = w:sub(m, n - 1), w:sub(k + 1, #w)
                    colors_[#colors_ + 1] = color
                    m = n
                end
                w = w:sub(1, n - 1) .. w:sub(k + 1, #w)
            end
            if text[0] then
                for i = 0, #text do
                    imgui.TextColored(colors_[i] or colors[1], text[i])
                    imgui.SameLine(nil, 0)
                end
                imgui.NewLine()
            else
                imgui.Text(w)
            end
        end
    end
    render_text(text)
end


function JSONSave()
    if doesFileExist(path) then
        local f = io.open(path, 'w+')
        if f then
            f:write(encodeJson(cfg)):close()
        end
    end
end

я написал лично на json
 
Последнее редактирование: