Jump to content

Remove /me command - Its resource name?


Recommended Posts

  
last_msg = {} 
addEventHandler ( "onPlayerChat", root, function ( message, tp )  
    if last_msg[source] and last_msg[source] == message then 
        cancelEvent ( ) 
    end 
    -- Optinal disable "me" chat completly 
    if ( tp == 1 ) then 
        cancelEvent ( ) 
    end 
    -- Remember last message 
    last_msg[source] = message 
end ) 

If the problem is spam then you might consider to protect the other chat's too since those may be accessed by command as well, cancel the event if the same message is sen't twice is one way, a timer would also work.

Link to comment
  
last_msg = {} 
addEventHandler ( "onPlayerChat", root, function ( message, tp )  
    if last_msg[source] and last_msg[source] == message then 
        cancelEvent ( ) 
    end 
    -- Optinal disable "me" chat completly 
    if ( tp == 1 ) then 
        cancelEvent ( ) 
    end 
    -- Remember last message 
    last_msg[source] = message 
end ) 

If the problem is spam then you might consider to protect the other chat's too since those may be accessed by command as well, cancel the event if the same message is sen't twice is one way, a timer would also work.

and how to cancel the commands /register and /login ?????

Link to comment
addEventHandler("onPlayerCommand", root, 
function(noreg) 
     if noreg == "register" then 
          cancelEvent() 
     end 
end) 
  
-- and 
  
addEventHandler("onPlayerCommand", root, 
function(noreg) 
     if noreg == "login" then -- is right? 
          cancelEvent() 
     end 
end) 

is right?

Link to comment

It's correct but you could add both the "if" statements into the same command handler like this:

-- List of commands to disable 
cmdList = { 
    ["register"]=true, 
    ["login"]=true 
} 
  
-- Disable unwanted commands 
addEventHandler("onPlayerCommand", root, 
function(cmdName) 
     if cmdList[cmdName] then 
          cancelEvent() 
     end 
end) 
  

And then, why not improve it further by adding the commands to a table to make it easier to add even more commands you might want to disable.

Link to comment
-- List of commands to disable 
cmdList = { 
    ["register"]=true, 
    ["login"]=true 
    ["me"]=true 
    ["say"]=true -- right? 
} 
  
-- Disable unwanted commands 
addEventHandler("onPlayerCommand", root, 
function(cmdName) 
     if cmdList[cmdName] then 
          cancelEvent() 
     end 
end) 

right?

Link to comment

It's correct except for those commas at the end of each table line, this will work.

 -- List of commands to disable 
cmdList = { 
    ["register"]=true, 
    ["login"]=true,  -- Don't forget the comma at the end of this and the below line. 
    ["me"]=true, 
    ["say"]=true  
} 
  
-- Disable unwanted commands 
addEventHandler("onPlayerCommand", root, 
function(cmdName) 
     if cmdList[cmdName] then 
          cancelEvent() 
     end 
end) 

the commands "me" and "say" are onPlayerChat so use the previous bit of code with the current piece of code,

Just wondering why do you wan't to remove "say"?

It's also commands that triggers the onPlayerChat event, but you're right, the say command is used with the chatbox command so it won't work to disable those in this event probably. Many roleplay servers removes the main chat as far as I know so it makes sense.

Link to comment
  • 3 years later...
9 hours ago, xNicO.ox said:

how remove code colour of the nickname of comand me?

You have to disable the default /me command and write new one. Try this code:

addEventHandler("onPlayerChat", root, function(message, type)
    if type == 1 then -- if action message
      cancelEvent() -- prevent from sending it into chatbox
      local actionMessage = string.gsub(getPlayerName(source), "#%x%x%x%x%x%x", "").." "..message
      outputChatBox(actionMessage, root, 255, 255, 255, false)
    end
end
      

 

Link to comment
10 hours ago, NeverUnbeatable said:

You have to disable the default /me command and write new one. Try this code:


addEventHandler("onPlayerChat", root, function(message, type)
    if type == 1 then -- if action message
      cancelEvent() -- prevent from sending it into chatbox
      local actionMessage = string.gsub(getPlayerName(source), "#%x%x%x%x%x%x", "").." "..message
      outputChatBox(actionMessage, root, 255, 255, 255, false)
    end
end
      

 

where? admin_server.lua or what?

Link to comment

I'd also point out that 

string.gsub(getPlayerName(source), "#%x%x%x%x%x%x", "")

won't remove double nested colour codes such as ##000000ff0000 but instead only remove the inner code #000000 and the output will contain #ff0000 which, if colour coding is enabled, will turn the subsequent text red.

A better alternative would be to do a while-do loop which would keep doing string.gsub while colour codes are still present (string.find), or if preferable, add some code which would disallow colour codes in names, freeing the need to filter such colour codes from names every time someone says something.

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