Jump to content

Muting script


megaman54

Recommended Posts

I'm making a mute script wich is different than the default one. It should work like this: i type /smute and it mutes that player without using the setPlayerMuted function. I want to make it like that no-one can see when someone gets muted and when the muted player tries to speak, he wont get the "you are muted" message. So, here is my problem: i must store the muted player names in a table, but i dont know how to check if the name is in the table. Here is what i have done so far:

muted = {} 
  
function silentMute() 
  

I know it isnt much but thats all i can do by myself. I'm a very noob with tables...

I hope someone can help me with this.

Link to comment

Hmmm, Maybe you should go check out the wiki, But heres what you wanted...

function muteOurPlayer(player, command, mutedguy, time, reason) 
    if mutedguy and time and reason then 
         
        local muted = getPlayerFromName(mutedguy) 
         
        if muted then 
             
            if( not isPlayerMuted(muted) ) then 
                 
                    setPlayerMuted(muted, true) 
                    outputChatBox(..getPlayerName(muted).." has been muted for "..time.." minutes. (Reason: "..reason.."#FF0000 )", getRootElement(), 255, 0, 0, true) 
                    setElementData(muted, "Muted", 1) 
                    setElementData(muted, "MutedTime", time) 
                    setElementData(muted, "Reason", reason) 
            end 
        end 
    else  
            outputChatBox("Mute command: /mute ", player) 
    end 
end 
addCommandHandler("mute", muteOurPlayer) 

Link to comment

To check, you'll need a loop:

function checkPlayerMuted ( thePlayer ) 
  for k, player in ipairs(muted) do 
    if player == thePlayer then 
      return true 
    end 
  end 
  return false 
end 

To disable the chat (=muted), cancel the onPlayerChat event if the player is in the table:

function checkMute ( ) 
  local player = source 
  if checkPlayerMuted ( player ) then 
    cancelEvent() 
  end 
end 
addEventHandler("onPlayerChat", root, checkMute) 

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