Ошибка в коде

diaslo123

Новичок
Автор темы
4
0
Пишу скрипт для удобств медика, нужно чтобы работало так, от сервера приходило сообщение в котором есть str 'AZ' это ворк, вывод так-же работает, но когда после того как строку находит и отправляет сообщение о начале отсчёта, система перестает работать на самой функции отсчёта, вот скрипт:
памагити :(
lua:
local samp = require("samp.events")
local encoding = require("encoding")
require('lib.moonloader')

encoding.default = "CP1251"
u8 = encoding.UTF8

local time = 0
local isCounting = false


function samp.onServerMessage(color, text)
    if text:find('AZ') then
        sampAddChatMessage('Начинаю отсчёт.', 0xFF0000)
        isCounting = true
        time = 300
        print(time, isCounting)
        while time > 0 do
            wait(1000)
            time = time - 1
            print(time)
        end
        isCounting = false
        print(isCounting, time)
    end
end

function main()
    while not isSampAvailable() do wait(0) end
    sampAddChatMessage('DoctorHelper loaded.', 0xFFFFFF)
    while true do
        wait(0)
        if wasKeyPressed(VK_4) and not sampIsCursorActive() then
            if isCounting then
                sampAddChatMessage('Осталось: ' .. time, 0xFF0000)
            else
                sampAddChatMessage('Отсчёт не запущен.', 0xFF0000)
            end
        end
    end
end

Только учусь скриптингу в сампе)
ошибки:

[ML] (error) HELPERFORCARETI.lua: ...ames Launcher\bin\new2024\moonloader\HELPERFORCARETI.lua:17: attempt to yield across C-call boundary
stack traceback:
[C]: in function 'wait'
...ames Launcher\bin\new2024\moonloader\HELPERFORCARETI.lua:17: in function 'otchet'
...ames Launcher\bin\new2024\moonloader\HELPERFORCARETI.lua:31: in function 'callback'
...Launcher\bin\new2024\moonloader\lib\samp\events\core.lua:79: in function <...Launcher\bin\new2024\moonloader\lib\samp\events\core.lua:53>
[ML] (error) HELPERFORCARETI.lua: Script died due to an error. (22C29CDC)
 

Neil_

Активный
200
29
Lua:
local samp = require("samp.events")
local encoding = require("encoding")
require('lib.moonloader')

encoding.default = "CP1251"
u8 = encoding.UTF8

local time = 0

function main()
    while not isSampAvailable() do wait(0) end
    sampAddChatMessage('DoctorHelper loaded.', 0xFFFFFF)

    while true do
        wait(0)
        if (isKeyJustPressed(VK_4) and not sampIsCursorActive()) then
            if ((time - os.time()) > 0) then
                sampAddChatMessage('Осталось: ' .. (time - os.time()), 0xFF0000)
            else
                sampAddChatMessage('Отсчёт не запущен.', 0xFF0000)
            end
        end
    end
end

function sampev.onServerMessage(color, text)
    if (string.find(text, 'AZ')) then
        sampAddChatMessage('Начинаю отсчёт.', 0xFF0000)
        time = (os.time() + 300)
    end   
end

И вообще, тебе в этот раздел https://www.blast.hk/forums/163/
 
Последнее редактирование:
  • Нравится
Реакции: diaslo123

diaslo123

Новичок
Автор темы
4
0
Lua:
local samp = require("samp.events")
local encoding = require("encoding")
require('lib.moonloader')

encoding.default = "CP1251"
u8 = encoding.UTF8

local time = 0

function main()
    while not isSampAvailable() do wait(0) end
    sampAddChatMessage('DoctorHelper loaded.', 0xFFFFFF)

    while true do
        wait(0)
        if (isKeyJustPressed(VK_4) and not sampIsCursorActive()) then
            if ((time - os.time()) > 0) then
                sampAddChatMessage('Осталось: ' .. (time - os.time()), 0xFF0000)
            else
                sampAddChatMessage('Отсчёт не запущен.', 0xFF0000)
            end
        end
    end
end

function sampev.onServerMessage(color, text)
    if (string.find(text, 'AZ')) then
        sampAddChatMessage('Начинаю отсчёт.', 0xFF0000)
        time = (os.time() + 300)
    end  
end

И вообще, тебе в этот раздел https://www.blast.hk/forums/163/
отдуши брааат