Как сделать задержку в LUA. wait() крашит скрипт.

Dereksovv

Новичок
Автор темы
26
3
Код:
---@diagnostic disable: undefined-global, lowercase-global

local main_color = 0x5A90CE

function main()
while not isSampAvailable() do wait(0) end
while true do
wait(0)

local id = sampGetPlayerIdByCharHandle(playerid)

sampRegisterChatCommand("nrg", nrg500)
sampRegisterChatCommand("accept", accepts)
sampRegisterChatCommand("tpdom", tphouse)

    if isKeyJustPressed(0x31) and not sampIsChatInputActive() and not sampIsDialogActive() then
    sampSendChat("/ot")
    end
    if isKeyJustPressed(0x69) and not sampIsChatInputActive() and not sampIsDialogActive() then
    sampSendChat("/vr [A] Помогу по игре, отвечу на вопросы, прослежу за /try! /vr + [A]")
    end
    if isKeyJustPressed(0x39) and not sampIsChatInputActive() and not sampIsDialogActive() then
    sampSendChat("/b Приятной игры на Arizona Supreme! Администрация поможет, Вам, в любой беде!")
    sampSendChat("/b С любовью Рампага!")
    end
end
end

function nrg500(arg)
    sampSendChat("/plveh ".. arg .. " 522 1")
end

function tphouse(arg)
    var1, var2 = string.match(arg, '(.+) (.+)')
        if var1 == nil or var1 == '' then
        sampAddChatMessage('Используйте /tphouse [id player] [id house]', 0xFFFFFF)
    else
        sampSendChat("/gotohouse ".. var2)
        sampSendChat("/gethere ".. var1)
    end
end


function accepts(arg)
    sampSendChat("/a Аццепт можно получить у бота в вк - @----.")
    sampSendChat("/a Привязываете страницу в игре и в боте, получаете аццепт.")
end

Нужно сделать задержку между выделенных строк, тупо телепортирует к дому и не тепает чела. Кто поможет - пожалуйста, буду благодарен.
 

ARMOR

kjor32 is legend
Модератор
4,852
6,081
Ты регистрируешь команду в бесконечном цикле чел...

Lua:
function main()
    while not isSampAvailable() do wait(0) end
    while not sampIsLocalPlayerSpawned() do wait(0) end

    sampRegisterChatCommand("nrg500", function(arg)
        sampSendChat("/plveh" .. arg .. " 522 1")
    end)
    sampRegisterChatCommand("accept", function()
        lua_thread.create(function()
            sampSendChat("/a Аццепт можно получить у бота в вк - @----.")
            wait(1000)
            sampSendChat("/a Привязываете страницу в игре и в боте, получаете аццепт.")
        end)
    end)
    sampRegisterChatCommand("tpdom", function(arg)
        lua_thread.create(function()
            local var1, var2 = string.match(arg, '(%d+) (%d+)')
            if var1 == nil or var1 == "" or var2 == nil or var2 == "" then
                sampAddChatMessage('Используйте /tphouse [id player] [id house]', 0xFFFFFF)
             else
                  sampSendChat("/gotohouse ".. var2)
                  wait(1500)
                  sampSendChat("/gethere ".. var1)
             end
         end)
    end)
 

    while true do
        wait(0)
        if isKeyJustPressed(0x31) and not sampIsChatInputActive() and not sampIsDialogActive() then
            sampSendChat("/ot")
       end
       if isKeyJustPressed(0x69) and not sampIsChatInputActive() and not sampIsDialogActive() then
           sampSendChat("/vr [A] Помогу по игре, отвечу на вопросы, прослежу за /try! /vr + [A]")
        end
        if isKeyJustPressed(0x39) and not sampIsChatInputActive() and not sampIsDialogActive() then
           sampSendChat("/b Приятной игры на Arizona Supreme! Администрация поможет, Вам, в любой беде!")
           sampSendChat("/b С любовью Рампага!")
        end
    end
end
 
Последнее редактирование:

Dereksovv

Новичок
Автор темы
26
3
Ты регистрируешь команду в бесконечном цикле чел...

Lua:
function main()
    while not isSampAvailable() do wait(0) end
    while not sampIsLocalPlayerSpawned() do wait(0) end

    sampRegisterChatCommand("nrg500", function(arg)
        sampSendChat("/plveh" .. arg .. " 522 1")
    end)
    sampRegisterChatCommand("accept", function()
        lua_thread.create(function()
            sampSendChat("/a Аццепт можно получить у бота в вк - @----.")
            wait(1000)
            sampSendChat("/a Привязываете страницу в игре и в боте, получаете аццепт.")
        end)
    end)
    sampRegisterChatCommand("tpdom", function(arg)
        lua_thread.create(function()
            local var1, var2 = string.match(arg, '(%d+) (%d+)')
            if var1 == nil or var1 == "" or var2 == nil or var2 == "" then
                sampAddChatMessage('Используйте /tphouse [id player] [id house]', 0xFFFFFF)
             else
                  sampSendChat("/gotohouse ".. var2)
                  wait(1500)
                  sampSendChat("/gethere ".. var1)
             end
         end)
    end)
 

    while true do
        wait(0)
    end
end
Я в луа 0, это же не Pawn, где всё легко. Спасибо.

Ты регистрируешь команду в бесконечном цикле чел...

Lua:
function main()
    while not isSampAvailable() do wait(0) end
    while not sampIsLocalPlayerSpawned() do wait(0) end

    sampRegisterChatCommand("nrg500", function(arg)
        sampSendChat("/plveh" .. arg .. " 522 1")
    end)
    sampRegisterChatCommand("accept", function()
        lua_thread.create(function()
            sampSendChat("/a Аццепт можно получить у бота в вк - @----.")
            wait(1000)
            sampSendChat("/a Привязываете страницу в игре и в боте, получаете аццепт.")
        end)
    end)
    sampRegisterChatCommand("tpdom", function(arg)
        lua_thread.create(function()
            local var1, var2 = string.match(arg, '(%d+) (%d+)')
            if var1 == nil or var1 == "" or var2 == nil or var2 == "" then
                sampAddChatMessage('Используйте /tphouse [id player] [id house]', 0xFFFFFF)
             else
                  sampSendChat("/gotohouse ".. var2)
                  wait(1500)
                  sampSendChat("/gethere ".. var1)
             end
         end)
    end)
 

    while true do
        wait(0)
    end
end
Вообще всё не фурычит, жму 1 - должно писать /ot, но не пишет. Код твой не изменял.
 
Последнее редактирование:
  • Нравится
Реакции: ARMOR

ARMOR

kjor32 is legend
Модератор
4,852
6,081
  • Нравится
Реакции: Dereksovv