Скрипт луа крашит игру

lovandog

Активный
Автор темы
226
98
Версия MoonLoader
.026-beta
Писал систему форм в хелпере для админов, но столкнулся с проблемой крашей при выполнении формы, причем краш происходит не сразу, а через какое-то время после принятия формы. может кто поможет если не лень?
Lua:
if text:find('{FFFFFF}• {......}(.+){FFFFFF} • (%a+_%a+)%[%d+%]: {......}(.*)') then
            formPrefix, formNick, formMsg = text:match('{FFFFFF}• {......}(.+){FFFFFF} • (%a+_%a+)%[%d+%]: {......}(.*)')
            if formMsg:find('/setsp') then
                formId = formMsg:match('(%d+)')
                if #formId == 0 then
                    sampAddChatMessage(sName .. 'Найдена форма, но не найден ID.', -1)
                else
                    lua_thread.create(function()
                        formWait = true
                        sampAddChatMessage(mainColor ..'[Forma] {ffffff}Найдена форма:' .. formMsg .. ', отправитель - ' .. formNick,-1)
                        sampAddChatMessage(mainColor ..'[Forma] {ffffff}Нажмите на клавишу B, чтобы принять форму',-1)
                        printStyledString(formMsg .. " 5 WAIT~n~~r~BY " .. formNick, 1000, 4)
                        wait(1000)
                        printStyledString(formMsg .. " 4 WAIT~n~~r~BY " .. formNick, 1000, 4)
                        wait(1000)
                        printStyledString(formMsg .. " 3 WAIT~n~~r~BY " .. formNick, 1000, 4)
                        wait(1000)
                        printStyledString(formMsg .. " 2 WAIT~n~~r~BY " .. formNick, 1000, 4)
                        wait(1000)
                        printStyledString(formMsg .. " 1 WAIT~n~~r~BY " .. formNick, 1000, 4)
                        wait(1000)
                        formWait = false
                    end)
                    lua_thread.create(function()                
                        while formWait do
                            wait(0)
                            if wasKeyPressed(0x42) then
                                lua_thread.create(function()
                                    sampSendChat('/setsp ' .. formId)
                                    wait(1000)
                                    sampSendChat('/a [Forma] + ')
                                    HLcfg.config.dayForms = HLcfg.config.dayForms + 1
                                    LsessionForma = LsessionForma + 1
                                    formWait = false
                                end)
                            end
                        end
                    end)
                end
            end
            if formMsg:find('/givebike') then
                formId = formMsg:match('(%d+)')
                if #formId == 0 then
                    sampAddChatMessage(sName .. 'Найдена форма, но не найден ID.', -1)
                else
                    lua_thread.create(function()
                        formWait = true
                        sampAddChatMessage(mainColor ..'[Forma] {ffffff}Найдена форма:' .. formMsg .. ', отправитель - ' .. formNick,-1)
                        sampAddChatMessage(mainColor ..'[Forma] {ffffff}Нажмите на клавишу B, чтобы принять форму',-1)
                        printStyledString(formMsg .. " 5 WAIT~n~~r~BY " .. formNick, 1000, 4)
                        wait(1000)
                        printStyledString(formMsg .. " 4 WAIT~n~~r~BY " .. formNick, 1000, 4)
                        wait(1000)
                        printStyledString(formMsg .. " 3 WAIT~n~~r~BY " .. formNick, 1000, 4)
                        wait(1000)
                        printStyledString(formMsg .. " 2 WAIT~n~~r~BY " .. formNick, 1000, 4)
                        wait(1000)
                        printStyledString(formMsg .. " 1 WAIT~n~~r~BY " .. formNick, 1000, 4)
                        wait(1000)
                        formWait = false
                    end)
                    lua_thread.create(function()                
                        while formWait do
                            wait(0)
                            if wasKeyPressed(0x42) then
                                lua_thread.create(function()
                                    sampSendChat('/givebike ' .. formId)
                                    wait(1000)
                                    sampSendChat('/a [Forma] +')
                                    HLcfg.config.dayForms = HLcfg.config.dayForms + 1
                                    LsessionForma = LsessionForma + 1
                                    formWait = false
                                end)
                            end
                        end
                    end)
                end
            end
        end
 
Решение
Решил проблему.
Была в том что я засунул lua_thread.create в while
Lua:
                    lua_thread.create(function()               
                        while formWait do
                            wait(0)
                            if wasKeyPressed(0x42) then
                                lua_thread.create(function()
                                    sampSendChat('/givebike ' .. formId)
                                    wait(1000)
                                    sampSendChat('/a [Forma] +')
                                    HLcfg.config.dayForms = HLcfg.config.dayForms + 1
                                    LsessionForma = LsessionForma + 1
                                    formWait = false...

lovandog

Активный
Автор темы
226
98
А тебя как крашит? Игра замирает? Либо вылет с окном краша?
игра просто закрывается без окна

при этом форма успевает выдаться, но потом просто закрывается гташка

1643138955275.png
бывает что не крашит а кидает варнинг
 
Последнее редактирование:

lovandog

Активный
Автор темы
226
98
Решил проблему.
Была в том что я засунул lua_thread.create в while
Lua:
                    lua_thread.create(function()               
                        while formWait do
                            wait(0)
                            if wasKeyPressed(0x42) then
                                lua_thread.create(function()
                                    sampSendChat('/givebike ' .. formId)
                                    wait(1000)
                                    sampSendChat('/a [Forma] +')
                                    HLcfg.config.dayForms = HLcfg.config.dayForms + 1
                                    LsessionForma = LsessionForma + 1
                                    formWait = false
                                end)
                            end
                        end
                    end)
ошибка в логе была cannot resume non-suspended coroutine, так что может кому это поможет
а вообще сам не понял, зачем я сделал два lua_thread.create, но ладно