turbodymacz1337 Posted July 21, 2019 Share Posted July 21, 2019 I got a code that mutes main chat for all players in server, I want to make it using a command and mute a player from using main chat, not all players.. local chat = true function chatDis(thePlayer) local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then outputChatBox("#ff0000Main 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("#ff0000Main chat has been enabled by "..getPlayerName(thePlayer)..".",root,255, 255, 255, true) chat = true end end addCommandHandler("chaton", chatEn) function onChat ( _, messageType ) if ( messageType == 0 and not chat ) then cancelEvent ( ) end end addEventHandler ( "onPlayerChat", root, onChat ) Link to comment
Scripting Moderators thisdp Posted July 21, 2019 Scripting Moderators Share Posted July 21, 2019 use a table or setElementData to record who was muted. before canceling event, check whether the source player is muted. Link to comment
Ceeser Posted July 21, 2019 Share Posted July 21, 2019 (edited) Add these utility functions: function isPlayerAllowed(uPlayer, strRank) if (not strRank) then strRank = "Admin"; end local strAccName = getAccountName(getPlayerAccount(uSource)); if (isObjectInACLGroup("user."..strAccName, aclGetGroup(strRank))) then return true; end return false; end 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 Ok.. this is for a temporary mute: Until unmute or reconnect. But it will stay in case of script restart. function onChat(_, messageType) if (messageType == 0 and getElementData(source, "chatMute")) then cancelEvent(); end end addEventHandler("onPlayerChat", root, onChat); function muteChatForPlayer(uSource, _, strPlayerName, bState) if (not isPlayerAllowed(uSource)) then -- output uSource error: no permissions end if (not bState) then bState = nil; else bState = (bState == "true") and true or nil; end local uPlayer = getPlayerFromPartialName(strPlayerName); if (uPlayer) then setElementData(uPlayer, "chatMute", bState); if (bState) then -- output uSource that uPlayer got muted -- output uPlayer that he got muted else -- output uSource that uPlayer got unmuted -- output uPlayer that he got unmuted end end end addCommandHandler("chatmute", muteChatForPlayer); This one is "permanent": Until unmute or script restart. In this case a reconnect wont help to get unmuted. local tblMutedPlayers = {}; function onChat(_, messageType) if (messageType == 0) then local strSerial = getPlayerSerial(uPlayer); if (tblMutedPlayers[strSerial]) then cancelEvent(); -- output source "you are muted" end end end addEventHandler("onPlayerChat", root, onChat); function muteChatForPlayer(uSource, _, strPlayerName, bState) if (not isPlayerAllowed(uSource)) then -- output uSource error: no permissions end if (not bState) then bState = nil; else bState = (bState == "true") and true or nil; end local uPlayer = getPlayerFromPartialName(strPlayerName); if (uPlayer) then local strSerial = getPlayerSerial(uPlayer); tblMutedPlayers[strSerial] = bState; if (bState) then -- output uSource that uPlayer got muted -- output uPlayer that he got muted else -- output uSource that uPlayer got unmuted -- output uPlayer that he got unmuted end end end addCommandHandler("chatmute", muteChatForPlayer); Edited July 21, 2019 by Ceeser 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