Помогите с кодом для lua скрипта!

cranley

Известный
Автор темы
13
21
У меня скрипт, который делит длинный текст на 2 строки, а так же проблема. На сервере на котором я играю шепот применяется не текстом, а !(текст), без пробелов.
Пытался весь день сделать так, чтоб скрипт работал так же с шепотом, ибо 2 строка уже сопровождается отсутствием !, ибо скрипт не считает данную вещицу командой.
Lua:
script_name("extraMessages")
script_version_number("0.3.1")
script_description("Divides one long message into two short messages. Upgrade Advance-RP SMS system")
script_author("AppleThe")

local sampev = require 'lib.samp.events'
commands = {"f", "r", "t", "n", "w", "s"}
bi = false

function sampev.onSendCommand(msg)
    if bi then bi = false; return end
    local cmd, msg = msg:match("/(%S*) (.*)")
    if msg == nil then return end
    -- cmd = cmd:lower()

    --Рация, радио, ООС чат, шепот, крик (с поддержкой переноса ООС-скобок)
    for i, v in ipairs(commands) do if cmd == v then
        local length = msg:len()
        if msg:sub(1, 2) == "((" then
            msg = string.gsub(msg:sub(4), "%)%)", "")
            if length > 65 then divide(msg, "/" .. cmd .. " (( ", " ))"); return false end
        else
            if length > 65 then divide(msg, "/" .. cmd .. " ", ""); return false end
        end
    end end

    --РП команды
    if cmd == "me" or cmd == "do" then
        local length = msg:len()
        if length > 70 then divide(msg, "/" .. cmd .. " ", "", "ext"); return false end
    end

    --SMS
    if cmd == "sms" then
        local msg = "{}" .. msg
        local number, _msg = msg:match("{}(%d+) (.*)")
        local msg = msg:sub(3)
        if _msg == nil then -- если номер не указан, ищется ближайшее полученное/отправленное сообщение
            for i = 1, 99 do                     -- номер берется из него
                local test = sampGetChatString(i):match("SMS: .* | .*: (.*)")
                if test ~= nil then number = string.match(test, ".* %[.*%.(%d+)%]") end
            end
        else msg = _msg end
        if number == nil then return end
        local length = msg:len()

        -- long SMS
        if length > 66 then divide(msg, "/sms " .. number .. " ", "", "sms"); return false end

        -- short SMS
        if length < 66 then bi = true; sampSendChat("/sms " .. number .. " " .. msg); return false end
    end
end

function sampev.onServerMessage(color, text)
    if color == -65281 and text:find(" %| Получатель: ") then
        return {bit.tobit(0xFFCC00FF), text}
    end
end

function sampev.onSendChat(msg) -- IC чат
    if bi then bi = false; return end
    local length = msg:len()
    if length > 70 then
        divide(msg, "", "")
        return false
    end
end

function divide(msg, beginning, ending, doing) -- разделение сообщения msg на два
    if doing == "sms" then limit = 57 else limit = 72 end
    
    -- -- -- ВЕРСИЯ С ПРИОРИТЕТОМ ТЕКСТА ДЛЯ ПЕРВОГО СООБЩЕНИЯ (ХУЕТА) -- -- --
    -- local one, two = string.match(msg:sub(limit), "(%S*) (.*)")
    -- if one == nil then one = "" end
    -- local one, two = msg:sub(1, limit - 1) .. one .. "...", "..." .. two
    
    -- ВЕРСИЯ С ПРИОРИТЕТОМ ТЕКСТА ДЛЯ ВТОРОГО СООБЩЕНИЯ (ЗБС НО НЕ РАБОТАЕТ) --
    -- local one, two = string.match(msg:sub(1, msg:len() - limit), "(.*) (.*)")
    -- if two == nil then two = "" end
    -- local one, two = one .. "...", "..." .. two .. msg:sub(msg:len() - limit + 1, msg:len())
    
    -- ВЕРСИЯ С ПРИОРИТЕТОМ ТЕКСТА ДЛЯ ВТОРОГО СООБЩЕНИЯ (ПОКА ЧТО РАБОТАЕТ) --
    local one, two = string.match(msg:sub(1, limit), "(.*) (.*)")
    if two == nil then two = "" end
    local one, two = one .. "...", "..." .. two .. msg:sub(limit + 1, msg:len())

    bi = true; sampSendChat(beginning .. one .. ending)
    if doing == "ext" then
        beginning = "/do "
        if two:sub(-1) ~= "." then two = two .. "." end
    end
    bi = true; sampSendChat(beginning .. two .. ending)
end

function main()
  if not isCleoLoaded() or not isSampfuncsLoaded() or not isSampLoaded() then return end
  while not isSampAvailable() do wait(100) end
    if not sampGetCurrentServerName():find("Advance RolePlay") then return end
    wait(-1)
end
 
Решение
Тест 0.1:
script_name("extraMessages")
script_version_number("0.3.1")
script_description("Divides one long message into two short messages. Upgrade Advance-RP SMS system")
script_author("AppleThe")

local sampev = require 'lib.samp.events'
commands = {"f", "r", "t", "n", "w", "s"}
bi = false

function sampev.onSendCommand(msg)
    if bi then bi = false; return end
    local cmd, msg = msg:match("/(%S*) (.*)")
    if msg == nil then return end
    -- cmd = cmd:lower()

    --Рация, радио, ООС чат, шепот, крик (с поддержкой переноса ООС-скобок)
    for i, v in ipairs(commands) do if cmd == v then
        local length = msg:len()
        if msg:sub(1, 2) == "((" then
            msg = string.gsub(msg:sub(4), "%)%)", "")
            if length > 65...

FixZer

Активный
126
36
У меня скрипт, который делит длинный текст на 2 строки, а так же проблема. На сервере на котором я играю шепот применяется не текстом, а !(текст), без пробелов.
Пытался весь день сделать так, чтоб скрипт работал так же с шепотом, ибо 2 строка уже сопровождается отсутствием !, ибо скрипт не считает данную вещицу командой.
Lua:
script_name("extraMessages")
script_version_number("0.3.1")
script_description("Divides one long message into two short messages. Upgrade Advance-RP SMS system")
script_author("AppleThe")

local sampev = require 'lib.samp.events'
commands = {"f", "r", "t", "n", "w", "s"}
bi = false

function sampev.onSendCommand(msg)
    if bi then bi = false; return end
    local cmd, msg = msg:match("/(%S*) (.*)")
    if msg == nil then return end
    -- cmd = cmd:lower()

    --Рация, радио, ООС чат, шепот, крик (с поддержкой переноса ООС-скобок)
    for i, v in ipairs(commands) do if cmd == v then
        local length = msg:len()
        if msg:sub(1, 2) == "((" then
            msg = string.gsub(msg:sub(4), "%)%)", "")
            if length > 65 then divide(msg, "/" .. cmd .. " (( ", " ))"); return false end
        else
            if length > 65 then divide(msg, "/" .. cmd .. " ", ""); return false end
        end
    end end

    --РП команды
    if cmd == "me" or cmd == "do" then
        local length = msg:len()
        if length > 70 then divide(msg, "/" .. cmd .. " ", "", "ext"); return false end
    end

    --SMS
    if cmd == "sms" then
        local msg = "{}" .. msg
        local number, _msg = msg:match("{}(%d+) (.*)")
        local msg = msg:sub(3)
        if _msg == nil then -- если номер не указан, ищется ближайшее полученное/отправленное сообщение
            for i = 1, 99 do                     -- номер берется из него
                local test = sampGetChatString(i):match("SMS: .* | .*: (.*)")
                if test ~= nil then number = string.match(test, ".* %[.*%.(%d+)%]") end
            end
        else msg = _msg end
        if number == nil then return end
        local length = msg:len()

        -- long SMS
        if length > 66 then divide(msg, "/sms " .. number .. " ", "", "sms"); return false end

        -- short SMS
        if length < 66 then bi = true; sampSendChat("/sms " .. number .. " " .. msg); return false end
    end
end

function sampev.onServerMessage(color, text)
    if color == -65281 and text:find(" %| Получатель: ") then
        return {bit.tobit(0xFFCC00FF), text}
    end
end

function sampev.onSendChat(msg) -- IC чат
    if bi then bi = false; return end
    local length = msg:len()
    if length > 70 then
        divide(msg, "", "")
        return false
    end
end

function divide(msg, beginning, ending, doing) -- разделение сообщения msg на два
    if doing == "sms" then limit = 57 else limit = 72 end
   
    -- -- -- ВЕРСИЯ С ПРИОРИТЕТОМ ТЕКСТА ДЛЯ ПЕРВОГО СООБЩЕНИЯ (ХУЕТА) -- -- --
    -- local one, two = string.match(msg:sub(limit), "(%S*) (.*)")
    -- if one == nil then one = "" end
    -- local one, two = msg:sub(1, limit - 1) .. one .. "...", "..." .. two
   
    -- ВЕРСИЯ С ПРИОРИТЕТОМ ТЕКСТА ДЛЯ ВТОРОГО СООБЩЕНИЯ (ЗБС НО НЕ РАБОТАЕТ) --
    -- local one, two = string.match(msg:sub(1, msg:len() - limit), "(.*) (.*)")
    -- if two == nil then two = "" end
    -- local one, two = one .. "...", "..." .. two .. msg:sub(msg:len() - limit + 1, msg:len())
   
    -- ВЕРСИЯ С ПРИОРИТЕТОМ ТЕКСТА ДЛЯ ВТОРОГО СООБЩЕНИЯ (ПОКА ЧТО РАБОТАЕТ) --
    local one, two = string.match(msg:sub(1, limit), "(.*) (.*)")
    if two == nil then two = "" end
    local one, two = one .. "...", "..." .. two .. msg:sub(limit + 1, msg:len())

    bi = true; sampSendChat(beginning .. one .. ending)
    if doing == "ext" then
        beginning = "/do "
        if two:sub(-1) ~= "." then two = two .. "." end
    end
    bi = true; sampSendChat(beginning .. two .. ending)
end

function main()
  if not isCleoLoaded() or not isSampfuncsLoaded() or not isSampLoaded() then return end
  while not isSampAvailable() do wait(100) end
    if not sampGetCurrentServerName():find("Advance RolePlay") then return end
    wait(-1)
end

Добрый вечер, скажите пожалуйста конкретно, что вам нужно.​

 
  • Вау
Реакции: bulba$h и Lance_Sterling

cranley

Известный
Автор темы
13
21

Добрый вечер, скажите пожалуйста конкретно, что вам нужно.​

Добрый, нужно, чтобы чат так же переносился, когда я пишу шепотом.
А на сервере на котором я играю, шепот работает таким образом: !Текст. То есть надо выставить восклицательный знак перед текстом, но текст который будет перенесен не учитывает это и пишет все в обычный чат.
 

FixZer

Активный
126
36
Добрый, нужно, чтобы чат так же переносился, когда я пишу шепотом.
А на сервере на котором я играю, шепот работает таким образом: !Текст. То есть надо выставить восклицательный знак перед текстом, но текст который будет перенесен не учитывает это и пишет все в обычный чат.
Может проще будет пройти в дискорд и там всё обсудить ?
Оставляю свой дс: kirushka4138
 
  • Нравится
Реакции: cranley

FixZer

Активный
126
36
Тест 0.1:
script_name("extraMessages")
script_version_number("0.3.1")
script_description("Divides one long message into two short messages. Upgrade Advance-RP SMS system")
script_author("AppleThe")

local sampev = require 'lib.samp.events'
commands = {"f", "r", "t", "n", "w", "s"}
bi = false

function sampev.onSendCommand(msg)
    if bi then bi = false; return end
    local cmd, msg = msg:match("/(%S*) (.*)")
    if msg == nil then return end
    -- cmd = cmd:lower()

    --Рация, радио, ООС чат, шепот, крик (с поддержкой переноса ООС-скобок)
    for i, v in ipairs(commands) do if cmd == v then
        local length = msg:len()
        if msg:sub(1, 2) == "((" then
            msg = string.gsub(msg:sub(4), "%)%)", "")
            if length > 65 then divide(msg, "/" .. cmd .. " (( ", " ))"); return false end
        else
            if length > 65 then divide(msg, "/" .. cmd .. " ", ""); return false end
        end
    end end

    --РП команды
    if cmd == "me" or cmd == "do" then
        local length = msg:len()
        if length > 70 then divide(msg, "/" .. cmd .. " ", "", "ext"); return false end
    end

    --SMS
    if cmd == "sms" then
        local msg = "{}" .. msg
        local number, _msg = msg:match("{}(%d+) (.*)")
        local msg = msg:sub(3)
        if _msg == nil then -- если номер не указан, ищется ближайшее полученное/отправленное сообщение
            for i = 1, 99 do                     -- номер берется из него
                local test = sampGetChatString(i):match("SMS: .* | .*: (.*)")
                if test ~= nil then number = string.match(test, ".* %[.*%.(%d+)%]") end
            end
        else msg = _msg end
        if number == nil then return end
        local length = msg:len()

        -- long SMS
        if length > 66 then divide(msg, "/sms " .. number .. " ", "", "sms"); return false end

        -- short SMS
        if length < 66 then bi = true; sampSendChat("/sms " .. number .. " " .. msg); return false end
    end
end

function sampev.onServerMessage(color, text)
    if color == -65281 and text:find(" %| Получатель: ") then
        return {bit.tobit(0xFFCC00FF), text}
    end
end

function sampev.onSendChat(msg) -- IC чат
    if bi then bi = false; return end
    local length = msg:len()
    if length > 70 then
        divide(msg, "", "")
        return false
    end
end

function divide(msg, beginning, ending, doing) -- разделение сообщения msg на два
    if doing == "sms" then limit = 57 else limit = 72 end
    
    -- -- -- ВЕРСИЯ С ПРИОРИТЕТОМ ТЕКСТА ДЛЯ ПЕРВОГО СООБЩЕНИЯ (ХУЕТА) -- -- --
    -- local one, two = string.match(msg:sub(limit), "(%S*) (.*)")
    -- if one == nil then one = "" end
    -- local one, two = msg:sub(1, limit - 1) .. one .. "...", "..." .. two
    
    -- ВЕРСИЯ С ПРИОРИТЕТОМ ТЕКСТА ДЛЯ ВТОРОГО СООБЩЕНИЯ (ЗБС НО НЕ РАБОТАЕТ) --
    -- local one, two = string.match(msg:sub(1, msg:len() - limit), "(.*) (.*)")
    -- if two == nil then two = "" end
    -- local one, two = one .. "...", "..." .. two .. msg:sub(msg:len() - limit + 1, msg:len())
    
    -- ВЕРСИЯ С ПРИОРИТЕТОМ ТЕКСТА ДЛЯ ВТОРОГО СООБЩЕНИЯ (ПОКА ЧТО РАБОТАЕТ) --
    local one, two = string.match(msg:sub(1, limit), "(.*) (.*)")
    if two == nil then two = "" end
    local one, two = one .. "...", "..." .. two .. msg:sub(limit + 1, msg:len())

    if string.sub(one, 1, 1) == '!' then
        one, two = one .. "", "!" .. two .. msg:sub(limit + 1, msg:len())
    end

    bi = true; sampSendChat(beginning .. one .. ending)
    if doing == "ext" then
        beginning = "/do "
        if two:sub(-1) ~= "." then two = two .. "." end
    end
    bi = true; sampSendChat(beginning .. two .. ending)
end

function main()
  if not isCleoLoaded() or not isSampfuncsLoaded() or not isSampLoaded() then return end
  while not isSampAvailable() do wait(100) end
    if not sampGetCurrentServerName():find("Advance RolePlay") then return end
    wait(-1)
end
 
Последнее редактирование:
  • Нравится
Реакции: cranley