Jump to content

[Solved] Disable outputChatBox


Recommended Posts

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
Link to comment
Not tested:
function preventSpam(message, element) 
    if not (getElementType(element) == "player") then 
        cancelEvent() 
    end 
end 
addEventHandler("onChatMessage", getRootElement(), preventSpam) 

makes no sense.

Why? :)

Link to comment

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

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

Link to comment
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 :/

Link to comment

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 ) 
  
  

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

Link to comment
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"

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

Link to comment

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 ) 

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

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

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

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