Arizona Хук диалога

Mr_kaneki

Активный
Автор темы
327
78
Версия SA-MP
  1. 0.3.7-R3
Делал я значит новый фаст ган через меню /gun скрипт в целом находит все нужные оружки но почему-то на отрез не может найти Тек 9 пробуя разные вариации пришел к абсолютно никакому результату

Lua:
script_name("FastGun")
script_author("MR.Kaneki")

local se = require "samp.events"

local info = nil

 -- Команды / названия
local Weapon = {
    ["fgc"]  = "COLT",
    ["fgd"]  = "DESERT EAGLE",
    ["fgs"]  = "Дробовик",
    ["fgu"]  = "Micro Tec-9",
    ["fgmp"] = "MP5",
    ["fgak"] = "AK47",
    ["fgm"]  = "M4",
    ["fgr"]  = "Винтовка"
}

function se.onSendCommand(cmd)
    local name, args = cmd:match("^/([^%s]+)%s*(.*)")
    if Weapon[name] then
        if info then
            sampAddChatMessage("Подожди...", -1)
            return false
        end

        local count = tonumber(args) or 50

        info = {
            step = 0,
            weapon = Weapon[name],
            count = count
        }

        return {"/gun"}
    end
end

function se.onShowDialog(id, style, title, btn1, btn2, text)
    if not info then return end

    --  Меню оружия
    if info.step == 0 and title:find("Меню оружия") then
        local lines = {}
        for line in text:gmatch("[^\r\n]+") do
            table.insert(lines, line)
        end

        local foundIndex = nil

        for i, line in ipairs(lines) do
            local upper = line:upper()

            if upper:find(info.weapon) then
                foundIndex = i - 1 -- SAMP index
                break
            end
        end

        if foundIndex then
            sampSendDialogResponse(id, 1, foundIndex, nil)
            info.step = 1
        else
            sampAddChatMessage("Оружие не найдено!", -1)
            info = nil
        end

        return false
    end

    --  Ввод количества
    if info.step == 1 and text:find("Введите количество") then
        sampSendDialogResponse(id, 1, nil, tostring(info.count))
        info = nil
        return false
    end
end
 
Решение
тебе надо true в конце, который будет заставлять луа искать обычный текст, а не паттерн. так как название типа Tec-9 в луа паттернах может ломать поиск
Lua:
upperLine:find(name:upper(), 1, true)

Lua:
script_name("FastGun")
script_author("MR.Kaneki")

local se = require "samp.events"

local info = nil

local Weapon = {
    ["fgc"]  = {"COLT"},
    ["fgd"]  = {"DESERT EAGLE"},
    ["fgs"]  = {"Дробовик"},
    ["fgu"]  = {"MICRO TEC-9", "MICROTEC-9", "TEC-9", "TEC 9", "TEC9", "TEK-9", "TEK 9", "Тек-9", "Тек 9"},
    ["fgmp"] = {"MP5"},
    ["fgak"] = {"AK47", "AK-47"},
    ["fgm"]  = {"M4"},
    ["fgr"]  = {"Винтовка"}
}

local function clearColors(s)
    return s:gsub("{%x%x%x%x%x%x}", "")
end

local function findWeapon(line, names)...

pewpewpewpew

Известный
Модератор
680
204
тебе надо true в конце, который будет заставлять луа искать обычный текст, а не паттерн. так как название типа Tec-9 в луа паттернах может ломать поиск
Lua:
upperLine:find(name:upper(), 1, true)

Lua:
script_name("FastGun")
script_author("MR.Kaneki")

local se = require "samp.events"

local info = nil

local Weapon = {
    ["fgc"]  = {"COLT"},
    ["fgd"]  = {"DESERT EAGLE"},
    ["fgs"]  = {"Дробовик"},
    ["fgu"]  = {"MICRO TEC-9", "MICROTEC-9", "TEC-9", "TEC 9", "TEC9", "TEK-9", "TEK 9", "Тек-9", "Тек 9"},
    ["fgmp"] = {"MP5"},
    ["fgak"] = {"AK47", "AK-47"},
    ["fgm"]  = {"M4"},
    ["fgr"]  = {"Винтовка"}
}

local function clearColors(s)
    return s:gsub("{%x%x%x%x%x%x}", "")
end

local function findWeapon(line, names)
    line = clearColors(line)

    local upperLine = line:upper()

    for _, name in ipairs(names) do
        if upperLine:find(name:upper(), 1, true) or line:find(name, 1, true) then
            return true
        end
    end

    return false
end

function se.onSendCommand(cmd)
    local name, args = cmd:match("^/([^%s]+)%s*(.*)")

    if Weapon[name] then
        if info then
            sampAddChatMessage("Подожди...", -1)
            return false
        end

        info = {
            step = 0,
            weapon = Weapon[name],
            count = tonumber(args) or 50
        }

        return {"/gun"}
    end
end

function se.onShowDialog(id, style, title, btn1, btn2, text)
    if not info then return end

    if info.step == 0 and title:find("Меню оружия", 1, true) then
        local lines = {}

        for line in text:gmatch("[^\r\n]+") do
            table.insert(lines, line)
        end

        local foundIndex = nil

        for i, line in ipairs(lines) do
            if findWeapon(line, info.weapon) then
                foundIndex = i - 1
                break
            end
        end

        if foundIndex then
            sampSendDialogResponse(id, 1, foundIndex, nil)
            info.step = 1
        else
            sampAddChatMessage("Оружие не найдено!", -1)
            info = nil
        end

        return false
    end

    if info.step == 1 and text:find("Введите количество", 1, true) then
        sampSendDialogResponse(id, 1, 0, tostring(info.count))
        info = nil
        return false
    end
end