Задержка вне main()

Ergalla

Новичок
Автор темы
6
2
Версия MoonLoader
.026-beta
Lua:
require "lib.moonloader"
local hook = require 'lib.samp.events'

grogger = false


function main()
    repeat wait(0) until isSampAvailable()
    sampAddChatMessage("Work", 0xc0c24e)
    sampRegisterChatCommand("click",
    function()
        grogger = not grogger
        if grogger then sampAddChatMessage("1", 0xc0c24e)
        else sampAddChatMessage("0", 0xc0c24e) end
    end)
    wait(-1)
end

function hook.onShowTextDraw(textdrawId, data)
    if grogger then
        if sampTextdrawGetString(2077):find("N") then
            wait(1000)
            sendKey(128)
        elseif sampTextdrawGetString(2077):find("Y") then
            wait(1000)
            sendKey(64)
        end
    end
end


function sendKey(key)
    local _, myId = sampGetPlayerIdByCharHandle(PLAYER_PED)
    local data = allocateMemory(68)
    sampStorePlayerOnfootData(myId, data)
    setStructElement(data, 36, 1, key, false)
    sampSendOnfootData(data)
    freeMemory(data)
end
Короче, как в function hook.onShowTextDraw сделать задержку, знаю что нужно использовать потоки, но как организовать - незнаю!
 
Решение
Lua:
require "lib.moonloader"
local hook = require 'lib.samp.events'

grogger = false


function main()
    repeat wait(0) until isSampAvailable()
    sampAddChatMessage("Work", 0xc0c24e)
    sampRegisterChatCommand("click",
    function()
        grogger = not grogger
        if grogger then sampAddChatMessage("1", 0xc0c24e)
        else sampAddChatMessage("0", 0xc0c24e) end
    end)
    wait(-1)
end

function hook.onShowTextDraw(textdrawId, data)
    if grogger then
        if sampTextdrawGetString(2077):find("N") then
            wait(1000)
            sendKey(128)
        elseif sampTextdrawGetString(2077):find("Y") then
            wait(1000)
            sendKey(64)
        end
    end
end


function sendKey(key)
    local _...

Rice.

Известный
Модератор
1,753
1,654
Lua:
require "lib.moonloader"
local hook = require 'lib.samp.events'

grogger = false


function main()
    repeat wait(0) until isSampAvailable()
    sampAddChatMessage("Work", 0xc0c24e)
    sampRegisterChatCommand("click",
    function()
        grogger = not grogger
        if grogger then sampAddChatMessage("1", 0xc0c24e)
        else sampAddChatMessage("0", 0xc0c24e) end
    end)
    wait(-1)
end

function hook.onShowTextDraw(textdrawId, data)
    if grogger then
        if sampTextdrawGetString(2077):find("N") then
            wait(1000)
            sendKey(128)
        elseif sampTextdrawGetString(2077):find("Y") then
            wait(1000)
            sendKey(64)
        end
    end
end


function sendKey(key)
    local _, myId = sampGetPlayerIdByCharHandle(PLAYER_PED)
    local data = allocateMemory(68)
    sampStorePlayerOnfootData(myId, data)
    setStructElement(data, 36, 1, key, false)
    sampSendOnfootData(data)
    freeMemory(data)
end
Короче, как в function hook.onShowTextDraw сделать задержку, знаю что нужно использовать потоки, но как организовать - незнаю!
Lua:
lua_thread.create(function()
--code
end)

--[[primer
lua_thread.create(function()
    print('1')
    wait(2000)
    print('2')
end)
]]
 
  • Нравится
Реакции: Ergalla

qdIbp

Автор темы
Проверенный
1,450
1,190
Lua:
require "lib.moonloader"
local hook = require 'lib.samp.events'

grogger = false


function main()
    repeat wait(0) until isSampAvailable()
    sampAddChatMessage("Work", 0xc0c24e)
    sampRegisterChatCommand("click",
    function()
        grogger = not grogger
        if grogger then sampAddChatMessage("1", 0xc0c24e)
        else sampAddChatMessage("0", 0xc0c24e) end
    end)
    wait(-1)
end

function hook.onShowTextDraw(textdrawId, data)
    lua_thread.create(function()
        if grogger then
            if sampTextdrawGetString(2077):find("N") then
                wait(1000)
                sendKey(128)
            elseif sampTextdrawGetString(2077):find("Y") then
                wait(1000)
                sendKey(64)
            end
        end
    end)
end


function sendKey(key)
    local _, myId = sampGetPlayerIdByCharHandle(PLAYER_PED)
    local data = allocateMemory(68)
    sampStorePlayerOnfootData(myId, data)
    setStructElement(data, 36, 1, key, false)
    sampSendOnfootData(data)
    freeMemory(data)
end
 
  • Нравится
Реакции: Ergalla