ищу фикс { в диалоге

players

Известный
Автор темы
56
10
1777566108832.png
 
Решение
Lua:
script_name("Brace Fix")

require "lib.moonloader"
local sampev = require "lib.samp.events"

local KEEP_COLOR_CODES = true

local LEFT_BRACE_REPLACE  = "("
local RIGHT_BRACE_REPLACE = ")"

local function fixDialogText(s)
    if not s or s == "" then return s end

    if KEEP_COLOR_CODES then
        local colors = {}

        s = s:gsub("{%x%x%x%x%x%x}", function(color)
            local key = "\1" .. tostring(#colors + 1) .. "\2"
            colors[key] = color
            return key
        end)

        s = s:gsub("{", LEFT_BRACE_REPLACE)
             :gsub("}", RIGHT_BRACE_REPLACE)

        for key, color in pairs(colors) do
            s = s:gsub(key, color)
        end
    else
        s = s:gsub("{%x%x%x%x%x%x}", "")

        s...

pewpewpewpew

Известный
544
146
Lua:
script_name("Brace Fix")

require "lib.moonloader"
local sampev = require "lib.samp.events"

local KEEP_COLOR_CODES = true

local LEFT_BRACE_REPLACE  = "("
local RIGHT_BRACE_REPLACE = ")"

local function fixDialogText(s)
    if not s or s == "" then return s end

    if KEEP_COLOR_CODES then
        local colors = {}

        s = s:gsub("{%x%x%x%x%x%x}", function(color)
            local key = "\1" .. tostring(#colors + 1) .. "\2"
            colors[key] = color
            return key
        end)

        s = s:gsub("{", LEFT_BRACE_REPLACE)
             :gsub("}", RIGHT_BRACE_REPLACE)

        for key, color in pairs(colors) do
            s = s:gsub(key, color)
        end
    else
        s = s:gsub("{%x%x%x%x%x%x}", "")

        s = s:gsub("{", LEFT_BRACE_REPLACE)
             :gsub("}", RIGHT_BRACE_REPLACE)
    end

    return s
end

function sampev.onShowDialog(id, style, title, button1, button2, text)
    title = fixDialogText(title)
    button1 = fixDialogText(button1)
    button2 = fixDialogText(button2)
    text = fixDialogText(text)

    return {id, style, title, button1, button2, text}
end

function main()
    repeat wait(0) until isSampAvailable()
    sampAddChatMessage("{73B461}[Brace Fix] {FFFFFF}Загружен. Фикс { и } в диалогах активен.", -1)

    while true do
        wait(0)
    end
end
 
  • Нравится
Реакции: players

players

Известный
Автор темы
56
10
Lua:
script_name("Brace Fix")

require "lib.moonloader"
local sampev = require "lib.samp.events"

local KEEP_COLOR_CODES = true

local LEFT_BRACE_REPLACE  = "("
local RIGHT_BRACE_REPLACE = ")"

local function fixDialogText(s)
    if not s or s == "" then return s end

    if KEEP_COLOR_CODES then
        local colors = {}

        s = s:gsub("{%x%x%x%x%x%x}", function(color)
            local key = "\1" .. tostring(#colors + 1) .. "\2"
            colors[key] = color
            return key
        end)

        s = s:gsub("{", LEFT_BRACE_REPLACE)
             :gsub("}", RIGHT_BRACE_REPLACE)

        for key, color in pairs(colors) do
            s = s:gsub(key, color)
        end
    else
        s = s:gsub("{%x%x%x%x%x%x}", "")

        s = s:gsub("{", LEFT_BRACE_REPLACE)
             :gsub("}", RIGHT_BRACE_REPLACE)
    end

    return s
end

function sampev.onShowDialog(id, style, title, button1, button2, text)
    title = fixDialogText(title)
    button1 = fixDialogText(button1)
    button2 = fixDialogText(button2)
    text = fixDialogText(text)

    return {id, style, title, button1, button2, text}
end

function main()
    repeat wait(0) until isSampAvailable()
    sampAddChatMessage("{73B461}[Brace Fix] {FFFFFF}Загружен. Фикс { и } в диалогах активен.", -1)

    while true do
        wait(0)
    end
end
помогло сяб