Jump to content

[Solved] Disable outputChatBox


Recommended Posts

Posted (edited)

Hello,

i wanted to prevent scripts or map to spam the chatbox with messages, so i removed the right with the acl

"function.outputChatBox" access="false">

it's working well for the non-admin scripts, but I just can't do the same for the maps, i tried by removing the right to all the acls, but the in-map scritps can still use outputChatBox.

Someone could help me please?

Edited by Guest
Posted

Not tested:

function preventSpam(message, element) 
    if not (getElementType(element) == "player") then 
        cancelEvent() 
    end 
end 
addEventHandler("onChatMessage", getRootElement(), preventSpam) 

Posted
Not tested:
function preventSpam(message, element) 
    if not (getElementType(element) == "player") then 
        cancelEvent() 
    end 
end 
addEventHandler("onChatMessage", getRootElement(), preventSpam) 

makes no sense.

Posted
Not tested:
function preventSpam(message, element) 
    if not (getElementType(element) == "player") then 
        cancelEvent() 
    end 
end 
addEventHandler("onChatMessage", getRootElement(), preventSpam) 

makes no sense.

Why? :)

Posted
onPlayerChat

cancelEvent

?? What about this?

And you can't cancel that event "onChatMessage"

That won't work, as the wiki says "This event is triggered when a player chats inside the chat box."

So it won't work for resources' messages

Posted

Thx for the help, it actually works if i use the client event:

function preventSpam() 
    if not (getElementType(source) == "player") then 
        cancelEvent() 
    end 
end 
addEventHandler("onClientChatMessage", getRootElement(), preventSpam) 

But it cancel all the chatbox msg, probably because the event doesn't return the element's name :/ i don' tknow how to fix that

Posted
But it cancel all the chatbox msg, probably because the event doesn't return the element's name :/ i don' tknow how to fix that

That's because the source of that event is the root element, so you aren't gonna get the resource that outputs the message.

Posted

Well thanks, but it's not helping me in any ways, when i try with the server , onChatMessage, i can't cancel this event, and it doesn't output Clients messages

if anyone have an idea to help me

Posted

You can try this, but its just something, not tested...

addEventHandler("onChatMessage",root, 
function () 
if (getElementType(source) ~= "player") then 
cancelEvent() 
end 
end 
) 

Posted
You can try this, but its just something, not tested...
addEventHandler("onChatMessage",root, 
function () 
if (getElementType(source) ~= "player") then 
cancelEvent() 
end 
end 
) 

i tried this, and it does nothing, it looks like we can't cancel this event :/ + i tested it and if im not wrong it doesn't detect client outputChatBox :/

Posted

client

[lua]function preventSpam() 
        cancelEvent() 
  outputChatBox("Chat Block",source) 
end 
addEventHandler("onClientChatMessage", getRootElement(), preventSpam) 

[/lua]

or

Server

  
function blockChatMessage(a) 
 if a ~= 911 then 
    cancelEvent() 
    cancelEvent() 
 end 
end 
addEventHandler( "onPlayerChat", getRootElement(), blockChatMessage ) 
  
  

Posted
You can try this, but its just something, not tested...
addEventHandler("onChatMessage",root, 
function () 
if (getElementType(source) ~= "player") then 
cancelEvent() 
end 
end 
) 

i tried this, and it does nothing, it looks like we can't cancel this event :/ + i tested it and if im not wrong it doesn't detect client outputChatBox :/

type

/debugscript 3

then restart the resource that this code is in, and tell me the error message you got.

Posted
You can try this, but its just something, not tested...
addEventHandler("onChatMessage",root, 
function () 
if (getElementType(source) ~= "player") then 
cancelEvent() 
end 
end 
) 

i tried this, and it does nothing, it looks like we can't cancel this event :/ + i tested it and if im not wrong it doesn't detect client outputChatBox :/

type

/debugscript 3

then restart the resource that this code is in, and tell me the error message you got.

by Mr.Pres[T]ege on Wed Apr 03, 2013 2:26 pm

--[[

onPlayerChat

]]--

cancelEvent

?? What about this?

And you can't cancel that event "onChatMessage"

Posted
You can try this, but its just something, not tested...
addEventHandler("onChatMessage",root, 
function () 
if (getElementType(source) ~= "player") then 
cancelEvent() 
end 
end 
) 

i tried this, and it does nothing, it looks like we can't cancel this event :/ + i tested it and if im not wrong it doesn't detect client outputChatBox :/

type

/debugscript 3

then restart the resource that this code is in, and tell me the error message you got.

I am not getting any error message, it's simply like i can't cancel this event

by Mr.Pres[T]ege on Wed Apr 03, 2013 2:26 pm

--[[

onPlayerChat

]]--

cancelEvent

?? What about this?

And you can't cancel that event "onChatMessage"

I actually want to cancel scripts messages, not players ones

Posted

Please, next time read the wiki.

Parameters

string theMessage, resource / element theElement

  • theMessage: The text that was output to the chatbox
  • theElement: Player element if chatbox output was done via say, teamsay or me. Resource if it was done via outputChatBox.

function onChatMessage ( _, theElement ) 
    if ( getElementType ( theElement ) ~= "player" ) then 
        cancelEvent ( ) 
    end 
end 
addEventHandler ( "onChatMessage", root, onChatMessage ) 

Posted
Please, next time read the wiki.
Parameters

string theMessage, resource / element theElement

  • theMessage: The text that was output to the chatbox
  • theElement: Player element if chatbox output was done via say, teamsay or me. Resource if it was done via outputChatBox.

function onChatMessage ( _, theElement ) 
    if ( getElementType ( theElement ) ~= "player" ) then 
        cancelEvent ( ) 
    end 
end 
addEventHandler ( "onChatMessage", root, onChatMessage ) 

I actually got it, thanks for the help but it's still that "onChatMessage" is done in server, and it does not cancel the client outputchatbox, or maybe because of some other reason.

At least i finished by preventing most of the spam by just adding this:

addEventHandler("onClientChatMessage",root, 
function (msg) 
if msg == "" or msg:find('www.',1,true) then     
cancelEvent(true) 
end 
end 
) 

So It's enough for me, there is no spam or pub, but the mapper can still use outputchatbox to comment his map.

Thank to all who helped me in this thread.

Posted

You're welcome. If you want cancel message all maps, you can use:

if getResourceInfo(res, "type") == "map" then 
    cancelEvent() 
end 

Server-side only.

Posted
You're welcome. If you want cancel message all maps, you can use:
if getResourceInfo(res, "type") == "map" then 
    cancelEvent() 
end 

Server-side only.

Well, wtf is wrong with this then? Crashed my script.

addEvent("onMapStarting",true) 
addEventHandler("onMapStarting",getRootElement(), 
function ( ) 
if getResourceInfo(res, "type") == "map" then 
    cancelEvent() 
end 
  

Posted
You're welcome. If you want cancel message all maps, you can use:
if getResourceInfo(res, "type") == "map" then 
    cancelEvent() 
end 

Server-side only.

Well, wtf is wrong with this then? Crashed my script.

addEvent("onMapStarting",true) 
addEventHandler("onMapStarting",getRootElement(), 
function ( ) 
if getResourceInfo(res, "type") == "map" then 
    cancelEvent() 
end 
  

You forgot ')' after condition.

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