Jump to content

[HELP] Voice Chat player muting


DreaM40BG

Recommended Posts

Is it possible to mute anybody from voice? I mean like in the chat and he can't talk? And how do it?
with "mutevoice"  it mutes only for me..
 
Тoday I have birthday and I want to fix some things in my server, that's why I am writing here ? 
Edited by DreaM40BG
Link to comment
  • Moderators

Hi, It's possible.
If you are using voice resource, the function is available by default, you just need to add the commands.

Open the voice/sPlayerMuting.Lua and paste these commands to the end of the file:

addCommandHandler("voicemute", function(player, cmd, targetname)
	-- some admin right check ...

	local target = getPlayerFromPartialName(targetname)
	if not target then return outputChatBox("[VOICEMUTE] * Player not found! ("..targetname..")", player) end
	
	setPlayerVoiceMuted(target, true)
	outputChatBox("[VOICEMUTE] * Player muted! ("..targetname..")", player)
end)

addCommandHandler("voiceunmute", function(player, cmd, targetname)
	-- some admin right check ...
	
	local target = getPlayerFromPartialName(targetname)
	if not target then return outputChatBox("[VOICEMUTE] * Player not found! ("..targetname..")", player) end
	
	setPlayerVoiceMuted(target, false)
	outputChatBox("[VOICEMUTE] * Player unmuted! ("..targetname..")", player)
end)

-- https://wiki.multitheftauto.com/wiki/GetPlayerFromPartialName
function getPlayerFromPartialName(name)
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil
    if name then
        for _, player in ipairs(getElementsByType("player")) do
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower()
            if name_:find(name, 1, true) then
                return player
            end
        end
    end
end

* You need to complete the code with admin rights check.

Edited by Patrick
  • Like 1
Link to comment

Doesn't work.

From line 68 till end.

if isVoiceEnabled() then
	function setPlayerVoiceMuted ( player, muted )
		if not checkValidPlayer ( player ) then return false end
		muted = not not muted or nil
		globalMuted[player] = muted
		return setPlayerVoiceBroadcastTo ( player, (not muted) and root or nil )
	end

	function isPlayerVoiceMuted ( player )
		if not checkValidPlayer ( player ) then return false end
		return not not globalMuted[player]
	end

	--Returns a list of players of which have muted the specified player
	function getPlayerVoiceMutedByList ( player )
		if not checkValidPlayer ( player ) then return false end
		return tableToArray(mutedBy[player] or {})
	end

	function updateMuted ( player )
		setPlayerVoiceIgnoreFrom ( player, getPlayerVoiceMutedByList ( player ) )
	end


	function addPlayerMutedBy ()
		mutedBy[client] = mutedBy[client] or {}
		mutedBy[client][source] = true
		updateMuted ( client )
	end
	addEventHandler ( "voice_mutePlayerForPlayer", root, addPlayerMutedBy )

	function removePlayerMutedBy ()
		if mutedBy[client] then
			mutedBy[client][source] = nil
			--Refresh the player
			updateMuted ( client )
		end
	end
	addEventHandler ( "voice_unmutePlayerForPlayer", root, removePlayerMutedBy )

	function addPlayerMutedByTable (players) --Single packet for multiple muted players
		for i,player in ipairs(players) do
			source = player
			addPlayerMutedBy()
		end
	end
	addEventHandler ( "voice_muteTableForPlayer", root, addPlayerMutedByTable )

	addEventHandler ( "onPlayerQuit", root,
		function()
			mutedBy[source] = nil
			globalMuted[source] = nil
		end
	)
else
	setPlayerVoiceMuted = outputVoiceNotLoaded
	isPlayerVoiceMuted = outputVoiceNotLoaded
	getPlayerVoiceMutedByList = outputVoiceNotLoaded
end

-- Functions for backward compatibility only
-- DO NOT USE THESE AS THEY WILL BE REMOVED IN A LITTLE WHILE --
function isPlayerMuted ( player )			return isPlayerVoiceMuted ( player ) end
function setPlayerMuted ( player, muted )	return setPlayerVoiceMuted ( player, muted ) end
function getPlayerMutedByList ( player )	return getPlayerVoiceMutedByList ( player ) end
-- DO NOT USE THESE AS THEY WILL BE REMOVED IN A LITTLE WHILE --

addCommandHandler("vmute", function(player, cmd, targetname)
    local accName = getAccountName ( getPlayerAccount ( thePlayer ) )
     if isObjectInACLGroup ("user."..accName, aclGetGroup ( "ChatControl" ) ) then
	local target = getPlayerFromPartialName(targetname)
	if not target then return outputChatBox("[VOICEMUTE] * Player not found! ("..targetname..")", player) end
	
	setPlayerVoiceMuted(target, true)
	outputChatBox("[VOICEMUTE] * Player muted! ("..targetname..")", player)
end)

addCommandHandler("vunmute", function(player, cmd, targetname)
    local accName = getAccountName ( getPlayerAccount ( thePlayer ) )
     if isObjectInACLGroup ("user."..accName, aclGetGroup ( "ChatControl" ) ) then
	local target = getPlayerFromPartialName(targetname)
	if not target then return outputChatBox("[VOICEMUTE] * Player not found! ("..targetname..")", player) end
	
	setPlayerVoiceMuted(target, false)
	outputChatBox("[VOICEMUTE] * Player unmuted! ("..targetname..")", player)
end)

-- https://wiki.multitheftauto.com/wiki/GetPlayerFromPartialName
function getPlayerFromPartialName(name)
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil
    if name then
        for _, player in ipairs(getElementsByType("player")) do
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower()
            if name_:find(name, 1, true) then
                return player
            end
        end
    end
end

 

Link to comment
  • Moderators
6 minutes ago, DreaM40BG said:

Doesn't work.

From line 68 till end.

Please learn Lua basics before you ask in this section, it's indispensable!

etRJ9VH.png

 

Some Lua tutorial for beginners:
https://forum.multitheftauto.com/topic/121619-Lua-for-absolute-beginners
https://forum.multitheftauto.com/topic/64228-the-ultimate-Lua-tutorial/
https://forum.multitheftauto.com/topic/95654-tut-debugging/

 

  • Like 1
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...