Скрипт бездействует

Kviyx

Новичок
Автор темы
16
5
Версия MoonLoader
.026-beta
Здравствуйте. Пытался сделать скрипт для автоматического питания на Аризоне. Суть в том, чтобы скрипт прописывал /satiety, и, когда в тексте окна появлялось "голодны", на сервер должна уходить команда "/cheeps". Проблема в том, что после активации скрипта через команду /aue on ничего не происходит, а также нельзя открыть окно сытости (когда ввожу /satiety ничего не происходит). Пытался убирать различные части скрипта и переносить строки кода выше/ниже, но все было безрезультатно.


Lua:
script_name("AutoEat")

require 'lib.moonloader'
local dialog = require 'lib.samp.events'
local detect = false

function main()

    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    sampAddChatMessage('{FFFFFF}AutoEat{FF0000} activated.', 0xFF0000)
    sampRegisterChatCommand('aue', cmd_eat)

    while true do
        wait(0)

        if detect then sampSendChat('/satiety')
            function dialog.onShowDialog(dialogId, style, title, button1, button2, text)
                if text:find('голодны') then
                    sampSendChat('/cheeps')
                    sampSendDialogResponse(dialogId, 0, 0, "")
                    return false
                end
            end
            wait(3000)
        end
end
end
function cmd_eat(arg)

    if arg == "" then
        sampAddChatMessage('{FFFFFF}On{FF0000} - включить скрипт.', 0xFFFFFF)
        sampAddChatMessage('{FFFFFF}Off{FF0000} - выключить скрипт.', 0xFFFFFF)
    elseif arg == "on" then
        sampAddChatMessage('{FFFFFF}Autoeat{FF0000} включен.', 0xFFFFFF)
        detect = true
    elseif arg == "off" then
        sampAddChatMessage('{FFFFFF}Autoeat{FF0000} выключен.', 0xFFFFFF)
        detect = false
    end
end
 

Kviyx

Новичок
Автор темы
16
5
Что у тебя функция хука диалога забыла в бесконечном цикле?
Немного не понял. Я впервые скрипты пишу, так что не особо разбираюсь. В бесконечный цикл я закинул команды, потому что они должны выполняться пока игра запущена, разве неверно? К тому же, когда я выносил функцию из бесконечного цикла вниз, то при активации скрипта все крашилось
 
Последнее редактирование:
  • Нравится
Реакции: ValeriyArtemenko

sdfy

Известный
349
230
Lua:
script_name("AutoEat")

require 'lib.moonloader'
local sampev = require 'lib.samp.events'
local detect = false

function main()

    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    sampAddChatMessage('{FFFFFF}AutoEat{FF0000} activated.', 0xFF0000)
    sampRegisterChatCommand('aue', cmd_eat)

    while true do
        wait(30000)
        sampSendChat('/satiety')
    end
end

function sampev.onShowDialog(dialogId, style, title, button1, button2, text)
    if text:find('голодны') and detect then
        sampSendChat('/cheeps')
        sampSendDialogResponse(dialogId, 0, 0, "")
        return false
    end
end

function cmd_eat(arg)

    if arg == "" then
        sampAddChatMessage('{FFFFFF}On{FF0000} - включить скрипт.', 0xFFFFFF)
        sampAddChatMessage('{FFFFFF}Off{FF0000} - выключить скрипт.', 0xFFFFFF)
    elseif arg == "on" then
        sampAddChatMessage('{FFFFFF}Autoeat{FF0000} включен.', 0xFFFFFF)
        detect = true
    elseif arg == "off" then
        sampAddChatMessage('{FFFFFF}Autoeat{FF0000} выключен.', 0xFFFFFF)
        detect = false
    end
end

onShowDialog вызывается только при открытии диалога, нет смысла ставить его в бесконечный цикл

Чтобы скрипт не крашнулся при вводе "/aue 1" используй:
Lua:
function cmd_eat(arg)
    if arg == "on" then
        sampAddChatMessage('{FFFFFF}Autoeat{FF0000} включен.', 0xFFFFFF)
        detect = true
    elseif arg == "off" then
        sampAddChatMessage('{FFFFFF}Autoeat{FF0000} выключен.', 0xFFFFFF)
        detect = false
    else
        sampAddChatMessage('{FFFFFF}On{FF0000} - включить скрипт.', 0xFFFFFF)
        sampAddChatMessage('{FFFFFF}Off{FF0000} - выключить скрипт.', 0xFFFFFF)
    end
end

Или если по-хорошему

Lua:
function cmd_eat(arg)
    detect = not detect
    sampAddChatMessage('{FFFFFF}Autoeat{FF0000} '..(detect and 'включен' or 'выключен'), -1)
end
 

Kviyx

Новичок
Автор темы
16
5
Lua:
script_name("AutoEat")

require 'lib.moonloader'
local sampev = require 'lib.samp.events'
local detect = false

function main()

    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    sampAddChatMessage('{FFFFFF}AutoEat{FF0000} activated.', 0xFF0000)
    sampRegisterChatCommand('aue', cmd_eat)

    while true do
        wait(30000)
        sampSendChat('/satiety')
    end
end

function sampev.onShowDialog(dialogId, style, title, button1, button2, text)
    if text:find('голодны') and detect then
        sampSendChat('/cheeps')
        sampSendDialogResponse(dialogId, 0, 0, "")
        return false
    end
end

function cmd_eat(arg)

    if arg == "" then
        sampAddChatMessage('{FFFFFF}On{FF0000} - включить скрипт.', 0xFFFFFF)
        sampAddChatMessage('{FFFFFF}Off{FF0000} - выключить скрипт.', 0xFFFFFF)
    elseif arg == "on" then
        sampAddChatMessage('{FFFFFF}Autoeat{FF0000} включен.', 0xFFFFFF)
        detect = true
    elseif arg == "off" then
        sampAddChatMessage('{FFFFFF}Autoeat{FF0000} выключен.', 0xFFFFFF)
        detect = false
    end
end

onShowDialog вызывается только при открытии диалога, нет смысла ставить его в бесконечный цикл

Чтобы скрипт не крашнулся при вводе "/aue 1" используй:
Lua:
function cmd_eat(arg)
    if arg == "on" then
        sampAddChatMessage('{FFFFFF}Autoeat{FF0000} включен.', 0xFFFFFF)
        detect = true
    elseif arg == "off" then
        sampAddChatMessage('{FFFFFF}Autoeat{FF0000} выключен.', 0xFFFFFF)
        detect = false
    else
        sampAddChatMessage('{FFFFFF}On{FF0000} - включить скрипт.', 0xFFFFFF)
        sampAddChatMessage('{FFFFFF}Off{FF0000} - выключить скрипт.', 0xFFFFFF)
    end
end

Или если по-хорошему

Lua:
function cmd_eat(arg)
    detect = not detect
    sampAddChatMessage('{FFFFFF}Autoeat{FF0000} '..(detect and 'включен' or 'выключен'), -1)
end
Написал все как ты указал, но при активации в чат выводится "AutoEat включен." и все, никакие чипсы персонаж не ест. Скрипт без включения сам вводит /satiety, а если его включить командой /aue - перестает.
Код того, что получилось прикладываю:
Lua:
script_name("AutoEat")

require 'lib.moonloader'
local sampev = require 'lib.samp.events'
local detect = false

function main()

    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    sampAddChatMessage('{FFFFFF}AutoEat{FF0000} activated.', 0xFF0000)
    sampRegisterChatCommand('aue', cmd_eat)

    while true do
        wait(30000)
        sampSendChat('/satiety')
    end
end

function sampev.onShowDialog(dialogId, style, title, button1, button2, text)
    if text:find('голодны') and detect then
        sampSendChat('/cheeps')
        sampSendDialogResponse(dialogId, 0, 0, "")
        return false
    end
end

function cmd_eat(arg)
    detect = not detect
    sampAddChatMessage('{FFFFFF}Autoeat{FF0000} '..(detect and 'включен' or 'выключен'), -1)
end
 
Последнее редактирование:
  • Ха-ха
Реакции: ValeriyArtemenko

why ega

РП игрок
Модератор
2,545
2,236
Здравствуйте. Пытался сделать скрипт для автоматического питания на Аризоне. Суть в том, чтобы скрипт прописывал /satiety, и, когда в тексте окна появлялось "голодны", на сервер должна уходить команда "/cheeps". Проблема в том, что после активации скрипта через команду /aue on ничего не происходит, а также нельзя открыть окно сытости (когда ввожу /satiety ничего не происходит). Пытался убирать различные части скрипта и переносить строки кода выше/ниже, но все было безрезультатно.


Lua:
script_name("AutoEat")

require 'lib.moonloader'
local dialog = require 'lib.samp.events'
local detect = false

function main()

    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    sampAddChatMessage('{FFFFFF}AutoEat{FF0000} activated.', 0xFF0000)
    sampRegisterChatCommand('aue', cmd_eat)

    while true do
        wait(0)

        if detect then sampSendChat('/satiety')
            function dialog.onShowDialog(dialogId, style, title, button1, button2, text)
                if text:find('голодны') then
                    sampSendChat('/cheeps')
                    sampSendDialogResponse(dialogId, 0, 0, "")
                    return false
                end
            end
            wait(3000)
        end
end
end
function cmd_eat(arg)

    if arg == "" then
        sampAddChatMessage('{FFFFFF}On{FF0000} - включить скрипт.', 0xFFFFFF)
        sampAddChatMessage('{FFFFFF}Off{FF0000} - выключить скрипт.', 0xFFFFFF)
    elseif arg == "on" then
        sampAddChatMessage('{FFFFFF}Autoeat{FF0000} включен.', 0xFFFFFF)
        detect = true
    elseif arg == "off" then
        sampAddChatMessage('{FFFFFF}Autoeat{FF0000} выключен.', 0xFFFFFF)
        detect = false
    end
end
тебе текст в чате или диалоге надо искать?
 

Kviyx

Новичок
Автор темы
16
5
Lua:
function sampev.onShowDialog(dialogId, style, title, button1, button2, text)
    if detect then
        for i in text:gmatch("[^\n]+") do
            if i:find('голодны') then
                sampSendChat('/cheeps')
                sampSendDialogResponse(dialogId, 0, nil, nil)
                return false
            end
        end
    end
end
Теперь скрипт открывает диалог после включения, но чипсы не ест.
 

Kviyx

Новичок
Автор темы
16
5

Вложения

  • Screenshot_8.png
    Screenshot_8.png
    200.8 KB · Просмотры: 19
Последнее редактирование:

sdfy

Известный
349
230
попробуй
Lua:
script_name("AutoEat")

require 'lib.moonloader'
local sampev = require 'lib.samp.events'
local detect = true

function main()

    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    sampAddChatMessage('{FFFFFF}AutoEat{FF0000} activated.', 0xFF0000)
    sampRegisterChatCommand('aue', cmd_eat)

    while true do
        wait(30000) -- раз в 30 сек
        if detect then
            sampSendChat('/satiety')
        end
    end
end

function sampev.onShowDialog(dialogId, style, title, button1, button2, text)
    if detect then -- добавь сюда проверку на ид диалога и убери тогда коменты ниже, иначе скрипт будет закрывать все диалоги
        for line in text:gmatch("[^\n]+") do
            if line:find('голодны') then
                sampSendChat('/cheeps')
            end
        end
        --sampSendDialogResponse(dialogId, 1, nil, nil)
        --return false
    end
end

function cmd_eat()
    detect = not detect
    sampAddChatMessage('{FFFFFF}Autoeat{FF0000} '..(detect and 'включен' or 'выключен'), -1)
end
 

Kviyx

Новичок
Автор темы
16
5
попробуй
Lua:
script_name("AutoEat")

require 'lib.moonloader'
local sampev = require 'lib.samp.events'
local detect = true

function main()

    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    sampAddChatMessage('{FFFFFF}AutoEat{FF0000} activated.', 0xFF0000)
    sampRegisterChatCommand('aue', cmd_eat)

    while true do
        wait(30000) -- раз в 30 сек
        if detect then
            sampSendChat('/satiety')
        end
    end
end

function sampev.onShowDialog(dialogId, style, title, button1, button2, text)
    if detect then -- добавь сюда проверку на ид диалога и убери тогда коменты ниже, иначе скрипт будет закрывать все диалоги
        for line in text:gmatch("[^\n]+") do
            if line:find('голодны') then
                sampSendChat('/cheeps')
            end
        end
        --sampSendDialogResponse(dialogId, 1, nil, nil)
        --return false
    end
end

function cmd_eat()
    detect = not detect
    sampAddChatMessage('{FFFFFF}Autoeat{FF0000} '..(detect and 'включен' or 'выключен'), -1)
end
Не работает, к тому же скрипт начал крашить, хотя может это я ошибся с кодом. Вот он:
Lua:
script_name("AutoEat")

require 'lib.moonloader'
local sampev = require 'lib.samp.events'
local detect = true

function main()

    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    sampAddChatMessage('{FFFFFF}AutoEat{FF0000} activated.', 0xFF0000)
    sampRegisterChatCommand('aue', cmd_eat)

    while true do
        wait(30000) -- раз в 30 сек
        if detect then
            sampSendChat('/satiety')
        end
    end
end

function sampev.onShowDialog(dialogId, style, title, button1, button2, text)
    if detect then
            if dialogId:find('0') then -- добавь сюда проверку на ид диалога и убери тогда коменты ниже, иначе скрипт будет закрывать все диалоги
        for line in text:gmatch("[^\n]+") do
            if line:find('голодны') then
                sampSendChat('/cheeps')
            end
        end
            end
        --sampSendDialogResponse(dialogId, 1, nil, nil)
        --return false
    end
end

function cmd_eat()
    detect = not detect
    sampAddChatMessage('{FFFFFF}Autoeat{FF0000} '..(detect and 'включен' or 'выключен'), -1)
end

Вот лог краша:
[ML] (system) AutoEat: Loaded successfully.
[ML] (error) AutoEat: D:\GTA San Andreas\moonloader\autoeat2.lua:25: attempt to index local 'dialogId' (a number value)
stack traceback:
D:\GTA San Andreas\moonloader\autoeat2.lua:25: in function 'callback'
D:\GTA San Andreas\moonloader\lib\samp\events\core.lua:79: in function <D:\GTA San Andreas\moonloader\lib\samp\events\core.lua:53>
[ML] (error) AutoEat: Script died due to an error. (140C8FD4)