таймер с (wait)

lisauro

Новичок
Автор темы
11
0
Версия MoonLoader
.026-beta
Я пытаюсь добавить подождать поток вне основной функции, но сценарий не работает. пожалуйста помоги.
не знаю как правильно добавить lua_thread
Код:
local q = require 'lib.samp.events'

function main()
    if not isSampLoaded() and isSampAvailable() then return end
    while not isSampAvailable() do wait(0) end
    sampAddChatMessage("{F8F9F9}(Activation command is /cartimer)")
    sampRegisterChatCommand("cartimer", cmd)
    wait(-1)
end

function cmd()
    Activate = not Activate
    sampAddChatMessage(string.format("{F8F9F9}Sell car timer is %s", Activate))
end

function q.onServerMessage(c, s)
    lua_thread.create(function()  <--- 
        if string.find("your reload time is 12 minutes") and Activate == true then
        wait(720000)
        printStringNow('you can sell car again', 5000)
    end)
end
 
Решение
Lua:
local q = require 'lib.samp.events'

local activate = false

function main()
  if not isSampLoaded() and isSampAvailable() then return end
  while not isSampAvailable() do wait(0) end
  sampAddChatMessage("{F8F9F9}(Activation command is /cartimer)", -1)
  sampRegisterChatCommand("cartimer", function()
        activate = not activate
      sampAddChatMessage(string.format("{F8F9F9}Sell car timer is %s", activate), -1)
    end)
  while true do
    wait(0)
  end
end

function q.onServerMessage(c, s)
    if activate then
      lua_thread.create(function()
        if s:find("your reload time is 12 minutes") and activate then
            wait(720000)
            printStringNow('you can sell car again', 5000)
          end
        end)...

Albertio

Attention! Thanks for your attention.
877
703
Lua:
local q = require 'lib.samp.events'

local activate = false

function main()
  if not isSampLoaded() and isSampAvailable() then return end
  while not isSampAvailable() do wait(0) end
  sampAddChatMessage("{F8F9F9}(Activation command is /cartimer)", -1)
  sampRegisterChatCommand("cartimer", function()
        activate = not activate
      sampAddChatMessage(string.format("{F8F9F9}Sell car timer is %s", activate), -1)
    end)
  while true do
    wait(0)
  end
end

function q.onServerMessage(c, s)
    if activate then
      lua_thread.create(function()
        if s:find("your reload time is 12 minutes") and activate then
            wait(720000)
            printStringNow('you can sell car again', 5000)
          end
        end)
    end
end
 

Kolbasa241

Известный
213
57
Lua:
local q = require 'lib.samp.events'

local time_for_timer = os.clock()
local Activate = false
local time = 720
local server_Message = false

function main()
    if not isSampLoaded() and isSampAvailable() then return end
    while not isSampAvailable() do wait(0) end
    sampAddChatMessage("{F8F9F9}(Activation command is /cartimer)", -1)
    sampRegisterChatCommand("cartimer", cmd)
    sampRegisterChatCommand("ctinfo", cmd_car_timer_info)
    while true do
        wait(-1)
    end
end

function cmd()
    Activate = not Activate
    if Activate then
        Activate_Text = "Work"
    else
        server_Message = false
        Activate_Text = "Not Work"
    end
    sampAddChatMessage(string.format("{F8F9F9}Sell car timer is %s", Activate_Text), -1)
    Timer()
end

function cmd_car_timer_info()
    if Activate then
        sampAddChatMessage("[Sell Car Timer] the rest of time - "..time_for_timer - os.clock().." s", -1)
    else
        sampAddChatMessage("[Sell Car Timer] Not Work", -1)
    end
end

function Timer()
    lua_thread.create(function()
        while Activate do
            wait(0)
            if server_Message and os.clock() >= time_for_timer then
                sampAddChatMessage('you can sell car again', -1)
                Activate = false
                server_Message = false
            end
        end
    end)
end

function q.onServerMessage(c, s)
    if Activate and s:find("your reload time is 12 minutes") then
        time_for_timer = os.clock() + time
        server_Message = true
    end
end
я думаю у меня будет вариант по функциональней
 
  • Нравится
Реакции: lisauro

Fott

Простреленный
3,446
2,307
Lua:
local q = require 'lib.samp.events'

local time_for_timer = os.clock()
local Activate = false
local time = 720
local server_Message = false

function main()
    if not isSampLoaded() and isSampAvailable() then return end
    while not isSampAvailable() do wait(0) end
    sampAddChatMessage("{F8F9F9}(Activation command is /cartimer)", -1)
    sampRegisterChatCommand("cartimer", cmd)
    sampRegisterChatCommand("ctinfo", cmd_car_timer_info)
    while true do
        wait(-1)
    end
end

function cmd()
    Activate = not Activate
    if Activate then
        Activate_Text = "Work"
    else
        server_Message = false
        Activate_Text = "Not Work"
    end
    sampAddChatMessage(string.format("{F8F9F9}Sell car timer is %s", Activate_Text), -1)
    Timer()
end

function cmd_car_timer_info()
    if Activate then
        sampAddChatMessage("[Sell Car Timer] the rest of time - "..time_for_timer - os.clock().." s", -1)
    else
        sampAddChatMessage("[Sell Car Timer] Not Work", -1)
    end
end

function Timer()
    lua_thread.create(function()
        while Activate do
            wait(0)
            if server_Message and os.clock() >= time_for_timer then
                sampAddChatMessage('you can sell car again', -1)
                Activate = false
                server_Message = false
            end
        end
    end)
end

function q.onServerMessage(c, s)
    if Activate and s:find("your reload time is 12 minutes") then
        time_for_timer = os.clock() + time
        server_Message = true
    end
end
я думаю у меня будет вариант по функциональней
Нахуя, а главное зачем все усложнять?
 
  • Ха-ха
  • Нравится
Реакции: kizn и Albertio

Kolbasa241

Известный
213
57
Нахуя, а главное зачем все усложнять?
Я конечно не эксперт, но если в евенте юзать задержку (wait) он будет ловить следующие сообщения от серва?

Да и я ему помог сделать скрипт лучше, может даже накинул ему идею, не захочет - не будет использовать.. Лишним думаю не будет
 

Fott

Простреленный
3,446
2,307
Я конечно не эксперт, но если в евенте юзать задержку (wait) он будет ловить следующие сообщения от серва?

Да и я ему помог сделать скрипт лучше, может даже накинул ему идею, не захочет - не будет использовать.. Лишним думаю не будет
Конечно будет ловить, чем ему задержка мешает? А скрипт ты вряд-ли лучше сделал, ты простоту превратил простейшую функцию в полный пиздец