Jump to content

chat colorido bloquear


Recommended Posts

Posted

Tópico movido para Portuguese / Português > Programação em Lua.

@~#Gaton

Please do not PM me with scripting related question nor support, use the forums instead.

Posted

Use esta função na mensagem que terá os códigos hex removidos:

function removeHex( s )
	if type(s) == "string" then
		while(s:find("#%x%x%x%x%x%x")) do
			s = s:gsub("#%x%x%x%x%x%x","")
		end
	end
	return s or false
end

 

Please do not PM me with scripting related question nor support, use the forums instead.

  • Moderators
Posted
3 hours ago, DNL291 said:

Use esta função na mensagem que terá os códigos hex removidos:


function removeHex( s )
	if type(s) == "string" then
		while(s:find("#%x%x%x%x%x%x")) do
			s = s:gsub("#%x%x%x%x%x%x","")
		end
	end
	return s or false
end

 

Testei essa função mas por algum motivo ela está falhando. Pois o string.find está sempre retornando nil.

Fiz assim e resolveu:

function removeHex (s)
    if type (s) == "string" then
        while (s ~= s:gsub ("#%x%x%x%x%x%x", "")) do
            s = s:gsub ("#%x%x%x%x%x%x", "")
        end
    end
    return s or false
end

 

Eu te ajudei ou achou meu comentário útil? Não esqueça de deixar um Thanksspacer.png

Minhas contribuições para a comunidade: LordHenry - MTA Wiki Profile
Inscreva-se no meu canal do YouTube: Lord Henry - Entertainment
Discord Oficial do MTA: https://mtasa.com/discord
Blacklist e Whitelist de Scripters: Planilha

Por favor, não me envie mensagens privadas solicitando suporte. Crie um tópico no fórum em vez disso.

Posted

Exemplo aplicado no chat do freeroam:

addEventHandler ("onPlayerChat", root, function (msg, type)
	if type == 0 then
		cancelEvent ()
		local mainChatDelay = 1000
		if chatTime[source] and chatTime[source] + mainChatDelay > getTickCount() then
			return	outputChatBox ("[ERRO] #FFFFFFNão floode o chat.", source, 255, 50, 50, true)
		else
			chatTime[source] = getTickCount()
		end
		if isObjectInACLGroup ("user."..getAccountName(getPlayerAccount(source)), aclGetGroup ("Admin")) then
			outputChatBox ("[ADM] #FFFFFF"..removeHex(getPlayerName(source)).." : #FF0000"..removeHex(msg), root, 255, 0, 0, true)
			outputServerLog( "ADMINCHAT: "..removeHex(getPlayerName(source)).. ": "..removeHex(msg))	
		elseif isObjectInACLGroup ("user."..getAccountName(getPlayerAccount(source)), aclGetGroup ("Everyone")) then
			outputChatBox(removeHex(getPlayerName(source))..": #FFFFFF"..removeHex(msg), root, 51, 170, 255, true)
			outputServerLog( "CHAT: "..removeHex(getPlayerName(source))..": "..removeHex(msg))
		end	
	end
end)

function removeHex (text)
	local text = text or ""
	while (string.find (text, "#%x%x%x%x%x%x" )) do
		text = string.gsub (text, "#%x%x%x%x%x%x", "")
	end
	return text;
end

 

Posted
23 hours ago, Lord Henry said:

Testei essa função mas por algum motivo ela está falhando. Pois o string.find está sempre retornando nil.

Fiz assim e resolveu:


function removeHex (s)
    if type (s) == "string" then
        while (s ~= s:gsub ("#%x%x%x%x%x%x", "")) do
            s = s:gsub ("#%x%x%x%x%x%x", "")
        end
    end
    return s or false
end

 

Eu testei a função com várias formas de códigos hexadecimal e funcionou sem retornar nil; Talvez foi um erro causado no seu teste?

Please do not PM me with scripting related question nor support, use the forums instead.

  • Moderators
Posted
2 minutes ago, DNL291 said:

Talvez foi um erro causado no seu teste?

Pode ser. Pois também achei estranho ele sempre retornar nil.

Eu te ajudei ou achou meu comentário útil? Não esqueça de deixar um Thanksspacer.png

Minhas contribuições para a comunidade: LordHenry - MTA Wiki Profile
Inscreva-se no meu canal do YouTube: Lord Henry - Entertainment
Discord Oficial do MTA: https://mtasa.com/discord
Blacklist e Whitelist de Scripters: Planilha

Por favor, não me envie mensagens privadas solicitando suporte. Crie um tópico no fórum em vez disso.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...