Jump to content

Check if the string is a colorcode


'LinKin

Recommended Posts

Hello,

I want to check if the thing that a player writes is a hex color.

This is the code I have

addCommandHandler("color", 
function(p,c,color) 
   if string.match(color ,"%x%x%x%x%x%x") then 
      outputChatBox("You've written a colorcode", p) 
   end 
end) 

But, for example if I type /color 00FF00Hola. It will be true, thus it will say I typed a colorcode..

How can I make it so that it ONLY works if what I type is 00FF00 - Not 00FF00Hola or mthElse00FF00.

I tried

if color == "%x%x%x%x%x%x" 

But it didnt work.

Link to comment
outputChatBox("#0046C8[bF3]: Player "..string.gsub(getPlayerName(source), "#%x%x%x%x%x%x", "").. "#0046C8 Logged in", getRootElement(), TextColour.R, TextColour.G, TextColour.B,true)

You must make a pattern to look after in order to use %x:

"#%x%x%x%x%x%x" will catch the 6 inmediate characters after #.

Link to comment

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...