краш скрипта после ввода команды

Cypher

Активный
Автор темы
224
55
Версия MoonLoader
.026-beta
1:
act = false

act = false

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand("bronik",arg)
    while true do
        wait(0)

        end
    end

function bronik(arg)
    act = not act
armour = getCharArmour(PLAYER_PED)
    if act and armour < 1 then
thr:run()
    end
end

function thread_function()
wait(5000)
sampSendChat("/armour")
end

ПОЖАЛУЙСТА НЕ СМОТРИТЕ НА КРИВУЮ ТАБУЛЯЦИЮ!!!!
после ввода /bronik крашится скрипт


[ML] (error) autoarmour.lua: attempt to call a nil value
stack traceback:
[ML] (error) autoarmour.lua: Script died due to an error. (0DB65B04)
 
  • Злость
Реакции: qdIbp
Решение
Lua:
local act = false

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand("bronik",function()act = not act print(act and 'вкл' or 'выкл')end)
    while true do wait(0)
        if act then
            if getCharArmour(PLAYER_PED) < 1 then
                wait(5000)
                sampSendChat("/armour")
            end
        end
    end
end
Lua:
local act = false

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand("bronik",function()act = not act print(act and 'вкл' or 'выкл')end)
    while true do wait(0)
        if act then
            if getCharArmour(PLAYER_PED) < 1 then
                wait(5000)
                if getCharArmour(PLAYER_PED) <...

хуега)

РП игрок
Модератор
2,565
2,262
вроде так
1:
act = false

act = false

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand("bronik",arg)
    while true do
        wait(0)

        end
    end

function bronik(arg)
    act = not act
armour = getCharArmour(PLAYER_PED)
    if act and armour < 1 then
thr:run()
    end
end

function thread_function()
wait(5000)
sampSendChat("/armour")
end

ПОЖАЛУЙСТА НЕ СМОТРИТЕ НА КРИВУЮ ТАБУЛЯЦИЮ!!!!
после ввода /bronik крашится скрипт


[ML] (error) autoarmour.lua: attempt to call a nil value
stack traceback:
[ML] (error) autoarmour.lua: Script died due to an error. (0DB65B04)

Lua:
local act = false

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand("bronik", function()
        lua_thread.create(function()
            local armour = getCharArmour(PLAYER_PED)
            if armour < 1 then
                wait(5000)
                sampSendChat("/armour")
            end
        end)
    end)
   
    while true do wait(0)
    end
end
 
  • Нравится
Реакции: qdIbp

Cypher

Активный
Автор темы
224
55
вроде так


Lua:
local act = false

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand("bronik", function()
        lua_thread.create(function()
            local armour = getCharArmour(PLAYER_PED)
            if armour < 1 then
                wait(5000)
                sampSendChat("/armour")
            end
        end)
    end)
 
    while true do wait(0)
    end
end
а зачем тут поток, почему локал функция в мейне, и где проверка на активацию.
Я то хочу узнать что исправить в моем надо шобы начало работать, ане получить новый скрипт
когда бесконечную функцию не используешь пиши wait(-1)
 

DZONE

Известный
184
187
Lua:
require("moonloader")

act = false

act = false

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand("bronik",bronik)
    while true do
        wait(0)

        end
    end

function bronik(arg)
    act = not act
armour = getCharArmour(PLAYER_PED)
    if act and armour < 1 then
thread_function()
    end
end

function thread_function()
wait(5000)
sampSendChat("/armour")
end
 
  • Bug
Реакции: qdIbp

qdIbp

Автор темы
Проверенный
1,387
1,143
Lua:
local act = false

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand("bronik",bronik)
    lua_thread.create(bronik) -- шоб работал wait в function bronik
    wait(-1)-- исп беск.задержку если не исп беск цикл
end
function bronik()
    act = not act
    if act then
        if getCharArmour(PLAYER_PED) < 1 then
            wait(5000)
            sampSendChat("/armour")
        end
    end
end

Либо же

Lua:
local act = false

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand("bronik",function()
        lua_thread.create(function() --для работы wait
            act = not act
            if act then
                if getCharArmour(PLAYER_PED) < 1 then
                    wait(5000)
                    sampSendChat("/armour")
                end
            end
        end)
    end)
    wait(-1)-- исп беск.задержку если не исп беск цикл
end


И захер ты пишешь арг в функции если ты с ними не взаимодействуешь?
 
  • Bug
Реакции: kyrtion

kyrtion

Известный
666
246
Подробно объясняю.
Lua:
function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand("command", it_is_function)
    while true do
        wait(0)
    end
end
-- ...
function it_is_function(arg)
    if #arg ~= 0 then
        sampAddChatMessage(arg, -1)
        -- /command awesome -> [CHAT] awesome. Не будет сработать если аргумент пустой
    else
        sampAddChatMessage("Введи /command [аргумент]", -1)
    end
end

-- АЛЬТЕРНАТИВНЫЙ ВАРИАНТ:
function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand("command", function(arg)
        sampAddChatMessage(arg)
    end)
    while true do
        wait(0)
    end
end
 

Cypher

Активный
Автор темы
224
55
Lua:
local act = false

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand("bronik",bronik)
    lua_thread.create(bronik) -- шоб работал wait в function bronik
    wait(-1)-- исп беск.задержку если не исп беск цикл
end
function bronik()
    act = not act
    if act then
        if getCharArmour(PLAYER_PED) < 1 then
            wait(5000)
            sampSendChat("/armour")
        end
    end
end

Либо же

Lua:
local act = false

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand("bronik",function()
        lua_thread.create(function() --для работы wait
            act = not act
            if act then
                if getCharArmour(PLAYER_PED) < 1 then
                    wait(5000)
                    sampSendChat("/armour")
                end
            end
        end)
    end)
    wait(-1)-- исп беск.задержку если не исп беск цикл
end
так в итоге /bronik команда не активная
После её ввода ничего не происходит
[ML] (error) autoarmour.lua: D:\SAMP - Standart\moonloader\autoarmour.lua:13: attempt to yield across C-call boundary
stack traceback:
[C]: in function 'wait'
 
  • Bug
  • Эм
Реакции: kyrtion и qdIbp

kyrtion

Известный
666
246
так в итоге /bronik команда не активная
После её ввода ничего не происходит
[ML] (error) autoarmour.lua: D:\SAMP - Standart\moonloader\autoarmour.lua:13: attempt to yield across C-call boundary
stack traceback:
[C]: in function 'wait'
Что ты хочешь сделать чтобы получилось скрипт?
 

qdIbp

Автор темы
Проверенный
1,387
1,143
Можешь wait удалить, как по мне он не нужен

так в итоге /bronik команда не активная
После её ввода ничего не происходит
[ML] (error) autoarmour.lua: D:\SAMP - Standart\moonloader\autoarmour.lua:13: attempt to yield across C-call boundary
stack traceback:
[C]: in function 'wait'
Во первых зачем удалять поток, во вторых если не хочешь ждать своей команды удали wait
 
  • Нравится
Реакции: kyrtion

Cypher

Активный
Автор темы
224
55
Можешь wait удалить, как по мне он не нужен
ага и потом изза КД аризоны юза броника в 1 минуту будет кикать за флуд функциями
поясняю, скрипт надевает броник пока его значение меньше одного,
если появится КД аризоны то он будет бесконечно спамить /armour без задержки и изза этого кик

Что ты хочешь сделать чтобы получилось скрипт?
после ввода /bronik скрипт должен ВСЕГДА проверять есть ли на мне броня - если её нет то он должен ждать 5 секунд и писать в чат /armour
 

хуега)

РП игрок
Модератор
2,565
2,262
а зачем тут поток, почему локал функция в мейне
Это функцию, команды, она вызывается внезависимости от мейна в своем потоке, тоже самое, если бы я ее вынес за мейн, но мне кажется проще так
и где проверка на активацию.
не совсем понимаю твой код, поэтому переписал так, как написал бы я
когда бесконечную функцию не используешь пиши wait(-1)
знаю, но в твоем коде был беск. цикл, поэтому оставил его
 

kyrtion

Известный
666
246
ага и потом изза КД аризоны юза броника в 1 минуту будет кикать за флуд функциями
поясняю, скрипт надевает броник пока его значение меньше одного,
если появится КД аризоны то он будет бесконечно спамить /armour без задержки и изза этого кик
для добавление задержку нужно поставить поток
Код:
lua_thread.create(function()
    sampAddChatMessage('Первое сообщение')
    wait(1000) -- 1.000 сек. 1 сек -> 1000 милисек
    sampAddChatMessage('Второе сообщение, спустя 1 секунд')
end)

если есть цикл, то можно поставить задержку
 

Cypher

Активный
Автор темы
224
55
Это функцию, команды, она вызывается внезависимости от мейна в своем потоке, тоже самое, если бы я ее вынес за мейн, но мне кажется проще так

не совсем понимаю твой код, поэтому переписал так, как написал бы я

знаю, но в твоем коде был беск. цикл, поэтому оставил его
я имею введу вместо while true do wait(0) писать while true do wait(-1)
 

qdIbp

Автор темы
Проверенный
1,387
1,143
Lua:
local act = false

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand("bronik",function()act = not act print(act and 'вкл' or 'выкл')end)
    while true do wait(0)
        if act then
            if getCharArmour(PLAYER_PED) < 1 then
                wait(5000)
                sampSendChat("/armour")
            end
        end
    end
end