h4x7o0r Posted January 19, 2014 Share Posted January 19, 2014 Hey there , i was wondering how can i mute a certain player from using only the public chat (lets say global) and as long as he's muted to let him use the teamchat ? Link to comment
Bonsai Posted January 19, 2014 Share Posted January 19, 2014 https://wiki.multitheftauto.com/wiki/OnPlayerChat messageType: An integer value representing the message type: 0: normal message 1: action message (/me) 2: team message if normal message and source = muted guy cancelEvent() Link to comment
h4x7o0r Posted January 20, 2014 Author Share Posted January 20, 2014 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
'LinKin Posted January 20, 2014 Share Posted January 20, 2014 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
xXMADEXx Posted January 20, 2014 Share Posted January 20, 2014 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
h4x7o0r Posted January 21, 2014 Author Share Posted January 21, 2014 Thanks linkin, not working atm. Thanks xXMADEXx, your code's partially working like when I mute someone it's also muting me and by execute again the command does not unmuting. Thanks for your help guys. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now