Секундомер с миллисекундами

Dewize

Потрачен
Автор темы
442
88
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Версия MoonLoader
.027.0-preview
Крч когда появляется окно диалоговое, запускается таймер с миллисекундами. Как сделать так, чтоб когда окно закрывало пропадал таймер и сброс был до 0?



Код:
local vk = require 'vkeys'
local sampev = require('samp.events')
local timertime, reservetime, enabled, paused = 0, 0, false, false

function main()
    if not isSampLoaded() then return end
    while not isSampAvailable() do wait(100) end
    while true do
        wait(0)
    end   
end



function sampev.onShowDialog(dialogId, dialogStyle, dialogTitle, okButtonText, cancelButtonText, dialogText)

    if dialogId == 722 then
        if enabled then
            if paused then
                timertime = os.clock() - reservetime + timertime
                reservetime = 0
            else
                reservetime = os.clock()
            end
            paused = not paused
        else   
            timertime = os.clock()
            enabled = true
        end
        if enabled and not paused then   
            printStringNow(string.format("%02i:%06.3f", math.floor((os.clock() - timertime) / 60), os.clock() - timertime - math.floor((os.clock() - timertime) / 60) * 60), 5000)
        end   
    end
end
 

7 СМЕРТНЫХ ГРЕХОВ

пісюнковий злочинець
527
165
Крч когда появляется окно диалоговое, запускается таймер с миллисекундами. Как сделать так, чтоб когда окно закрывало пропадал таймер и сброс был до 0?



Код:
local vk = require 'vkeys'
local sampev = require('samp.events')
local timertime, reservetime, enabled, paused = 0, 0, false, false

function main()
    if not isSampLoaded() then return end
    while not isSampAvailable() do wait(100) end
    while true do
        wait(0)
    end
end



function sampev.onShowDialog(dialogId, dialogStyle, dialogTitle, okButtonText, cancelButtonText, dialogText)

    if dialogId == 722 then
        if enabled then
            if paused then
                timertime = os.clock() - reservetime + timertime
                reservetime = 0
            else
                reservetime = os.clock()
            end
            paused = not paused
        else
            timertime = os.clock()
            enabled = true
        end
        if enabled and not paused then
            printStringNow(string.format("%02i:%06.3f", math.floor((os.clock() - timertime) / 60), os.clock() - timertime - math.floor((os.clock() - timertime) / 60) * 60), 5000)
        end
    end
end
Попробуй мб так:
LUA:
function sampev.onShowDialog(dialogId, dialogStyle, dialogTitle, okButtonText, cancelButtonText, dialogText)

    if dialogId == 722 then
        if enabled then
            if paused then
                timertime = os.clock() - reservetime + timertime
                reservetime = 0
            else
                reservetime = os.clock()
            end
            paused = not paused
        else 
            timertime = os.clock()
            enabled = true
        end
        if enabled and not paused then 
            printStringNow(string.format("%02i:%06.3f", math.floor((os.clock() - timertime) / 60), os.clock() - timertime - math.floor((os.clock() - timertime) / 60) * 60), 5000)
        end
    end
   enabled = false
   timertime = 0
   reservetime = 0
end
 

Dewize

Потрачен
Автор темы
442
88
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Попробуй мб так:
LUA:
function sampev.onShowDialog(dialogId, dialogStyle, dialogTitle, okButtonText, cancelButtonText, dialogText)

    if dialogId == 722 then
        if enabled then
            if paused then
                timertime = os.clock() - reservetime + timertime
                reservetime = 0
            else
                reservetime = os.clock()
            end
            paused = not paused
        else
            timertime = os.clock()
            enabled = true
        end
        if enabled and not paused then
            printStringNow(string.format("%02i:%06.3f", math.floor((os.clock() - timertime) / 60), os.clock() - timertime - math.floor((os.clock() - timertime) / 60) * 60), 5000)
        end
    end
   enabled = false
   timertime = 0
   reservetime = 0
end
не робит
 

Dewize

Потрачен
Автор темы
442
88
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.

7 СМЕРТНЫХ ГРЕХОВ

пісюнковий злочинець
527
165
С телефона писал.
Ну тебе надо твои значение
timertime и reservetime что бы сбрасывались до дефолт значений типо = 0

Мб попробуй типо если диалог не == ид
То
enabled = false
timertime = 0
reservetime = 0
 

Lance_Sterling

Известный
995
355
Да я шарю. Мне надо, чтоб когда диалоговое окно пропадало, то таймер сбрасывался, останавливался и пропадал. Выше код
Напиши елс и шоб переменная равнялась nil

Lua:
local vk = require 'vkeys'
local sampev = require('samp.events')
local timertime, reservetime, enabled, paused = 0, 0, false, false

function main()
    if not isSampLoaded() then return end
    while not isSampAvailable() do wait(100) end
    while true do
        wait(0)
    end   
end



function sampev.onShowDialog(dialogId, dialogStyle, dialogTitle, okButtonText, cancelButtonText, dialogText)

    if dialogId == 722 then
        if enabled then
            if paused then
                timertime = os.clock() - reservetime + timertime
                reservetime = 0
            else
                reservetime = os.clock()
            end
            paused = not paused
        else   
            timertime = os.clock()
            enabled = true
        end
        if enabled and not paused then   
            printStringNow(string.format("%02i:%06.3f", math.floor((os.clock() - timertime) / 60), os.clock() - timertime - math.floor((os.clock() - timertime) / 60) * 60), 5000)
        end
    else
       timertime = nil
    end
end
 

Dewize

Потрачен
Автор темы
442
88
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Напиши елс и шоб переменная равнялась nil

Lua:
local vk = require 'vkeys'
local sampev = require('samp.events')
local timertime, reservetime, enabled, paused = 0, 0, false, false

function main()
    if not isSampLoaded() then return end
    while not isSampAvailable() do wait(100) end
    while true do
        wait(0)
    end  
end



function sampev.onShowDialog(dialogId, dialogStyle, dialogTitle, okButtonText, cancelButtonText, dialogText)

    if dialogId == 722 then
        if enabled then
            if paused then
                timertime = os.clock() - reservetime + timertime
                reservetime = 0
            else
                reservetime = os.clock()
            end
            paused = not paused
        else  
            timertime = os.clock()
            enabled = true
        end
        if enabled and not paused then  
            printStringNow(string.format("%02i:%06.3f", math.floor((os.clock() - timertime) / 60), os.clock() - timertime - math.floor((os.clock() - timertime) / 60) * 60), 5000)
        end
    else
       timertime = nil
    end
end
не-а
 

Lance_Sterling

Известный
995
355
Lua:
local vk = require 'vkeys'
local timertime, reservetime, enabled, paused = 0, 0, false, false

function main()
    if not isSampLoaded() then return end
    while not isSampAvailable() do wait(100) end
    while true do
    wait(0)
        if isKeyJustPressed(vk.VK_F2) then
            if enabled then
                if paused then
                    timertime = os.clock() - reservetime + timertime
                    reservetime = 0
                else
                    reservetime = os.clock()
                end
                paused = not paused
            else
                enabled = true
                timertime = os.clock()
            end
        end
        if isKeyJustPressed(vk.VK_F3) then
            timertime, reservetime, enabled, paused = 0, 0, false, false
        end
        if enabled and not paused then
            printStringNow(string.format("%02i:%06.3f", math.floor((os.clock() - timertime) / 60), os.clock() - timertime - math.floor((os.clock() - timertime) / 60) * 60), 5000)
        end
    end
end

Попробуй
Lua:
local vk = require 'vkeys'
local sampev = require('samp.events')
local timertime, reservetime, enabled, paused = 0, 0, false, false

function main()
    if not isSampLoaded() then return end
    while not isSampAvailable() do wait(100) end
    while true do
        wait(0)
        
if enabled and not paused then  
            printStringNow(string.format("%02i:%06.3f", math.floor((os.clock() - timertime) / 60), os.clock() - timertime - math.floor((os.clock() - timertime) / 60) * 60), 5000)
        end
    end  
end



function sampev.onShowDialog(dialogId, dialogStyle, dialogTitle, okButtonText, cancelButtonText, dialogText)

    if dialogId == 722 then
        if enabled then
            if paused then
                timertime = os.clock() - reservetime + timertime
                reservetime = 0
            else
                reservetime = os.clock()
            end
            paused = not paused
        else  
            timertime = os.clock()
            enabled = true
        end
    else
       timertime, reservetime, enabled, paused = 0, 0, false, false
    end
end
 

sdfy

Известный
346
228
onSendDialogResponse для вас шутка или че

Что ты вообще из этого кода хочешь ? Чтобы выводило сколько был активен диалог ?

Как так ? Нечитабельный говнокодерский вариант ?
Lua:
function DialogTime()
    while true do wait(1)
        if sampIsDialogActive() then
            local ttime = os.clock()
            while sampIsDialogActive() do wait(0) end
            sampAddChatMessage(string.format("Диалог %s был активен %s сек", sampGetDialogCaption():gsub("%{......%}", ""), string.sub(os.clock() - ttime, 1, 5)), 16777215)
        end
    end
end

-- в main
lua_thread.create(DialogTime)
 
Последнее редактирование: