Код не выполняет свои функции. | Помогите!!!

Статус
В этой теме нельзя размещать новые ответы.

versacheskiy

Новичок
Автор темы
3
0
Версия MoonLoader
Другое
Писал автоматический калькулятор с автоматической отправкой решения в /a для ArzFun. Но скрипт не выполняет ни одно из действий! Помогите!

Код:
script_name("AutoMath by.versacheskiy")
script_author("versacheskiy")
script_version("1.0")

require "monetloader"
local samp = require "sampfuncs"

function main()
    while not isSampAvailable() do wait(100) end

    sampAddChatMessage("{00FF00}[AutoMath]:{FFFFFF} Готов к решению примеров!", -1)

    sampRegisterChatMessageFilter(onChatMessage) -- Фильтр сообщений, работает быстрее
end

function onChatMessage(_, text, prefix, color, pName)
    if text:find("Кто первый решит пример") then
        local num1, op, num2 = text:match("(%d+)%s*([%+%-/%*])%s*(%d+)")
        if num1 and op and num2 then
            local result = calculate(tonumber(num1), op, tonumber(num2))
            if result then
                local delay = math.random(500, 1500) + getPing() -- Учитываем пинг для естественности
                sampAddChatMessage(string.format("{00FF00}[AutoMath]:{FFFFFF} Решаю: %s %s %s = %s (Отправка в /a через %.1f сек)", num1, op, num2, result, delay / 1000), -1)
                wait(delay)
                sampSendChat(string.format("/a %s", result)) -- Отправляем ответ в /a
            end
        end
    end
end

function calculate(a, operator, b)
    if operator == "+" then
        return a + b
    elseif operator == "-" then
        return a - b
    elseif operator == "*" then
        return a * b
    elseif operator == "/" then
        return b ~= 0 and string.format("%.2f", a / b) or "Ошибка (деление на 0)"
    end
    return nil
end
 
Решение
кодикккккк:
require('moonloader')
local sampev = require('samp.events')

function main()
    while not isSampAvailable() do wait(100) end
   
    sampAddChatMessage("{00FF00}[AutoMath]:{FFFFFF} Готов к решению примеров!", -1)
   
    while true do
        wait(0)
    end
end

function sampev.onServerMessage(color, text)
    if text:find("Пример") then
        local num1, op, num2 = text:match("(%d+)%s*([%+%-/%*])%s*(%d+)")
        if num1 and op and num2 then
            local result = calculate(tonumber(num1), op, tonumber(num2))
            if result then
                local delay = math.random(500, 1500)
                sampAddChatMessage(string.format("{00FF00}[AutoMath]:{FFFFFF} Решаю: %s %s %s = %s (Отправка в /a через %.1f сек)", num1, op, num2...

zuxobu

Участник
12
5
кодикккккк:
require('moonloader')
local sampev = require('samp.events')

function main()
    while not isSampAvailable() do wait(100) end
   
    sampAddChatMessage("{00FF00}[AutoMath]:{FFFFFF} Готов к решению примеров!", -1)
   
    while true do
        wait(0)
    end
end

function sampev.onServerMessage(color, text)
    if text:find("Пример") then
        local num1, op, num2 = text:match("(%d+)%s*([%+%-/%*])%s*(%d+)")
        if num1 and op and num2 then
            local result = calculate(tonumber(num1), op, tonumber(num2))
            if result then
                local delay = math.random(500, 1500)
                sampAddChatMessage(string.format("{00FF00}[AutoMath]:{FFFFFF} Решаю: %s %s %s = %s (Отправка в /a через %.1f сек)", num1, op, num2, result, delay / 1000), -1)
                lua_thread.create(function()
                    wait(delay)
                    sampSendChat(string.format("/a %s", result))
                end)
            end
        end
    end
end

function calculate(a, operator, b)
    if operator == "+" then
        return a + b
    elseif operator == "-" then
        return a - b
    elseif operator == "*" then
        return a * b
    elseif operator == "/" then
        return b ~= 0 and string.format("%.2f", a / b) or "Ошибка (деление на 0)"
    end
    return nil
end
 
  • Нравится
Реакции: versacheskiy
Статус
В этой теме нельзя размещать новые ответы.