Jump to content

mute chat but allowed teamchat


h4x7o0r

Recommended Posts

Oh Thanks Bonsai for those guiding lines, tried something but i don't think will manage to do it myself.

  
addEventHandler('onPlayerChat', root, 
    function( message, messageType ) 
    local tipu = getPlayerFromName ( source ) 
    local echipa = getPlayerTeam (source) 
       if isPlayerMuted (tipu) then 
          if messageType == 0  then 
       outputChatBox("You are muted on Public chat. You can still use TeamChat.",tipu) 
       cancelEvent() 
          elseif messageType == 2 then 
        outputChatBox(": #FFFFFF"..message, echipa, red, green, blue, true ) 
          end 
       end 
    end 
) 
  
function mutePlayer(player,command,victimName) 
    -- if the player has specified a victim name to mute 
    if victimName then 
        -- get the victim player element from their name 
        local tipu = getPlayerFromName(victimName) 
        -- if the player exists 
        if tipu then 
            -- if they arent already muted 
            if ( not isPlayerMuted(tipu) ) then 
                -- mute them and output a message to the chat 
                setPlayerMuted(tipu, true) 
                outputChatBox("You have been muted.",tipu) 
            end 
        else 
            outputChatBox("Could not find player with name: "..tostring(victimName),player) 
        end 
    else 
        outputChatBox("Usage: /pmute <player name>",player) 
    end 
end 
  
addCommandHandler("pmute",mutePlayer) 
  

Any help is appreciated.

Link to comment

No I think you must not use 'isPlayerMuted' 'setPlayerMuted' aren't they the default functions from MTA?

Look do this:

On the function that /pmute triggers, play with "setElementData" and "getElementData"

For example; setElementData(tipu,"muteOnMain",true)

And in the function handled by onPlayerChat, use getElementData(tipu, "muteOnMain"), it will return true if he's muted.

then cancelEvent()

EDIT:

function mutePlayer(thePlayer, theCommand, theTarget)

local toPlayer = getPlayerFromName(theTarget)

if getElementData(toPlayer, "mutedOnMain") == false then

setElementData(toPlayer, "mutedOnMain", true)

elseif getElementData(toPlayer, "mutedOnMain") == true then

setElementData(toPlayer, "mutedOnMain", false)

end

end

addCommandHan.....mutePlayer)

function playerChat(message, messageType)

if getElementData(source, "muteOnMain") == true then

if messageType ~= 2 then

cancelEvent()

outputChatBox ( "You are muted in public chat", source, 255, 255, 255, true )

end

end

end

addEventHand..."onPlayerChat")

So yeah Gibril, you must toggle the function mutePlayer using the same command.

And well, now you've got the general look of it, You can add details as you wish.

Link to comment
No I think you must not use 'isPlayerMuted' 'setPlayerMuted' aren't they the default functions from MTA?

Look do this:

On the function that /pmute triggers, play with "setElementData" and "getElementData"

For example; setElementData(tipu,"muteOnMain",true)

And in the function handled by onPlayerChat, use getElementData(tipu, "muteOnMain"), it will return true if he's muted.

then cancelEvent()

EDIT:

function mutePlayer(thePlayer, theCommand, theTarget)

local toPlayer = getPlayerFromName(theTarget)

if getElementData(toPlayer, "mutedOnMain") == false then

setElementData(toPlayer, "mutedOnMain", true)

elseif getElementData(toPlayer, "mutedOnMain") == true then

setElementData(toPlayer, "mutedOnMain", false)

end

end

addCommandHan.....mutePlayer)

function playerChat(message, messageType)

if getElementData(source, "muteOnMain") == true then

if messageType ~= 2 then

cancelEvent()

outputChatBox ( "You are muted in public chat", source, 255, 255, 255, true )

end

end

end

addEventHand..."onPlayerChat")

So yeah Gibril, you must toggle the function mutePlayer using the same command.

And well, now you've got the general look of it, You can add details as you wish.

isPlayerMuted and setplayerMuted are default functions....

((Not Tested))

addEventHandler('onPlayerChat', root, function( message, messageType ) 
    local echipa = getPlayerTeam (source) 
    if messageType == 0 and isPlayerMuted ( source )  then 
        outputChatBox("You are muted on Public chat. You can still use TeamChat.",source) 
    elseif messageType == 2 then 
        if ( echipa ) then 
            local r, g, b = getTeamColor ( echipa ) 
            for k, p in ipairs ( getPlayersInTeam ( echipa ) ) do  
                outputChatBox(getPlayerName ( source )": #FFFFFF"..message, p, r, g, b, true ) 
            end 
        end 
    end 
    cancelEvent( ) 
end ) 
  
function mutePlayer(player,command,victimName) 
    if victimName then 
        local tipu = getPlayerFromName(victimName) 
        if tipu then 
            if ( not isPlayerMuted(tipu) ) then 
                setPlayerMuted(tipu, true) 
                outputChatBox("You have been muted.",tipu) 
            end 
        else 
            outputChatBox("Could not find player with name: "..tostring(victimName),player) 
        end 
    else 
        outputChatBox("Usage: /pmute ",player) 
    end 
end 
addCommandHandler("pmute",mutePlayer) 

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