script_name('KeyBinder')
script_author('KatanaBloodline')
require 'lib.moonloader'
local encoding = require 'encoding'
local imgui = require 'imgui'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local keys = {
{ name = 'A', code = 0x41 },
{ name = 'B', code = 0x42 },
{ name = 'C', code = 0x43 },
{ name = 'D', code = 0x44 },
{ name = 'E', code = 0x45 },
{ name = 'F', code = 0x46 },
{ name = 'G', code = 0x47 },
{ name = 'H', code = 0x48 },
{ name = 'I', code = 0x49 },
{ name = 'J', code = 0x4A },
{ name = 'K', code = 0x4B },
{ name = 'L', code = 0x4C },
{ name = 'M', code = 0x4D },
{ name = 'N', code = 0x4E },
{ name = 'O', code = 0x4F },
{ name = 'P', code = 0x50 },
{ name = 'Q', code = 0x51 },
{ name = 'R', code = 0x52 },
{ name = 'S', code = 0x53 },
{ name = 'T', code = 0x54 },
{ name = 'U', code = 0x55 },
{ name = 'V', code = 0x56 },
{ name = 'W', code = 0x57 },
{ name = 'X', code = 0x58 },
{ name = 'Y', code = 0x59 },
{ name = 'Z', code = 0x5A },
{ name = '0', code = 0x30 },
{ name = '1', code = 0x31 },
{ name = '2', code = 0x32 },
{ name = '3', code = 0x33 },
{ name = '4', code = 0x34 },
{ name = '5', code = 0x35 },
{ name = '6', code = 0x36 },
{ name = '7', code = 0x37 },
{ name = '8', code = 0x38 },
{ name = '9', code = 0x39 }
}
local key_names = {}
for i, v in ipairs(keys) do
table.insert(key_names, v.name)
end
local keybinds = {
{ selected_key = imgui.ImInt(0), command = imgui.ImBuffer(256), waiting_for_key = false },
{ selected_key = imgui.ImInt(0), command = imgui.ImBuffer(256), waiting_for_key = false },
{ selected_key = imgui.ImInt(0), command = imgui.ImBuffer(256), waiting_for_key = false },
{ selected_key = imgui.ImInt(0), command = imgui.ImBuffer(256), waiting_for_key = false }
}
local show_window = imgui.ImBool(false) -- Используем imgui.ImBool для управления отображением окна
local window_opacity = 0.0 -- Используем переменную для управления прозрачностью окна
local current_tab = imgui.ImInt(1) -- Переменная для отслеживания текущей вкладки
local blink_state = false -- Переменная для отслеживания состояния мигания
local blink_timer = 0 -- Таймер для мигания
function main()
while not isSampAvailable() do wait(100) end
sampRegisterChatCommand('keybind', function()
show_window.v = not show_window.v
if show_window.v then
window_opacity = 0.0
end
end)
sampAddChatMessage(u8('KeyBinder by KatanaBloodline загружен'), 0x1cd031)
sampAddChatMessage(u8('Открыть настройки: /keybind'), 0x1cd031)
while true do
wait(0)
blink_timer = blink_timer + 1
if blink_timer >= 30 then
blink_state = not blink_state
blink_timer = 0
end
for i, bind in ipairs(keybinds) do
if bind.waiting_for_key then
for j, v in ipairs(keys) do
if wasKeyPressed(v.code) then
bind.selected_key.v = j - 1
bind.waiting_for_key = false
sampAddChatMessage(u8('Клавиша изменена: ') .. u8(v.name), 0x1cd031) -- Отладочное сообщение
break
end
end
end
if bind.selected_key.v ~= 0 and wasKeyPressed(keys[bind.selected_key.v + 1].code) and not sampIsCursorActive() then
if bind.command.v:sub(1, 1) == '/' then
sampSendChat(u8(bind.command.v), true) -- Отправляем команду без отображения в чате
else
sampAddChatMessage(u8('Команда должна начинаться с символа /'), 0xFF0000)
end
end
end
imgui.Process = show_window.v
end
end
function imgui.OnDrawFrame()
if show_window.v then
if window_opacity < 1.0 then
window_opacity = window_opacity + 0.05
end
imgui.PushStyleVar(imgui.StyleVar.Alpha, window_opacity)
imgui.SetNextWindowPos(imgui.ImVec2(50, 400), imgui.Cond.FirstUseEver) -- Устанавливаем позицию окна
imgui.SetNextWindowSize(imgui.ImVec2(300, 400), imgui.Cond.FirstUseEver) -- Устанавливаем размер окна
imgui.Begin(u8('Key Binder'), show_window)
imgui.TextColored(imgui.ImVec4(1, 1, 0, 1), u8('Настройки биндов клавиш'))
imgui.Separator()
-- Вкладки
if imgui.Button(u8('Команда 1'), imgui.ImVec2(70, 30)) then current_tab.v = 1 end
imgui.SameLine()
if imgui.Button(u8('Команда 2'), imgui.ImVec2(70, 30)) then current_tab.v = 2 end
imgui.SameLine()
if imgui.Button(u8('Команда 3'), imgui.ImVec2(70, 30)) then current_tab.v = 3 end
imgui.SameLine()
if imgui.Button(u8('Команда 4'), imgui.ImVec2(70, 30)) then current_tab.v = 4 end
imgui.Separator()
-- Содержимое вкладок
local bind = keybinds[current_tab.v]
imgui.Text(u8('Выберите клавишу для команды ' .. current_tab.v .. ':'))
imgui.PushStyleVar(imgui.StyleVar.FrameRounding, 10)
if imgui.Button(u8('Назначить клавишу ' .. current_tab.v)) then
bind.waiting_for_key = true
sampAddChatMessage(u8('Нажмите клавишу для назначения'), 0x1cd031) -- Отладочное сообщение
end
imgui.PopStyleVar()
imgui.SameLine()
if bind.waiting_for_key and blink_state then
imgui.TextColored(imgui.ImVec4(1, 0, 0, 1), u8(keys[bind.selected_key.v + 1].name))
else
imgui.Text(u8(keys[bind.selected_key.v + 1].name))
end
imgui.Text(u8('Введите команду ' .. current_tab.v .. ':'))
imgui.InputText(u8('Команда ' .. current_tab.v), bind.command, imgui.InputTextFlags.CallbackAlways, function() end)
imgui.Separator()
imgui.PushStyleVar(imgui.StyleVar.FrameRounding, 10)
if imgui.Button(u8('Сохранить'), imgui.ImVec2(100, 30)) then
show_window.v = false
for i, bind in ipairs(keybinds) do
sampAddChatMessage(u8('Настройки сохранены: Клавиша = ') .. u8(keys[bind.selected_key.v + 1].name) .. u8(', Команда = ') .. u8(bind.command.v), 0x1cd031) -- Отладочное сообщение
end
end
imgui.PopStyleVar()
imgui.End()
imgui.PopStyleVar()
end
end