SHy^

  • Jr. Member
  • Don't dare to mess
  • Posts: 87
Mute System with timers
«  »Last edited
Well, just learned table today so thought to make a something so I decided to make mute system, tested it and sharing it with 0 errors as I tested. ;D

(click to show/hide)

In top of script:
Code: [Select]
mute <- {};

onPlayerJoin:
Code: [Select]
mute.rawset( player.ID, {} );

onPlayerChat:
Code: [Select]
if ( mute.rawget(player.ID).rawin("muted") ) return MessagePlayer("[#ff0000]Error! You're muted, wait mute to expire.", player);

onPlayerPart:
Code: [Select]
if ( mute.rawget(player.ID).rawin("muted")) mute.rawget(playerr.ID).rawdelete("muted");

Function:
Code: [Select]
function Unmute(p)
{
local plr = FindPlayer(p);
if ( plr && mute.rawget(plr.ID).rawin("muted"))
{
mute.rawget(plr.ID).rawdelete("muted");
Message(format("Automuted %s Reason: Mute time expired!", plr.Name));
}
}

onPlayerCommand:
Code: [Select]
if ( cmd == "mute")
{
if (!text) return MessagePlayer("Error - use /mute <player> <min:sec> <reason>.", player);
else
{
         local plr = GetPlayer( GetTok(text, " ", 1));
         local tym =  GetTok(text, " ", 2);
         local reason = GetTok(text, " ", 3, NumTok(text, " "));
if ( !plr) return MessagePlayer("Error - unknown plr.", player);
else if (!tym) return MessagePlayer("Error - use /mute <player> <sec> <reason>.", player);
else if (!reason) return MessagePlayer("Error - use /mute <player> <sec> <reason>.", player);
else if ( !IsNum(tym)) return MessagePlayer("Input secs as integer or float, noob.", player);
else if ( tym.tointeger() < 15 ) return MessagePlayer("Error! Minimum secs are 15.", player);
else if ( mute.rawget(plr.ID).rawin("muted") ) return MessagePlayer("Error! Requested plr already muted.", player);
else
{
         mute.rawget(plr.ID).rawset("muted", true);
UnmuteTimer <-  NewTimer("Unmute", tym.tointeger()*1000, 1, plr.ID);
Message("Admin "+player.Name+" muted "+plr.Name+" Time: "+tym.tointeger()+" seconds, Reason added: "+reason+"");
}
}
}
else if ( cmd == "unmute")
{
if (!text) return MessagePlayer("Error - use /unmute <player> .", player);
else
{
local plr = FindPlayer(text);
if (!plr) return MessagePlayer("Error - unknown plr.", player);
else if ( !mute.rawget(plr.ID).rawin("muted")) return MessagePlayer("Error! requested plr not muted.", player);
else
{
            mute.rawget(plr.ID).rawdelete("muted");
UnmuteTimer.Stop();
Message(format("Admin %s unmuted %s", player.Name, plr.Name));
}
}
}

If you find any bug from somewhere, report it to me in PM and I'll try to fix it immediately. ::)

Note: Due to lack of time, I didn't add GetTok, NumTok & GetPlayer functions. Search on the forum & you'll find it.