как в imgui с помощью checkbox сделать включение/выключения скрипта

lightmetal

Участник
Автор темы
32
3
Версия MoonLoader
.026-beta
как в imgui с помощью checkbox сделать включение/выключения скрипта
 
Решение
У тебя твой скрипт внутри imgui.OnFrame, а надо в бесконечном цикле отдельно.
Выделенные строки - те, что изменил. И табуляцию нормальную делай, пожалуйста.
Lua:
local imgui = require 'mimgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
local u8 = encoding.UTF8
 
local WinState = imgui.new.bool()
 
local tab = 1
local active_script = imgui.new.bool()
 
imgui.OnFrame(function() return WinState[0] end, function(player)
    imgui.SetNextWindowPos(imgui.ImVec2(500, 500), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
    imgui.SetNextWindowSize(imgui.ImVec2(400, 120), imgui.Cond.Always)
    imgui.Begin(u8'Пример', WinState, imgui.WindowFlags.NoResize)
    
    for numberTab, nameTab in...
Не чит конечно, но всё же.
Это чекбокс, который обнаруживает текст и удаляет его (если он включен).
Вот пример:


Lua:
local event = require 'lib.samp.events'

local delltext = new.bool() -- эта хуйня делает инпут или как оно, ну короче, без этой хуйни крашнет скрипт.

-- onFrame

if imgui.Checkbox(u8'Dellete text', delltext) then  end-- создаём сам чекбокс в мимгуи.

-- onFrame конец

function event.onServerMessage(col, text)
    if delltext[0] then -- 1
        if text:find('sex') then
            return false
        end
    end
end
 
Последнее редактирование:
  • Bug
Реакции: recxvery

#SameLine

Активный
417
37
как в imgui с помощью checkbox сделать включение/выключения скрипта
Lua:
-- locals
local active_script = imgui.new.bool()

-- onFrame
if imgui.Checkbox(u8'Включение/выключение', active_script) then
    --code
end

-- где-то в коде где ты обрабатываешь отображение окна mimgui
if active_script[0] then
    --отображаешь
end

Не чит конечно, но всё же.
Это чекбокс, который обнаруживает текст и удаляет его (если он включен).
Вот пример:


Lua:
local event = require 'lib.samp.events'

local delltext = new.bool() -- эта хуйня делает инпут или как оно, ну короче, без этой хуйни крашнет скрипт.

-- onFrame

if imgui.Checkbox(u8'Dellete text', delltext) then -- создаём сам чекбокс в мимгуи.

-- onFrame конец

function event.onServerMessage(col, text)
    if delltext[0] then -- 1
        if text:find('sex') then
            return false
        end
    end
end
Либо я долблюсь в глаза либо чел попросил сделать включение/выключение скрипта, а не удаление текста, и плюс правильный код будет:
Lua:
local delltext = imgui.new.bool()
так как чтобы использовать сокращенный твой метод нужно указать
Lua:
local new = imgui.new
local delltext = new.bool()
 

lightmetal

Участник
Автор темы
32
3
Можешь подсказать что я не так делаю. Чекбокс есть, но он не включает/выключает скрипт. Просто кнопка которая включается, выключается, без выполнения действия
Код:
local imgui = require 'mimgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
local u8 = encoding.UTF8
 
local WinState = imgui.new.bool()
 
local tab = 1
— locals
local active_script = imgui.new.bool()
 
imgui.OnFrame(function() return WinState[0] end, function(player)
 imgui.SetNextWindowPos(imgui.ImVec2(500, 500), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
 imgui.SetNextWindowSize(imgui.ImVec2(400, 120), imgui.Cond.Always)
 imgui.Begin(u8'Пример', WinState, imgui.WindowFlags.NoResize)
 for numberTab,nameTab in pairs({'Основное','Настройки','Инфа', 'Тест'}) do
 if imgui.Button(u8(nameTab), imgui.ImVec2(80,24)) then
 tab = numberTab
 end
 end
 imgui.SetCursorPos(imgui.ImVec2(95, 28))
 if imgui.BeginChild('Name##'..tab, imgui.ImVec2(300, 80), true) then
 —Содержимое вкладок
 if tab == 1 then
 if imgui.Checkbox(u8'Включение/выключение', active_script) then
 if active_script[0] then
 if wasKeyPressed(0x31) and not sampIsChatInputActive() and not sampIsDialogActive() then
 local result, ped = getCharPlayerIsTargeting(PLAYER_HANDLE)
 
 if result then
 _, id = sampGetPlayerIdByCharHandle(ped)
 sampSendChat('/me передал бандану')
 wait(1000)
 sampSendChat('/givecbook '..id..' 100')
 sampSendChat('/invite '..id)
 setVirtualKeyDown(13, true)
 wait(100)
 setVirtualKeyDown(13, false)
 accept = true
 end
 end
 end
 end
 end
 elseif tab == 2 then
 — что то будет
 end
 imgui.End()
end)
function main()
 sampRegisterChatCommand('cmdd', function() WinState[0] = not WinState[0] end)
 wait(-1)
end
 

Vintik

Мечтатель
Проверенный
1,470
920
У тебя твой скрипт внутри imgui.OnFrame, а надо в бесконечном цикле отдельно.
Выделенные строки - те, что изменил. И табуляцию нормальную делай, пожалуйста.
Lua:
local imgui = require 'mimgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
local u8 = encoding.UTF8
 
local WinState = imgui.new.bool()
 
local tab = 1
local active_script = imgui.new.bool()
 
imgui.OnFrame(function() return WinState[0] end, function(player)
    imgui.SetNextWindowPos(imgui.ImVec2(500, 500), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
    imgui.SetNextWindowSize(imgui.ImVec2(400, 120), imgui.Cond.Always)
    imgui.Begin(u8'Пример', WinState, imgui.WindowFlags.NoResize)
    
    for numberTab, nameTab in pairs({'Основное','Настройки','Инфа', 'Тест'}) do
        if imgui.Button(u8(nameTab), imgui.ImVec2(80,24)) then
            tab = numberTab
        end
    end
     imgui.SetCursorPos(imgui.ImVec2(95, 28))
    if imgui.BeginChild('Name##'..tab, imgui.ImVec2(300, 80), true) then
        -- Содержимое вкладок
        if tab == 1 then
            imgui.Checkbox(u8'Включение/выключение', active_script)
        end
    elseif tab == 2 then
        -- что то будет
    end
    
    imgui.End()
end)

function main()
    sampRegisterChatCommand('cmdd', function() WinState[0] = not WinState[0] end)
    while true do
        if active_script[0] then
            if wasKeyPressed(0x31) and not sampIsChatInputActive() and not sampIsDialogActive() then
                local result, ped = getCharPlayerIsTargeting(PLAYER_HANDLE)
                if result then
                    _, id = sampGetPlayerIdByCharHandle(ped)
                    sampSendChat('/me передал бандану')
                    wait(1000)
                    sampSendChat('/givecbook '..id..' 100')
                    sampSendChat('/invite '..id)
                    setVirtualKeyDown(13, true)
                    wait(100)
                    setVirtualKeyDown(13, false)
                    accept = true
                end
            end
        end
        wait(0)
    end
end
 
  • Нравится
Реакции: lightmetal

lightmetal

Участник
Автор темы
32
3
У тебя твой скрипт внутри imgui.OnFrame, а надо в бесконечном цикле отдельно.
Выделенные строки - те, что изменил. И табуляцию нормальную делай, пожалуйста.
Lua:
local imgui = require 'mimgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
local u8 = encoding.UTF8
 
local WinState = imgui.new.bool()
 
local tab = 1
local active_script = imgui.new.bool()
 
imgui.OnFrame(function() return WinState[0] end, function(player)
    imgui.SetNextWindowPos(imgui.ImVec2(500, 500), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
    imgui.SetNextWindowSize(imgui.ImVec2(400, 120), imgui.Cond.Always)
    imgui.Begin(u8'Пример', WinState, imgui.WindowFlags.NoResize)
   
    for numberTab, nameTab in pairs({'Основное','Настройки','Инфа', 'Тест'}) do
        if imgui.Button(u8(nameTab), imgui.ImVec2(80,24)) then
            tab = numberTab
        end
    end
     imgui.SetCursorPos(imgui.ImVec2(95, 28))
    if imgui.BeginChild('Name##'..tab, imgui.ImVec2(300, 80), true) then
        -- Содержимое вкладок
        if tab == 1 then
            imgui.Checkbox(u8'Включение/выключение', active_script)
        end
    elseif tab == 2 then
        -- что то будет
    end
   
    imgui.End()
end)

function main()
    sampRegisterChatCommand('cmdd', function() WinState[0] = not WinState[0] end)
    while true do
        if active_script[0] then
            if wasKeyPressed(0x31) and not sampIsChatInputActive() and not sampIsDialogActive() then
                local result, ped = getCharPlayerIsTargeting(PLAYER_HANDLE)
                if result then
                    _, id = sampGetPlayerIdByCharHandle(ped)
                    sampSendChat('/me передал бандану')
                    wait(1000)
                    sampSendChat('/givecbook '..id..' 100')
                    sampSendChat('/invite '..id)
                    setVirtualKeyDown(13, true)
                    wait(100)
                    setVirtualKeyDown(13, false)
                    accept = true
                end
            end
        end
        wait(0)
    end
end
Если я захочу добавлять ещё checkbox, radio, button , то нужно будет отдельными функциями это записывать?
 

Vintik

Мечтатель
Проверенный
1,470
920