keybind

uvie

Известный
Автор темы
267
54
simple keybind (-er) made by me lols
a simple problem, when you press the letter X, above, below the right an imgui_cpp error is thrown, but when you turn it off with the selected button, for example MOUSE4, there is no error

lazy 4 fix it beeeeeehehehehehe

Discord_2024-05-27_03-06-59.png

Lua:
local imgui = require 'imgui'
inicfg = require 'inicfg'
encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local key = require 'vkeys'
local memory = require 'memory'
local ffi = require 'ffi'
local fun = require 'fun'
pcall(require, 'sflua')
local sampev = require 'lib.samp.events'

local window = imgui.ImBool(false)
local act = true

ffi.cdef [[
int __stdcall GetVolumeInformationA(
    const char* lpRootPathName,
    char* lpVolumeNameBuffer,
    uint32_t nVolumeNameSize,
    uint32_t* lpVolumeSerialNumber,
    uint32_t* lpMaximumComponentLength,
    uint32_t* lpFileSystemFlags,
    char* lpFileSystemNameBuffer,
    uint32_t nFileSystemNameSize
);
]]
local serial = ffi.new("unsigned long[1]", 0)
ffi.C.GetVolumeInformationA(nil, nil, 0, serial, nil, nil, nil, 0)
serial = serial[0]

function main()
    while not isSampLoaded() do
        wait(0)
    end
    wait(1000)
    --[[if serial ~= 3736399178 then
        thisScript():unload()
    end]]

    imgui.Process = false
    window.v = false
    lua_thread.create(MiniBinder)
    while true do
        wait(100)
        if wasKeyPressed(key.VK_XBUTTON2) and isKeyCheckAvailable() then
            window.v = not window.v
        end
        imgui.Process = window.v
    end
end

local mainn = inicfg.load({

    keybind = {
        text1 = '',
        text2 = '',
        text3 = '',
        text4 = '',
        text5 = '',
        text6 = '',
        text7 = '',
        text8 = '',
        text9 = '',
        text10 = ''
    }

}, '..\\config\\Binder.ini')

local text1 = imgui.ImBuffer(tostring(mainn.keybind.text1), 256)
local text2 = imgui.ImBuffer(tostring(mainn.keybind.text2), 256)
local text3 = imgui.ImBuffer(tostring(mainn.keybind.text3), 256)
local text4 = imgui.ImBuffer(tostring(mainn.keybind.text4), 256)
local text5 = imgui.ImBuffer(tostring(mainn.keybind.text5), 256)
local text6 = imgui.ImBuffer(tostring(mainn.keybind.text6), 256)
local text7 = imgui.ImBuffer(tostring(mainn.keybind.text7), 256)
local text8 = imgui.ImBuffer(tostring(mainn.keybind.text8), 256)
local text9 = imgui.ImBuffer(tostring(mainn.keybind.text9), 256)
local text10 = imgui.ImBuffer(tostring(mainn.keybind.text10), 256)

function sampev.onSendCommand(text)
    if text:find('/keybind') then
        window.v = not window.v
        imgui.Process = window.v
    end
end

function imgui.OnDrawFrame()
    if window.v then
        imgui.SetNextWindowPos(imgui.ImVec2(350.0, 250.0), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowSize(imgui.ImVec2(339.0, 390), imgui.Cond.FirstUseEver)
        imgui.Begin('                                       Binder', window, imgui.WindowFlags.NoResize,
            imgui.WindowFlags.NoInputs, imgui.WindowFlags.NoMove, imgui.WindowFlags.NoFocusOnAppearing,
            imgui.WindowFlags.NoFocusOnAppearing + 8 + 16)
        imgui.Text('1')
        imgui.SameLine()
        imgui.InputText('', text1)
        imgui.Text('2')
        imgui.SameLine()
        imgui.InputText(' ', text2)
        imgui.Text('3')
        imgui.SameLine()
        imgui.InputText('  ', text3)
        imgui.Text('4')
        imgui.SameLine()
        imgui.InputText('   ', text4)
        imgui.Text('5')
        imgui.SameLine()
        imgui.InputText('    ', text5)
        imgui.Text('6')
        imgui.SameLine()
        imgui.InputText('     ', text6)
        imgui.Text('7')
        imgui.SameLine()
        imgui.InputText('      ', text7)
        imgui.Text('8')
        imgui.SameLine()
        imgui.InputText('       ', text8)
        imgui.Text('9')
        imgui.SameLine()
        imgui.InputText('        ', text9)
        imgui.Text('0')
        imgui.SameLine()
        imgui.InputText('          ', text10)

        if imgui.Button('SAVE BINDS') then
            mainn.keybind.text1 = text1.v
            mainn.keybind.text2 = text2.v
            mainn.keybind.text3 = text3.v
            mainn.keybind.text4 = text4.v
            mainn.keybind.text5 = text5.v
            mainn.keybind.text6 = text6.v
            mainn.keybind.text7 = text7.v
            mainn.keybind.text8 = text8.v
            mainn.keybind.text9 = text9.v
            mainn.keybind.text10 = text10.v
            inicfg.save(mainn, '..\\config\\Binder.ini')
        end
        imgui.SameLine()
        if imgui.Button('TOGGLE') then
            if act == false then
                act = true
                sampAddChatMessage('keybind ON', -1)
            else
                sampAddChatMessage('keybind OFF', -1)

                act = false
            end
        end
    end
    imgui.End()

end

function MiniBinder()
    while true do
        wait(0)
        if isKeyJustPressed(key.VK_1) and isKeyCheckAvailable() then
            sampSendChat(u8:decode(text1.v))
        end
        if isKeyJustPressed(key.VK_2) and isKeyCheckAvailable() then
            sampSendChat(u8:decode(text2.v))
        end
        if isKeyJustPressed(key.VK_3) and isKeyCheckAvailable() then
            sampSendChat(u8:decode(text3.v))
        end
        if isKeyJustPressed(key.VK_4) and isKeyCheckAvailable() then
            sampSendChat(u8:decode(text4.v))
        end
        if isKeyJustPressed(key.VK_5) and isKeyCheckAvailable() then
            sampSendChat(u8:decode(text5.v))
        end
        if isKeyJustPressed(key.VK_6) and isKeyCheckAvailable() then
            sampSendChat(u8:decode(text6.v))
        end
        if isKeyJustPressed(key.VK_7) and isKeyCheckAvailable() then
            sampSendChat(u8:decode(text7.v))
        end
        if isKeyJustPressed(key.VK_8) and isKeyCheckAvailable() then
            sampSendChat(u8:decode(text8.v))
        end
        if isKeyJustPressed(key.VK_9) and isKeyCheckAvailable() then
            sampSendChat(u8:decode(text9.v))
        end
        if isKeyJustPressed(key.VK_0) and isKeyCheckAvailable() then
            sampSendChat(u8:decode(text10.v))

        end
    end
end

function isKeyCheckAvailable()
    if sampIsChatInputActive() or sampIsDialogActive() then
        return false
    else
        return true
    end
end

function orange()
    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)
end
orange()
 

Вложения

  • keybind.lua
    9.2 KB · Просмотры: 7