Jump to content

Chat mute


Recommended Posts

Posted

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:

Posted

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) 

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

Posted
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

Posted
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) 

Posted

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

  • Moderators
Posted
@ 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.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

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

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