Замена, удаление части текста LUA

AterEX

Участник
Автор темы
44
1
Версия MoonLoader
.026-beta
Lua:
local array = {"КПЗ: Red County PD" = "RCPD", "КПЗ: Las Venturas" = "LV"}

function sampev.onServerMessage(color, text)
    if string.find(text, "| Без адвоката", 1, true) then
        lua_thread.create(function()
            wait(1000)
            sampAddChatMessage(string.gsub(text, "%D", array), -1)
          end)
    end
end

Скрипт для аризоны, при вводе команды /zeks сервер пишет типо: Test_Name(ID) | Время: x мин | Залог: $x | КПЗ: x | Без адвоката
Но почему-то выдает ошибку C:\Games\GTA San Andreas\moonloader\test.lua:5: '}' expected near '='
Делал по этому примеру:

Lua:
local t = {green = "red", black = "blue"}
local str1 = "green, black, black, green"      -- строка
log (str1)
local str2 = string.gsub(str1, "(%a+)", t)    -- заменить все слова 'green' на 'red' и 'black' на 'blue'
log (str2)
 
Последнее редактирование:

azimoff

azimoff
Проверенный
90
70
if string.find(text, "| Без адвоката", 1, true) then
замени на
Lua:
if text:find("| Без адвоката") then
А что нужно сделать объясни?

UPD 17:00

понял в чем ошибка, сделай так
local array = {["КПЗ: Red County PD"] = "RCPD", ["КПЗ: Las Venturas"] = "LV"}
 
Последнее редактирование:
  • Нравится
Реакции: AterEX

AterEX

Участник
Автор темы
44
1
if string.find(text, "| Без адвоката", 1, true) then
замени на
Lua:
if text:find("| Без адвоката") then
А что нужно сделать объясни?

UPD 17:00

понял в чем ошибка, сделай так
local array = {["КПЗ: Red County PD"] = "RCPD", ["КПЗ: Las Venturas"] = "LV"}
Lua:
KPZ = {["Неизвестно"]="LSPD", ["Red County PD"]="RCPD",["San Fierro PD"]="SFPD",["Las Venturas PD"]="LVPD"}

function sampev.onServerMessage(color, text)
    if string.find(text, "Без адвоката", 1, true) then
        lua_thread.create(function()
            for k, value in ipairs(KPZ) do
                wait(1000)
                sampAddChatMessage(string.gsub(text, k, value), -1)
            end
          end)
    end
end
Сделал так, но ничего не происходит, возможно напутал с циклом for.
Ребята, я уже все перепробовал, посмотрел гайд, сделал все точь в точь, но все равно не работает.
 
Последнее редактирование:

AterEX

Участник
Автор темы
44
1
Код:
if text:find('Без адвоката') then
for k, v in pairs(KPZ) do
if text:find(k) then
text:gsub(k, v)
return text
end
end
end
Спасибо, завтра чекну
Код:
if text:find('Без адвоката') then
for k, v in pairs(KPZ) do
if text:find(k) then
text = text:gsub(k, v)
return text
end
end
end
Не робит(
Lua:
require "lib.moonloader"
local sampev = require "lib.samp.events"

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    while true do wait(0) end
end

KPZ = {
    ["Неизвестно"] = "LSPD",
    ["Red County PD"] = "RCPD",
    ["San Fierro PD"] = "SFPD",
    ["Las Venturas PD"] = "LVPD"
}

function sampev.onServerMessage(color, text)
    if text:find('Без адвоката') then
        for k, v in pairs(KPZ) do
            if text:find(k) then
                text = text:gsub(k, v)
                return text
            end
        end
    end
end
 
Последнее редактирование:

CaJlaT

Овощ
Модератор
2,807
2,613
Спасибо, завтра чекну

Не робит(
Lua:
require "lib.moonloader"
local sampev = require "lib.samp.events"

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    while true do wait(0) end
end

KPZ = {
    ["Неизвестно"] = "LSPD",
    ["Red County PD"] = "RCPD",
    ["San Fierro PD"] = "SFPD",
    ["Las Venturas PD"] = "LVPD"
}

function sampev.onServerMessage(color, text)
    if text:find('Без адвоката') then
        for k, v in pairs(KPZ) do
            if text:find(k) then
                text = text:gsub(k, v)
                return text
            end
        end
    end
end
return {color, text}