Оптимизируйте плис скрипт lua и помогите с заголовком

askfmaskfaosflas

Потрачен
Автор темы
1,089
511
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Версия SA-MP
  1. Любая
  2. Другая
Пожалуйста оптимизируйте скрипт. И решите проблему с тем, что заголовок окна "Debug".

Скрипт:
require "lib.moonloader"

require "lib.moonloader"

local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local main_window_state = imgui.ImBool(false) 
local text_buffer = imgui.ImBuffer(256)

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    sampAddChatMessage("iBinder loaded", 0xFFFF0000)
    sampRegisterChatCommand("ibinder", cmd_ibinder)
    imgui.Process = false

    -- блок выполняется 1 раз после старта сампа
    while true do
        wait(0)
        -- блок выполняется бесконечно (пока самп активен)

    end
end

function cmd_ibinder(arg)
    main_window_state.v = not main_window_state.v 
    imgui.Process = main_window_state.v
 end

function imgui.OnDrawFrame()
    imgui.BeginChild("iBinder", imgui.ImVec2(140, 200), true)
    if imgui.Button(u8"Основное", imgui.ImVec2(-1, 25)) then menu = 1 end
    if imgui.Button(u8"Настройки", imgui.ImVec2(-1, 25)) then menu = 2 end
    if imgui.Button(u8"О скрипте", imgui.ImVec2(-1, 25)) then menu = 3 end
    imgui.EndChild()
    imgui.SameLine()
    if menu == 1 then
        imgui.BeginChild("child2", imgui.ImVec2(270, 100), true)
        imgui.Text("1")
        imgui.EndChild()
    end
    imgui.SameLine()
    if menu == 2 then
        imgui.BeginChild("child2", imgui.ImVec2(270, 100), true)
        imgui.Text("2")
        imgui.EndChild()
    end
    imgui.SameLine()
    if menu == 3 then
        imgui.BeginChild("child2", imgui.ImVec2(270, 100), true)
        imgui.Text("3")
        imgui.EndChild()
    end
end
 
Последнее редактирование:
Решение
Пожалуйста оптимизируйте скрипт. И решите проблему с тем, что заголовок окна "Debug".

Скрипт:
require "lib.moonloader"

require "lib.moonloader"

local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local main_window_state = imgui.ImBool(false)
local text_buffer = imgui.ImBuffer(256)

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    sampAddChatMessage("iBinder loaded", 0xFFFF0000)
    sampRegisterChatCommand("ibinder", cmd_ibinder)
    imgui.Process = false

    -- блок выполняется 1 раз после старта сампа
    while true do
        wait(0)
        -- блок выполняется бесконечно (пока...

barjik

Известный
464
190
Lua:
require "lib.moonloader"
local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

local window = imgui.ImBool(false)

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    sampAddChatMessage("iBinder loaded", 0xFFFF0000)
    sampRegisterChatCommand("ibinder", function() window.v = not window.v imgui.Process = window.v end)
    while true do wait(0)
    if window.v == false then
    imgui.Process = false end
    end
end

function imgui.OnDrawFrame()
    local ex, ey = getScreenResolution()
    imgui.SetNextWindowSize(imgui.ImVec2(450, 350), imgui.Cond.FirstUseEver)
    imgui.SetNextWindowPos(imgui.ImVec2(ex / 2, ey / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
    imgui.Begin("Test Window", window)
    imgui.BeginChild("iBinder", imgui.ImVec2(130, 300), true)
    if imgui.Button(u8"Основное", imgui.ImVec2(-1, 25)) then menu = 1 end
    if imgui.Button(u8"Настройки", imgui.ImVec2(-1, 25)) then menu = 2 end
    if imgui.Button(u8"О скрипте", imgui.ImVec2(-1, 25)) then menu = 3 end
    imgui.EndChild() imgui.SameLine()
    if menu == 1 then
        imgui.BeginChild("child1", imgui.ImVec2(200, 100), true)
        imgui.Text("1")
        imgui.EndChild()
    end
    imgui.SameLine()
    if menu == 2 then
        imgui.BeginChild("child2", imgui.ImVec2(200, 100), true)
        imgui.Text("2")
        imgui.EndChild()
    end
    imgui.SameLine()
    if menu == 3 then
        imgui.BeginChild("child3", imgui.ImVec2(200, 100), true)
        imgui.Text("3")
        imgui.EndChild()
    end
    imgui.End()
end
 
  • Нравится
Реакции: askfmaskfaosflas

SomaGnoma

Известный
442
152
Пожалуйста оптимизируйте скрипт. И решите проблему с тем, что заголовок окна "Debug".

Скрипт:
require "lib.moonloader"

require "lib.moonloader"

local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local main_window_state = imgui.ImBool(false)
local text_buffer = imgui.ImBuffer(256)

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    sampAddChatMessage("iBinder loaded", 0xFFFF0000)
    sampRegisterChatCommand("ibinder", cmd_ibinder)
    imgui.Process = false

    -- блок выполняется 1 раз после старта сампа
    while true do
        wait(0)
        -- блок выполняется бесконечно (пока самп активен)

    end
end

function cmd_ibinder(arg)
    main_window_state.v = not main_window_state.v
    imgui.Process = main_window_state.v
 end

function imgui.OnDrawFrame()
    imgui.BeginChild("iBinder", imgui.ImVec2(140, 200), true)
    if imgui.Button(u8"Основное", imgui.ImVec2(-1, 25)) then menu = 1 end
    if imgui.Button(u8"Настройки", imgui.ImVec2(-1, 25)) then menu = 2 end
    if imgui.Button(u8"О скрипте", imgui.ImVec2(-1, 25)) then menu = 3 end
    imgui.EndChild()
    imgui.SameLine()
    if menu == 1 then
        imgui.BeginChild("child2", imgui.ImVec2(270, 100), true)
        imgui.Text("1")
        imgui.EndChild()
    end
    imgui.SameLine()
    if menu == 2 then
        imgui.BeginChild("child2", imgui.ImVec2(270, 100), true)
        imgui.Text("2")
        imgui.EndChild()
    end
    imgui.SameLine()
    if menu == 3 then
        imgui.BeginChild("child2", imgui.ImVec2(270, 100), true)
        imgui.Text("3")
        imgui.EndChild()
    end
end
у тебя имгуи начинается с чайдла.
Lua:
imgui.Begin(u8"о мой кун", main_window_state) -- называешь окно и присваиваешь его к переменной.
-- твоя дичь
imgui.End()
 
  • Нравится
Реакции: askfmaskfaosflas

THERION

Известный
Проверенный
88
324
оптимизируйте скрипт
Lua:
script_name("iBinder")
local CMD = string.lower(thisScript().name) -- acitvation command

local imgui = require("imgui")
local encoding = require("encoding")
encoding.default = "CP1251"
local u8 = encoding.UTF8

local window = imgui.ImBool(false) -- window state
local menu = 0 -- selected menu section

function main()
   repeat wait(0) until isSampAvailable()
   do
      sampAddChatMessage(thisScript().name .. " loaded", 0xFFFF0000)
      sampRegisterChatCommand(CMD,
      function()
         window.v = not window.v
         imgui.Process = window.v
      end)

      imgui.Process = window.v
   end
end

function imgui.OnDrawFrame()
   do
      local resx, resy = getScreenResolution()
      imgui.SetNextWindowSize(imgui.ImVec2(450, 350), imgui.Cond.FirstUseEver)
      imgui.SetNextWindowPos(imgui.ImVec2(resx / 2, resy / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
   end
   imgui.Begin("Test Window", window)
   do
      imgui.BeginChild(thisScript().name, imgui.ImVec2(130, 300), true)
         for i, name in ipairs({u8("Основное"), u8("Настройки"), u8("О скрипте")}) do
            if imgui.Button(name, imgui.ImVec2(-1, 25)) then
               menu = i
            end
         end
      imgui.EndChild()
     
      for i = 1, 3 do
         if i == menu then
            imgui.SameLine()
            imgui.BeginChild("child" .. tostring(i), imgui.ImVec2(200, 100), true)
               imgui.Text(tostring(i))
            imgui.EndChild()
         end
      end
   end
   imgui.End()
end

Lua:
if menu == 1 then
    imgui.BeginChild("child1", imgui.ImVec2(200, 100), true)
    imgui.Text("1")
    imgui.EndChild()
end
imgui.SameLine()
if menu == 2 then
    imgui.BeginChild("child2", imgui.ImVec2(200, 100), true)
    imgui.Text("2")
    imgui.EndChild()
end
imgui.SameLine()
if menu == 3 then
    imgui.BeginChild("child3", imgui.ImVec2(200, 100), true)
    imgui.Text("3")
    imgui.EndChild()
end
циклы:
wsp5WEY.png
 
Последнее редактирование:

SomaGnoma

Известный
442
152
Lua:
script_name("iBinder")
local CMD = string.lower(thisScript().name) -- acitvation command

local imgui = require("imgui")
local encoding = require("encoding")
encoding.default = "CP1251"
local u8 = encoding.UTF8

local window = imgui.ImBool(false) -- window state
local menu = 0 -- selected menu section

function main()
   repeat wait(0) until isSampAvailable()
   do
      sampAddChatMessage(thisScript().name .. " loaded", 0xFFFF0000)
      sampRegisterChatCommand(CMD,
      function()
         window.v = not window.v
         imgui.Process = window.v
      end)

      imgui.Process = window.v
   end
end

function imgui.OnDrawFrame()
   do
      local resx, resy = getScreenResolution()
      imgui.SetNextWindowSize(imgui.ImVec2(450, 350), imgui.Cond.FirstUseEver)
      imgui.SetNextWindowPos(imgui.ImVec2(resx / 2, resy / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
   end
   imgui.Begin("Test Window", window)
   do
      imgui.BeginChild(thisScript().name, imgui.ImVec2(130, 300), true)
         for i, name in ipairs({u8("Основное"), u8("Настройки"), u8("О скрипте")}) do
            if imgui.Button(name, imgui.ImVec2(-1, 25)) then
               menu = i
            end
         end
      imgui.EndChild()
    
      for i = 1, 3 do
         if i == menu then
            imgui.SameLine()
            imgui.BeginChild("child" .. tostring(i), imgui.ImVec2(200, 100), true)
               imgui.Text(tostring(i))
            imgui.EndChild()
         end
      end
   end
   imgui.End()
end


циклы:
wsp5WEY.png
а нафик циклами все усложнять и do ?
 

THERION

Известный
Проверенный
88
324
Как минимум это упрощает навигацию по файлу
GT6TppL.png

Сказать что блоки do усложняют код это что-то на уровне "зачем функции, можно же все писать в main".
Чтобы не повторять одинаковый код
 
Последнее редактирование: