вопрос по mimgui

kwzInside

Участник
Автор темы
65
7
Версия MoonLoader
.027.0-preview
у меня такой вопросик, как сделать так, чтобы при нажатии на чекбокс "Порт" в чат вводилась команда (например /farm), а после того, как вы убрали галочку с чекбокса она вводилась повторно?
Код:
script_author("kwzInside")
script_name("MultiBots")
script_version("1.0 Beta")
--==--libs--==--
require 'moonloader'
local imgui = require 'mimgui'
local sampev = require 'lib.samp.events'
local ffi = require 'ffi'
local encoding = require 'encoding'
encoding.default = 'CP1251'
local u8 = encoding.UTF8
local new, str = imgui.new, ffi.string
local inputField = new.char[256]()
local sizeX, sizeY = getScreenResolution()
local WinState, checkboxone, checkboxx = new.bool(), new.bool(), new.bool()
--==--list--==--
local list = {
    commands = {[[Разработчик скрипта kwzInside.
Версия скрипта 1.0 BETA. Данный скрипт имеет несколько ботов для фарма на разных работах, таких как: порт, лесопилка и тд.]]}
}
--==--Imgui--==--
local newFrame = imgui.OnFrame(
    function() return WinState[0] end,
    function(player)
        imgui.SetNextWindowPos(imgui.ImVec2(sizeX / 4, sizeY / 4), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(395, 205), imgui.Cond.Always)
        imgui.Begin('Multi Bots by kwzInside', WinState, imgui.WindowFlags.NoResize)
        if imgui.CollapsingHeader(u8'Информация') then
            imgui.TextWrapped(u8(table.concat(list.commands, '\n')), imgui.GetWindowSize())
        end
        imgui.Separator()
        imgui.Checkbox(u8'Порт', checkboxone)
        imgui.SameLine()
        imgui.Checkbox(u8'Лесопилка', checkboxx)
    end
)
function main()
    while not isSampAvailable() do wait(50) end
    sampRegisterChatCommand('mlb', function() WinState[0] = not WinState[0] end)
    while true do
        if checkboxone[0] then
            sampSendChat('/farm')
            wait(5000)
        end
        wait(0)
    end
end
 

kwzInside

Участник
Автор темы
65
7
как запихнуть этот код
Код:
script_name("PortBot")
script_authors("kwzInside")
script_description("Bot for farm AZ Rub")
script_version("1.0")
require "lib.moonloader"
function main()
    if not isSampfuncsLoaded() or not isSampLoaded() then return end
    sampRegisterChatCommand("farm", cmd_bot)
    local saveX = {}
    local saveY = {}
    local saveZ = {}
    while true do
        wait(0)
        if isPlayerPlaying(playerHandle) and enabled then
            BeginToPoint(2624.919922, -2191.280029, 16.980000, 1.000000, -255, false)
            BeginToPoint(2625.129883, -2196.550049, 15.780000, 1.000000, -255, false)
            BeginToPoint(2624.989990, -2204.419922, 13.570000, 1.000000, -255, false)
            BeginToPoint(2618.399902, -2205.149902, 13.570000, 1.000000, -255, false)
            BeginToPoint(2602.659912, -2198.709961, 13.570000, 1.000000, -255, false)
            BeginToPoint(2598.290039, -2196.709961, 13.570000, 1.000000, -255, false)
            wait(10000)
            local posX, posY, posZ = GetCoordinates()
            local mfind, mposX, mposY, mposZ = SearchMarker(posX, posY, posZ, 50.000000, false)
            if mfind then BeginToPoint(mposX, mposY, mposZ, 1.000000, -255, false) end
            BeginToPoint(2595.590088, -2195.459961, 13.570000, 1.000000, -255, false)
            BeginToPoint(2617.689941, -2203.689941, 13.570000, 1.000000, -255, false)
            BeginToPoint(2624.570068, -2202.550049, 13.570000, 1.000000, -255, false)
            BeginToPoint(2624.870117, -2191.820068, 16.980000, 1.000000, -255, false)
        end
    end
end


function BeginToPoint(x, y, z, radius, move_code, isSprint)
    repeat
        local posX, posY, posZ = GetCoordinates()
        SetAngle(x, y, z)
        MovePlayer(move_code, isSprint)
        local dist = getDistanceBetweenCoords3d(x, y, z, posX, posY, z)
        wait(0)
    until not enabled or dist < radius
end
function MovePlayer(move_code, isSprint)
    setGameKeyState(1, move_code)
    if isSprint then setGameKeyState(16, 255) end
end
function SetAngle(x, y, z)
    local posX, posY, posZ = GetCoordinates()
    local pX = x - posX
    local pY = y - posY
    local zAngle = getHeadingFromVector2d(pX, pY)
    if isCharInAnyCar(playerPed) then
        local car = storeCarCharIsInNoSave(playerPed)
        setCarHeading(car, zAngle)
    else
        setCharHeading(playerPed, zAngle)
    end
    restoreCameraJumpcut()
end
function GetCoordinates()
    if isCharInAnyCar(playerPed) then
        local car = storeCarCharIsInNoSave(playerPed)
        return getCarCoordinates(car)
    else
        return getCharCoordinates(playerPed)
    end
end
function cmd_bot(param)
    enabled = not enabled
    if enabled then
        sampAddChatMessage(string.format("[%s]: Активирован", thisScript().name), 0x40FF40)
    else
        sampAddChatMessage(string.format("[%s]: Деактивирован", thisScript().name), 0xFF4040)
    end
end
function teleportPlayer(x, y, z)
    if isCharInAnyCar(playerPed) then
        setCharCoordinates(playerPed, x, y, z)
    end
    setCharCoordinatesDontResetAnim(playerPed, x, y, z)
end
function setCharCoordinatesDontResetAnim(char, x, y, z)
    if doesCharExist(char) then
        local ptr = getCharPointer(char)
        setEntityCoordinates(ptr, x, y, z)
    end
end
function setEntityCoordinates(entityPtr, x, y, z)
    if entityPtr ~= 0 then
        local matrixPtr = readMemory(entityPtr + 0x14, 4, false)
        if matrixPtr ~= 0 then
            local posPtr = matrixPtr + 0x30
            writeMemory(posPtr + 0, 4, representFloatAsInt(x), false) --X
            writeMemory(posPtr + 4, 4, representFloatAsInt(y), false) --Y
            writeMemory(posPtr + 8, 4, representFloatAsInt(z), false) --Z
        end
    end
end
function SearchMarker(posX, posY, posZ, radius, isRace)
    local ret_posX = 0.0
    local ret_posY = 0.0
    local ret_posZ = 0.0
    local isFind = false
    for id = 0, 31 do
        local MarkerStruct = 0
        if isRace then MarkerStruct = 0xC7F168 + id * 56
        else MarkerStruct = 0xC7DD88 + id * 160 end
        local MarkerPosX = representIntAsFloat(readMemory(MarkerStruct + 0, 4, false))
        local MarkerPosY = representIntAsFloat(readMemory(MarkerStruct + 4, 4, false))
        local MarkerPosZ = representIntAsFloat(readMemory(MarkerStruct + 8, 4, false))
        if MarkerPosX ~= 0.0 or MarkerPosY ~= 0.0 or MarkerPosZ ~= 0.0 then
            if getDistanceBetweenCoords3d(MarkerPosX, MarkerPosY, MarkerPosZ, posX, posY, posZ) < radius then
                ret_posX = MarkerPosX
                ret_posY = MarkerPosY
                ret_posZ = MarkerPosZ
                isFind = true
                radius = getDistanceBetweenCoords3d(MarkerPosX, MarkerPosY, MarkerPosZ, posX, posY, posZ)
            end
        end
    end
    return isFind, ret_posX, ret_posY, ret_posZ
end
в код имгуи
Код:
script_author("kwzInside")
script_name("MultiBots")
script_version("1.0 Beta")
--==--libs--==--
require 'moonloader'
local imgui = require 'mimgui'
local sampev = require 'lib.samp.events'
local ffi = require 'ffi'
local encoding = require 'encoding'
encoding.default = 'CP1251'
local u8 = encoding.UTF8
local new, str = imgui.new, ffi.string
local inputField = new.char[256]()
local sizeX, sizeY = getScreenResolution()
local WinState, checkboxone, checkboxx = new.bool(), new.bool(), new.bool()
--==--list--==--
local list = {
    commands = {[[Разработчик скрипта kwzInside.
Версия скрипта 1.0 BETA. Данный скрипт имеет несколько ботов для фарма на разных работах, таких как: порт, лесопилка и тд.]]}
}
--==--Imgui--==--
local newFrame = imgui.OnFrame(
    function() return WinState[0] end,
    function(player)
        imgui.SetNextWindowPos(imgui.ImVec2(sizeX / 4, sizeY / 4), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(395, 205), imgui.Cond.Always)
        imgui.Begin('Multi Bots by kwzInside', WinState, imgui.WindowFlags.NoResize)
        if imgui.CollapsingHeader(u8'Информация') then
            imgui.TextWrapped(u8(table.concat(list.commands, '\n')), imgui.GetWindowSize())
        end
        imgui.Separator()
        imgui.Checkbox(u8'Порт', checkboxone)
        imgui.SameLine()
        imgui.Checkbox(u8'Лесопилка', checkboxx)
    end
)
function main()
    while not isSampAvailable() do wait(50) end
    sampRegisterChatCommand('mlb', function() WinState[0] = not WinState[0] end)
    while true do
        if checkboxone[0] then
            sampSendChat("/mn")
            wait(100)
        end
        wait(0)
    end
end
то есть чтобы при нажатии чекбокса "Порт" срабатывал этот код?
 

wojciech?

Известный
216
130
Зачем отдельно создавать функцию7
в целом, не обязательно. просто для удобства и чтобы сильно не мусорить в коде фрейма, да и функция может использоваться в других местах. но при желании нужный код можно запихать и внутрь проверки на нажатие чекбокса
 
  • Нравится
Реакции: Sadow

kwzInside

Участник
Автор темы
65
7
Lua:
-- в коде
function name()
    -- код, который нужно выполнить
end

-- в фрейме
if imgui.CheckBox(...) then
    name()
end
типо так?
Код:
function main()
    while not isSampAvailable() do wait(50) end
    sampRegisterChatCommand('farm', function name())
    sampRegisterChatCommand('mlb', function() WinState[0] = not WinState[0] end)
    while true do
        if checkboxone[0] then
            sampSendChat("/farm")
            wait(100)
        end
        wait(0)
    end
end
function name()
    if not isSampfuncsLoaded() or not isSampLoaded() then return end
    sampRegisterChatCommand("farm", cmd_bot)
    local saveX = {}
    local saveY = {}
    local saveZ = {}
    while true do
        wait(0)
        if isPlayerPlaying(playerHandle) and enabled then
            BeginToPoint(2624.919922, -2191.280029, 16.980000, 1.000000, -255, false)
            BeginToPoint(2625.129883, -2196.550049, 15.780000, 1.000000, -255, false)
            BeginToPoint(2624.989990, -2204.419922, 13.570000, 1.000000, -255, false)
            BeginToPoint(2618.399902, -2205.149902, 13.570000, 1.000000, -255, false)
            BeginToPoint(2602.659912, -2198.709961, 13.570000, 1.000000, -255, false)
            BeginToPoint(2598.290039, -2196.709961, 13.570000, 1.000000, -255, false)
            wait(10000)
            local posX, posY, posZ = GetCoordinates()
            local mfind, mposX, mposY, mposZ = SearchMarker(posX, posY, posZ, 50.000000, false)
            if mfind then BeginToPoint(mposX, mposY, mposZ, 1.000000, -255, false) end
            BeginToPoint(2595.590088, -2195.459961, 13.570000, 1.000000, -255, false)
            BeginToPoint(2617.689941, -2203.689941, 13.570000, 1.000000, -255, false)
            BeginToPoint(2624.570068, -2202.550049, 13.570000, 1.000000, -255, false)
            BeginToPoint(2624.870117, -2191.820068, 16.980000, 1.000000, -255, false)
        end
    end
end


function BeginToPoint(x, y, z, radius, move_code, isSprint)
    repeat
        local posX, posY, posZ = GetCoordinates()
        SetAngle(x, y, z)
        MovePlayer(move_code, isSprint)
        local dist = getDistanceBetweenCoords3d(x, y, z, posX, posY, z)
        wait(0)
    until not enabled or dist < radius
end
function MovePlayer(move_code, isSprint)
    setGameKeyState(1, move_code)
    if isSprint then setGameKeyState(16, 255) end
end
function SetAngle(x, y, z)
    local posX, posY, posZ = GetCoordinates()
    local pX = x - posX
    local pY = y - posY
    local zAngle = getHeadingFromVector2d(pX, pY)
    if isCharInAnyCar(playerPed) then
        local car = storeCarCharIsInNoSave(playerPed)
        setCarHeading(car, zAngle)
    else
        setCharHeading(playerPed, zAngle)
    end
    restoreCameraJumpcut()
end
function GetCoordinates()
    if isCharInAnyCar(playerPed) then
        local car = storeCarCharIsInNoSave(playerPed)
        return getCarCoordinates(car)
    else
        return getCharCoordinates(playerPed)
    end
end
function cmd_bot(param)
    enabled = not enabled
    if enabled then
        sampAddChatMessage(string.format("[%s]: Активирован", thisScript().name), 0x40FF40)
    else
        sampAddChatMessage(string.format("[%s]: Деактивирован", thisScript().name), 0xFF4040)
    end
end
function teleportPlayer(x, y, z)
    if isCharInAnyCar(playerPed) then
        setCharCoordinates(playerPed, x, y, z)
    end
    setCharCoordinatesDontResetAnim(playerPed, x, y, z)
end
function setCharCoordinatesDontResetAnim(char, x, y, z)
    if doesCharExist(char) then
        local ptr = getCharPointer(char)
        setEntityCoordinates(ptr, x, y, z)
    end
end
function setEntityCoordinates(entityPtr, x, y, z)
    if entityPtr ~= 0 then
        local matrixPtr = readMemory(entityPtr + 0x14, 4, false)
        if matrixPtr ~= 0 then
            local posPtr = matrixPtr + 0x30
            writeMemory(posPtr + 0, 4, representFloatAsInt(x), false) --X
            writeMemory(posPtr + 4, 4, representFloatAsInt(y), false) --Y
            writeMemory(posPtr + 8, 4, representFloatAsInt(z), false) --Z
        end
    end
end
function SearchMarker(posX, posY, posZ, radius, isRace)
    local ret_posX = 0.0
    local ret_posY = 0.0
    local ret_posZ = 0.0
    local isFind = false
    for id = 0, 31 do
        local MarkerStruct = 0
        if isRace then MarkerStruct = 0xC7F168 + id * 56
        else MarkerStruct = 0xC7DD88 + id * 160 end
        local MarkerPosX = representIntAsFloat(readMemory(MarkerStruct + 0, 4, false))
        local MarkerPosY = representIntAsFloat(readMemory(MarkerStruct + 4, 4, false))
        local MarkerPosZ = representIntAsFloat(readMemory(MarkerStruct + 8, 4, false))
        if MarkerPosX ~= 0.0 or MarkerPosY ~= 0.0 or MarkerPosZ ~= 0.0 then
            if getDistanceBetweenCoords3d(MarkerPosX, MarkerPosY, MarkerPosZ, posX, posY, posZ) < radius then
                ret_posX = MarkerPosX
                ret_posY = MarkerPosY
                ret_posZ = MarkerPosZ
                isFind = true
                radius = getDistanceBetweenCoords3d(MarkerPosX, MarkerPosY, MarkerPosZ, posX, posY, posZ)
            end
        end
    end
    return isFind, ret_posX, ret_posY, ret_posZ
end