Ошибка в коде

DiteD331

Участник
Автор темы
87
12
Версия MoonLoader
.026-beta
Скрипт крашит игру, в чём ошибся?

код:
local active = true

script_name(FOR_YURA)
script_author(DiteD331)

function main()
    while not isSampAvailable() do wait(0) end
        sampAddChatMessage('Script activated', 0xff0000)
    while true do
        wait(0)
        sampRegisterChatCommand('okay', okay)
        sampRegisterChatCommand('notokay', NotOkay)
    end
end

function okay()
    while active do
        sampSendChat('/anim 6 13')
        sampAddChatMessage('Proverka', 0xff0000)
    end
end

function NotOkay()
    active = not active
end
 

ChromiusJ

Известный
Друг
4,900
3,189
Скрипт крашит игру, в чём ошибся?

код:
local active = true

script_name(FOR_YURA)
script_author(DiteD331)

function main()
    while not isSampAvailable() do wait(0) end
        sampAddChatMessage('Script activated', 0xff0000)
    while true do
        wait(0)
        sampRegisterChatCommand('okay', okay)
        sampRegisterChatCommand('notokay', NotOkay)
    end
end

function okay()
    while active do
        sampSendChat('/anim 6 13')
        sampAddChatMessage('Proverka', 0xff0000)
    end
end

function NotOkay()
    active = not active
end
1712161925755.png

1.у тебя информация о скрипте должна быть в кавычках, на вики написано же
2. ты регистрируешь команды в беск.цикле, убери оттуда, и перенеси это выше в мейн
 

MLycoris

Режим чтения
Проверенный
1,821
1,860
пиздец посмотри гайды


Lua:
script_name('FOR_YURA')
script_author('DiteD331')
local active = true

function main()
    while not isSampAvailable() do wait(100) end
    sampAddChatMessage('Script activated', 0xff0000)
    sampRegisterChatCommand('okay', function()
        sampSendChat('/anim 6 13')
        sampAddChatMessage('Proverka', 0xff0000)
    end)
    sampRegisterChatCommand('notokay', function()
        active = not active
    end)
    while true do wait(0)
       
    end
end
 

minxty

Известный
875
750
1. Ты КАЖДЫЕ 0 миллисекунд регистрируешь 2 новые команды, а нужно только один раз после загрузки скрипта
2. Что бы игра не крашила, создавай в бесконечном цикле задержку в 0 миллисекунд, и не забывай про потоки
Вот рабочий код
Lua:
local active = true

script_name('FOR_YURA')
script_author('DiteD331')

function main()
    while not isSampAvailable() do wait(0) end
    sampAddChatMessage('Script activated', 0xff0000)
    sampRegisterChatCommand('okay', okay)
    sampRegisterChatCommand('notokay', NotOkay)
    while true do
        wait(0)

    end
end

function okay()
    lua_thread.create(function()
        while active do wait(0)
            sampSendChat('/anim 6 13')
            sampAddChatMessage('Proverka', 0xff0000)
        end
    end)
end

function NotOkay()
    active = not active
end
 
  • Нравится
Реакции: Iskon и qdIbp