Jump to content

Chat mute


Recommended Posts

Hey, I started on a new chatmute script and it seems to have errors, I know there are errors in the script because of the debugscript which says:

ERROR: Loading script failed: localmute\client.lua:5: '' expected near 'end' 

I can't get it to work (I know that there are alot of mistakes)

    function chatdis(command) 
        cancelEvent() 
        outputChatBox("#E3E8B7The chat has been disabled by (localPlayerName)",source,255,0,0) 
        addEventHandler("onPlayerChat",getRootElement(),chatdis) 
end end 
    end 
) 
  
function chaten(command) 
        outputChatBox("#E3E8B7The chat has been enabled by (localPlayerName)",getRootElement(),255,0,0) 
        removeEventHandler("onPlayerChat",getRootElement(),chatdis) 
        end 
    ) 
) 
addCommandHandler("myname", 
  function() 
   local localPlayerName = getPlayerName(getLocalPlayer()) 
  end 
) 
  
addCommandHandler("chatoff",chatdis) 
addCommandHandler("chaton",chaten) 
  
  

Can you correct me?

Thanks :fadein:

Link to comment

You had all sorts of errors...

function chatdis( ) 
    cancelEvent() 
    outputChatBox("#E3E8B7The chat has been disabled by (localPlayerName)",source,255,0,0) 
    addEventHandler("onPlayerChat",getRootElement(),chatdis) 
end 
  
function chaten( ) 
    outputChatBox("#E3E8B7The chat has been enabled by (localPlayerName)",getRootElement(),255,0,0) 
    removeEventHandler("onPlayerChat",getRootElement(),chatdis) 
end 
  
     
addCommandHandler("myname", function() 
    local localPlayerName = getPlayerName(getLocalPlayer()) 
end ) 
addCommandHandler("chatoff",chatdis) 
addCommandHandler("chaton",chaten) 

Link to comment
local chat = true 
  
function chatDis(thePlayer) 
    outputChatBox("#E3E8B7The chat has been disabled by "..getPlayerName(thePlayer)..".",root,255, 255, 255, true) 
    chat = false 
end 
addCommandHandler("chatoff", chatDis) 
  
function chatEn(thePlayer) 
    outputChatBox("#E3E8B7The chat has been enabled by "..getPlayerName(thePlayer)..".",root,255, 255, 255, true) 
    chat = true 
end 
addCommandHandler("chaton",chatEn) 
  
function onChat() 
    if (chat == false) then 
    cancelEvent() 
end 
end 
addEventHandler("onPlayerChat", root, onChat) 

I'm not sure if this is gonna work, but give it a try..

Serversided.

Link to comment
local chat = true 
  
function chatDis(thePlayer) 
    outputChatBox("#E3E8B7The chat has been disabled by "..getPlayerName(thePlayer)..".",root,255, 255, 255, true) 
    chat = false 
end 
addCommandHandler("chatoff", chatDis) 
  
function chatEn(thePlayer) 
    outputChatBox("#E3E8B7The chat has been enabled by "..getPlayerName(thePlayer)..".",root,255, 255, 255, true) 
    chat = true 
end 
addCommandHandler("chaton",chatEn) 
  
function onChat() 
    if (chat == false) then 
    cancelEvent() 
end 
end 
addEventHandler("onPlayerChat", root, onChat) 

I'm not sure if this is gonna work, but give it a try..

Serversided.

Thanks that works perfectly.

Do you know how to make teamchat allowed? but the main chat disabled

Also, only admins can /chaton /chatoff, not everyone.

thanks again

Link to comment
local chat = true 
  
function chatDis(thePlayer) 
   local accName = getAccountName(getPlayerAccount(thePlayer)) 
     if isObjectInACLGroup("user."..accName, aclGetGroup("Admin")) then 
    outputChatBox("#E3E8B7The chat has been disabled by "..getPlayerName(thePlayer)..".",root,255, 255, 255, true) 
    chat = false 
end 
end 
addCommandHandler("chatoff", chatDis) 
  
function chatEn(thePlayer) 
   local accName = getAccountName(getPlayerAccount(thePlayer)) 
     if isObjectInACLGroup("user."..accName, aclGetGroup("Admin")) then 
    outputChatBox("#E3E8B7The chat has been enabled by "..getPlayerName(thePlayer)..".",root,255, 255, 255, true) 
    chat = true 
end 
end 
addCommandHandler("chaton",chatEn) 
  
function onChat(msg, msgType) 
    if (chat == false) and (msgType == 0) then 
    cancelEvent() 
end 
end 
addEventHandler("onPlayerChat", root, onChat) 

Link to comment
  • Moderators
@ Samer, why output to root when a loop is much more efficient? root can be tens of thousands of elements, but looping through players is so much more efficient.

Where do you see Samer? O_o

Root is more efficient, since it only can be send to players.

A loop will call the outputChatBox function over and over, which uses much more memory.

You can test that with getTickCount(), if you don't believe me.

Link to comment
@ Samer, why output to root when a loop is much more efficient? root can be tens of thousands of elements, but looping through players is so much more efficient.

Where do you see Samer? O_o

abxf is Samer.

I never knew that root outputs to players... I'll have to test this myself lol damn.

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