Hello, I would like to ask how to make this code below saving a player mute after reconnect.
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
function mmute ( message, messageType )
if ( getElementData ( source, "isPlayerMuted" ) ) == true then
if (messageType == 0) or (messageType == 1) then
cancelEvent()
end
end
end
-- attach it as a handler to onPlayerChat
addEventHandler( "onPlayerChat", getRootElement(), mmute )
function muteCommand ( thePlayer , command , source )
local mutedPlayer = getPlayerFromPartialName ( source )
local source = mutedPlayer
local muteData = getElementData( source, "isPlayerMuted" )
if ( hasObjectPermissionTo ( thePlayer, "function.setPlayerMuted", true ) ) then
if ( mutedPlayer ) then
if ( muteData == false ) then
if getElementType ( mutedPlayer ) == "player" then
setElementData ( source, "isPlayerMuted", true )
outputChatBox ( getPlayerName(source).. "#ff0000 has been mainchat muted by " .. getPlayerName(thePlayer) , root, 255, 0, 0, true )
end
else
outputChatBox ( "Player is already muted!", thePlayer, 255, 0, 0, true )
end
elseif not mutedPlayer then
outputChatBox ( "Mute a player from main chat by writing /mmute [part of the player name]", thePlayer, 255, 0, 0 ) -- Tell the player the proper syntax
end
else
outputChatBox ( "You can't do that!", thePlayer, 255, 0, 0, true )
end
end
addCommandHandler ( "mmute" , muteCommand )
function unmuteCommand ( thePlayer, command, source )
local mutedPlayer = getPlayerFromPartialName ( source )
local source = mutedPlayer
local muteData = getElementData( source, "isPlayerMuted" )
if ( hasObjectPermissionTo ( thePlayer, "function.setPlayerMuted", true ) ) then
if ( mutedPlayer ) then
if ( muteData == true ) then
if getElementType ( mutedPlayer ) == "player" then
setElementData ( source, "isPlayerMuted", false )
outputChatBox ( getPlayerName(source).. "#00ff00 has been mainchat unmuted by " .. getPlayerName(thePlayer) , root, 0, 255, 0, true )
end
else
outputChatBox ( "Player is not muted!", thePlayer, 255, 0, 0, true )
end
elseif not mutedPlayer then
outputChatBox ( "Unmute a player from main chat by typing /unmmute [part of the player name]", thePlayer, 255, 0, 0 ) -- Tell the player the proper syntax
end
else
outputChatBox ( "You can't do that!", thePlayer, 255, 0, 0, true )
end
end
addCommandHandler ("unmmute" , unmuteCommand )