не могу объединить 2 функции lua скрипт

Статус
В этой теме нельзя размещать новые ответы.

sadasdasdasdasdasd

Участник
Автор темы
81
16
Версия MoonLoader
Другое
хочу написать свой первый скрипт, но сразу столкнулся с проблемой, при нажатии на чекбокс, функция не работает, что делать? я где то ошибся? помогите пожалуйста. функция, это исходник скрипта server time by kalashnikov
код:

Lua:
script_name('ShishaHub')
script_author('Shisha')


require "lib.moonloader"
local keys = require ('vkeys')
local imgui = require('imgui')
local encoding = require('encoding')
encoding.default = 'CP1251'
u8 = encoding.UTF8
local huy = require("samp.events")
local piska = 0


local oX = 250
local oY = 430


local main_window_state = imgui.ImBool(false)
local text_buffer_name = imgui.ImBuffer(256)

local stime = imgui.ImBool(false)

bike = {[481] = true, [509] = true, [510] = true}
moto = {[448] = true, [461] = true, [462] = true, [463] = true, [468] = true, [471] = true, [521] = true, [522] = true, [523] = true, [581] = true, [586] = true}


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

    sampRegisterChatCommand("mmenu", cmd_imgui)

    imgui.Process = false

    while true do
        wait(0)
       
        if main_window_state.v == false then
            imgui.Process = false

       
        end
    end
end

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



function imgui.OnDrawFrame()
    imgui.Begin("ShishaHub", main_window_state)
    imgui.Text("Всем ку",text_buffer_name)
    imgui.Checkbox("Sever time by KALASHNIKOV", stime)
    imgui.End()
end

function time()
    if stime.v then
        if not isSampLoaded() or not isSampfuncsLoaded() then return end
        while not isSampAvailable() do wait(100) end
        while true do
            sampTextdrawCreate(221, "Server_time:", oX, oY)
            sampTextdrawSetLetterSizeAndColor(221, 0.3, 1.7, 0xFFe1e1e1)
            sampTextdrawSetOutlineColor(221, 0.5, 0xFF000000)
            sampTextdrawSetAlign(221, 1)
            sampTextdrawSetStyle(221, 2)
            timer = os.time() + piska
            sampTextdrawCreate(222, os.date("%H:%M:%S", timer), oX + 90, oY)
            sampTextdrawSetLetterSizeAndColor(222, 0.3, 1.7, 0xFFff6347)
            sampTextdrawSetOutlineColor(222, 0.5, 0xFF000000)
            sampTextdrawSetAlign(222, 1)
            sampTextdrawSetStyle(222, 2)
            wait(500)
        end
    end
end

function huy.onShowDialog(dialogId,style,title,button1,button2,text)
    if stime.v then
        if string.match(text, "Текущее время") then
            chislo, mesyac, god = string.match(text, "Сегодняшняя дата:     {2EA42E}(%d+):(%d+):(%d+)")
            chas, minuti, sekundi = string.match(text, "Текущее время:     {345690}(%d+):(%d+):(%d+)")
            datetime = {year = god,month = mesyac,day = chislo,hour = chas,min = minuti,sec = sekundi}
            piska = tostring(os.time(datetime)) - os.time()
        end
    end
end
 
Решение
при выключении чек бокса, server time не пропадает
ой забыл, вот

и гайды на мимгуи:)

MLycoris

Режим чтения
Проверенный
1,821
1,860
Как минимум, тебе нужно поместить эту часть в беск цикл или создать поток, а так, если ещё не поздно, начинай своё изучение с мимгуи, а не имгуи
1681057554280.png
 
  • Нравится
Реакции: joumey и YarikVL

joumey

Активный
195
43
Как минимум, тебе нужно поместить эту часть в беск цикл или создать поток, а так, если ещё не поздно, начинай своё изучение с мимгуи, а не имгуи
Посмотреть вложение 197084
Lua:
script_name('ShishaHub')
script_author('Shisha')


require "lib.moonloader"
local keys = require ('vkeys')
local imgui = require('imgui')
local encoding = require('encoding')
encoding.default = 'CP1251'
u8 = encoding.UTF8
local huy = require("samp.events")
local piska = 0


local oX = 250
local oY = 430


local main_window_state = imgui.ImBool(false)
local text_buffer_name = imgui.ImBuffer(256)

local stime = imgui.ImBool(false)

bike = {[481] = true, [509] = true, [510] = true}
moto = {[448] = true, [461] = true, [462] = true, [463] = true, [468] = true, [471] = true, [521] = true, [522] = true, [523] = true, [581] = true, [586] = true}


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

    sampRegisterChatCommand("mmenu", cmd_imgui)

    imgui.Process = false

    while true do
        wait(0)
        if main_window_state.v == false then
            imgui.Process = false
        end
        if stime.v then
            sampTextdrawCreate(221, "Server_time:", oX, oY)
            sampTextdrawSetLetterSizeAndColor(221, 0.3, 1.7, 0xFFe1e1e1)
            sampTextdrawSetOutlineColor(221, 0.5, 0xFF000000)
            sampTextdrawSetAlign(221, 1)
            sampTextdrawSetStyle(221, 2)
            timer = os.time() + piska
            sampTextdrawCreate(222, os.date("%H:%M:%S", timer), oX + 90, oY)
            sampTextdrawSetLetterSizeAndColor(222, 0.3, 1.7, 0xFFff6347)
            sampTextdrawSetOutlineColor(222, 0.5, 0xFF000000)
            sampTextdrawSetAlign(222, 1)
            sampTextdrawSetStyle(222, 2)
            wait(500)
            textDrawIsWorking = true
        else
            if textDrawIsWorking then
                sampTextdrawDelete(221)
                sampTextdrawDelete(222)
                textDrawIsWorking = false
            end
        end
    end
end

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



function imgui.OnDrawFrame()
    imgui.Begin("ShishaHub", main_window_state)
    imgui.Text("Всем ку",text_buffer_name)
    imgui.Checkbox("Sever time by KALASHNIKOV", stime)
    imgui.End()
end

function huy.onShowDialog(dialogId,style,title,button1,button2,text)
    if stime.v then
        if string.match(text, "Текущее время") then
            chislo, mesyac, god = string.match(text, "Сегодняшняя дата:     {2EA42E}(%d+):(%d+):(%d+)")
            chas, minuti, sekundi = string.match(text, "Текущее время:     {345690}(%d+):(%d+):(%d+)")
            datetime = {year = god,month = mesyac,day = chislo,hour = chas,min = minuti,sec = sekundi}
            piska = tostring(os.time(datetime)) - os.time()
        end
    end
end
Вот уже сделанная версия
 

sadasdasdasdasdasd

Участник
Автор темы
81
16
переписал на мимгуи, активация та же - /mmenu
при выключении чек бокса, server time не пропадает

Lua:
script_name('ShishaHub')
script_author('Shisha')


require "lib.moonloader"
local keys = require ('vkeys')
local imgui = require('imgui')
local encoding = require('encoding')
encoding.default = 'CP1251'
u8 = encoding.UTF8
local huy = require("samp.events")
local piska = 0


local oX = 250
local oY = 430


local main_window_state = imgui.ImBool(false)
local text_buffer_name = imgui.ImBuffer(256)

local stime = imgui.ImBool(false)

bike = {[481] = true, [509] = true, [510] = true}
moto = {[448] = true, [461] = true, [462] = true, [463] = true, [468] = true, [471] = true, [521] = true, [522] = true, [523] = true, [581] = true, [586] = true}


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

    sampRegisterChatCommand("mmenu", cmd_imgui)

    imgui.Process = false

    while true do
        wait(0)
        if main_window_state.v == false then
            imgui.Process = false
        end
        if stime.v then
            sampTextdrawCreate(221, "Server_time:", oX, oY)
            sampTextdrawSetLetterSizeAndColor(221, 0.3, 1.7, 0xFFe1e1e1)
            sampTextdrawSetOutlineColor(221, 0.5, 0xFF000000)
            sampTextdrawSetAlign(221, 1)
            sampTextdrawSetStyle(221, 2)
            timer = os.time() + piska
            sampTextdrawCreate(222, os.date("%H:%M:%S", timer), oX + 90, oY)
            sampTextdrawSetLetterSizeAndColor(222, 0.3, 1.7, 0xFFff6347)
            sampTextdrawSetOutlineColor(222, 0.5, 0xFF000000)
            sampTextdrawSetAlign(222, 1)
            sampTextdrawSetStyle(222, 2)
            wait(500)
            textDrawIsWorking = true
        else
            if textDrawIsWorking then
                sampTextdrawDelete(221)
                sampTextdrawDelete(222)
                textDrawIsWorking = false
            end
        end
    end
end

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



function imgui.OnDrawFrame()
    imgui.Begin("ShishaHub", main_window_state)
    imgui.Text("Всем ку",text_buffer_name)
    imgui.Checkbox("Sever time by KALASHNIKOV", stime)
    imgui.End()
end

function huy.onShowDialog(dialogId,style,title,button1,button2,text)
    if stime.v then
        if string.match(text, "Текущее время") then
            chislo, mesyac, god = string.match(text, "Сегодняшняя дата:     {2EA42E}(%d+):(%d+):(%d+)")
            chas, minuti, sekundi = string.match(text, "Текущее время:     {345690}(%d+):(%d+):(%d+)")
            datetime = {year = god,month = mesyac,day = chislo,hour = chas,min = minuti,sec = sekundi}
            piska = tostring(os.time(datetime)) - os.time()
        end
    end
end
Вот уже сделанная версия
всё работает, спасибо.
Так-же прислушаюсь, и буду учить mimgui, спасибо за совет и за помощь
 
  • Нравится
Реакции: joumey и MLycoris

MLycoris

Режим чтения
Проверенный
1,821
1,860
при выключении чек бокса, server time не пропадает
ой забыл, вот

и гайды на мимгуи:)
 

Вложения

  • 1test.lua
    2.3 KB · Просмотры: 2
Статус
В этой теме нельзя размещать новые ответы.