greenday

Remove /me command - Its resource name?

Recommended Posts

Players on my server abuse /me command, they bind it and spam the chat box. I wanna know the name of the resource this command is in. I searched a lot and couldn't find any thread related to it.

Share this post


Link to post

/me is a command that is created by the MTA server. You can use this script to cancel it:

addEventHandler ( "onPlayerChat", root, function ( _, tp )  
    if ( tp == 1 ) then 
        cancelEvent ( ) 
    end 
end ) 

Share this post


Link to post
  
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.

Share this post


Link to post
  
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 ?????

Share this post


Link to post

you really should try to make it yourself, and us help if you have errors but.

addEventHandler("onPlayerCommand", root, 
function(noreg) 
     if noreg == "register" then 
          cancelEvent() 
     end 
end) 

Share this post


Link to post
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?

Share this post


Link to post

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.

Share this post


Link to post
-- 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?

Share this post


Link to post

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"?

Share this post


Link to post

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.

Share this post


Link to post

I'm actually pretty sure that the /register (not sure about /login) is part of the default admin resource.

Edit: I checked the admin resource, and it should be (by default) in admin/server/admin_server.lua on lines 447-468

Share this post


Link to post
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
      

 

Share this post


Link to post
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?

Share this post


Link to post
7 hours ago, xNicO.ox said:

where? admin_server.lua or what?

Any serverside .lua script. Learn how to script and ask only if you have question related to scripting problem.

Share this post


Link to post

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.

Share this post


Link to post

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.