Бесконечное повторение скрипта

Majak1234

Новичок
Автор темы
16
0
Как сделать так, чтобы скрипт при активации выполнялся несколько раз, или же до последующего нажатия кнопки?


Код:
require 'lib.moonloader'
local events = require 'lib.samp.events'

local a = 0

function main()
    while not isSampAvailable() do wait(0) end
    while true do wait(0)
        if isKeyJustPressed(VK_0) and not sampIsCursorActive() then
            if a == 0 then
            sampSendClickTextdraw(2272)
                        sampSendClickTextdraw(2220)
                        sampSendClickTextdraw(57)
                        wait(100)
                        a = 1
                    else
                        sampSendClickTextdraw(49)
                        sampSendClickTextdraw(57)
                        a = 1
                        b = 0
            end
        end
    end
end

function events.onShowTextDraw(id, data)
    lua_thread.create(function()
    if b == 0 then
    if data.text:find('Snakehead') and a == 1 then
        sampSendClickTextdraw(id)
        sampSendClickTextdraw(2219)
        a = 0
        b = 1
            end
        end
    end)
end
 

YarikVL

Известный
Проверенный
4,796
1,813
Как сделать так, чтобы скрипт при активации выполнялся несколько раз, или же до последующего нажатия кнопки?


Код:
require 'lib.moonloader'
local events = require 'lib.samp.events'

local a = 0

function main()
    while not isSampAvailable() do wait(0) end
    while true do wait(0)
        if isKeyJustPressed(VK_0) and not sampIsCursorActive() then
            if a == 0 then
            sampSendClickTextdraw(2272)
                        sampSendClickTextdraw(2220)
                        sampSendClickTextdraw(57)
                        wait(100)
                        a = 1
                    else
                        sampSendClickTextdraw(49)
                        sampSendClickTextdraw(57)
                        a = 1
                        b = 0
            end
        end
    end
end

function events.onShowTextDraw(id, data)
    lua_thread.create(function()
    if b == 0 then
    if data.text:find('Snakehead') and a == 1 then
        sampSendClickTextdraw(id)
        sampSendClickTextdraw(2219)
        a = 0
        b = 1
            end
        end
    end)
end
Посмотри лучше все гайды the champ guess особенно те, где он рассказывает про repeat ( это повторять пока что-то ) и for( это повторять определенное количество раз )
 
  • Нравится
Реакции: Majak1234

chapo

🫡 В армии с 17.10.2023. В ЛС НЕ ОТВЕЧАЮ
Друг
8,776
11,226
Вот пример:
Lua:
require 'lib.moonloader'
local active = false

function main()
    while not isSampAvailable() do wait(0) end
    while true do
        wait(0)
        if wasKeyPressed(VK_H) then
            active = not active
            sampAddChatMessage('Скрипт '..(active and 'включен' or 'выключен'), -1)
        end
        if active then
            print('скрипт включен') -- если скрипт включен то в консоль будет флуд
        end
    end
end
 
  • Нравится
Реакции: Majak1234