multiple (onServerMessage) reliant scripts

AMR42O

Новичок
Автор темы
1
0
so i made multiple scripts which use (onServerMessage)
But i am not able to use all those scripts.

Example:
Script_1.lua - changes [Radio] in chat to -> [R]
Script_2.lua - changes [Advertisment] in chat to ->[Ad]

Now if i put both of their code in script 1, it works.
but both scripts differently don't work.
I know this is some limitation but is there any work around? (sorry i don't know Russian)
-------------------------------------------------------------------------------------------------------
Russian: (google translate)
поэтому я сделал несколько сценариев, которые используют (onServerMessage)
Но я не могу использовать все эти скрипты.

Пример:
Script_1.lua - меняет [Radio] в чате на -> [R]
Script_2.lua - изменяет [Advertisment] в чате на ->[Ad]

Теперь, если я помещу оба их кода в скрипт 1, он сработает.
но оба скрипта по-разному не работают.
Я знаю, что это некоторое ограничение, но есть ли обходной путь? (извините я не знаю Pусский)
 

Sidney31

Известный
1,132
385
Sorry, I don't know enough English, so I use Yandex Translator. =) Try using the code I attached below. I checked it, everything works for me.

Lua:
local sampev = require 'lib.samp.events'
function sampev.onServerMessage(color, text)
    if text:match('Advertisment') then
        msg = text:match('Advertisment')
         str = string.gsub (text, msg, "AD")
        return {color, str}
    end
    if text:match('Radio') then
        msg = text:match('Radio')
        str = string.gsub (text, msg, "R")
        return {color, str}
    end
end