#include <sscanf2> // include the sscanf file
#include <zcmd> // include the zcmd file
new Mute[MAX_PLAYERS]; // global variable to check if a player is muted
forward SecondTimer(); // timer that we will be using that will tick second-by-second
public OnGameModeInit()
{
SetTimer("SecondTimer", 1000, true); // this will initiate the timer
return 1; // don't put this line if you've already got return 1 at the bottom of your OnGameModeInit
}
public SecondTimer()
{
for(new i = 0; i < MAX_PLAYERS; i ++) // loops all the players
{
if(IsPlayerConnected(i)) // will check if the player is connected
{
if(Mute[i] >= 1) // will check if their mute time is equal or above to 1
{
Mute[i] --; // if it is, then it will minus the mute time by 1 second
}
}
}
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
if(Mute[playerid] >= 1) // will check if the player was muted
{
new mutename[MAX_PLAYER_NAME], string[100]; // creates a few new public variables
GetPlayerName(playerid, mutename, sizeof(mutename)); // retrieve the player name
format(string, sizeof(string), "%s just left the game with a remaining mute time of %d seconds", mutename, Mute[playerid]); // will set the string that we'll use
for(new i = 0; i <= MAX_PLAYERS; i ++) // again, loops all the players
{
if(IsPlayerConnected(i) && IsPlayerAdmin(i)) // check if the player is connected and if they're an RCON admin
{
SendClientMessage(i, 0xAFAFAFFF, string); // send the message to the player
}
}
}
Mute[playerid] = 0; // this will reset the mute time, so the next person that logs in with the same ID won't suffer a mute
return 1; // don't add this line if you've already got it at the bottom of your OnPlayerDisconnect
}
OnPlayerText(playerid, text[])
{
if(Mute[playerid] >= 1) // check if the player is muted
{
new string[50]; // creates a new variable
format(string, sizeof(string), "You're muted for another %d seconds.", Mute[playerid]); // sets the string
SendClientMessage(playerid, 0xFFFFFFFF, string); // sends the message
return 0; // this is crucial, by returning 0 here it will stop the player from being able to talk
}
return 1; // don't put this here if you've already got it at the bottom of your OnPlayerText.
}
CMD:mute(playerid, params[])
{
if(!IsPlayerAdmin(playerid)) return 0; // returns "SERVER: Unknown command." if the player is not an RCON admin
new giveplayerid, reason[50], string[120], minutes, pname1[MAX_PLAYER_NAME], pname2[MAX_PLAYER_NAME]; // declares a few new variables
if(sscanf(params, "uds[50]", giveplayerid, minutes, reason)) return SendClientMessage(playerid, 0xFFFFFFFF, "Correct usage: /mute [playerid/name] [time in minutes] [reason]"); // returns this message if the player typed an incorrect syntax
if(giveplayerid == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFFFFFFFF, "Player not connected."); // returns this message if the receiver player is not connected
GetPlayerName(playerid, pname1, sizeof(pname1)); // get the sender name
GetPlayerName(giveplayerid, pname2, sizeof(pname2)); // get the receiver name
format(string, sizeof(string), "%s (%d) was muted for %d minutes by admin %s (%d), reason: %s", pname2, giveplayerid, minutes, pname1, playerid, reason); // sets the string
SendClientMessageToAll(0xFFFFFFFF, string); // sends a global message
new calc = minutes*60; // calculates the seconds
Mute[giveplayerid] = calc; // sets the mute time to the calculated value
GameTextForPlayer(giveplayerid, "~r~muted~n~~w~check the chat", 5000, 6); // 5 second game text for the receiver that got the mute informing him to check the chat for information about the mute
return 1;
}
CMD:unmute(playerid, params[])
{
if(!IsPlayerAdmin(playerid)) return 0;
new giveplayerid, reason[50], string[120]; // variables
if(sscanf(params, "us[50]", giveplayerid, reason)) return SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}Syntax: /unmute [playerid/name] [reason]"); // syntax check
if(giveplayerid == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}Player not connected."); // player not connected
new pname1[MAX_PLAYER_NAME], pname2[MAX_PLAYER_NAME]; // more variables
GetPlayerName(playerid, pname1, sizeof(pname1)); // gets the senders name
GetPlayerName(giveplayerid, pname2, sizeof(pname2)); // gets the receivers name
format(string, sizeof(string), "%s (%d) was unmuted by %s (%d), reason: %s", pname2, giveplayerid, pname1, playerid, reason); // sets the string
SendClientMessageToAll(0xFFFFFFFF, string); // sends everyone the message that was string'd
Mute[giveplayerid] = 0; // sets the mute of the other player to 0
GameTextForPlayer(giveplayerid, "~g~unmuted~n~~w~check the chat", 5000, 6); // game text for the other player informing them that his mute has been taken off him
return 1;
}
CMD:mymute(playerid, params[])
{
if(Mute[playerid] <= 0) return SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}You're not muted at the moment."); // checks if the player is muted, if not, it will return that message
new string[50]; // new variable
SendClientMessage(playerid, 0xFFFFFFFF, "|__________ My Mute __________|"); // sends a base message
format(string, sizeof(string), "%d seconds remain from your mute.", Mute[playerid]); // sets the string
SendClientMessage(playerid, 0xFFFFFFFF, string); // sends the string'd message
return 1;
}
CMD:mutelist(playerid, params[])
{
new iname[MAX_PLAYER_NAME], string[120], count; // new variables
for(new i = 0; i < MAX_PLAYERS; i++) // loops all the players
{
if(IsPlayerConnected(i)) // checks if the player is connected
{
if(Mute[i] >= 1) // checks if the looped player is muted at the moment
{
GetPlayerName(i, iname, sizeof(iname)); // if they are, this retrieves the name
format(string, sizeof(string), "%s (%d) - %d seconds remaining", iname, i, Mute[i]); // sets the string
SendClientMessage(playerid, 0xFFFFFFFF, string); // sends the message
count++; // puts the count to a ++ value, you'll see why further down
}
}
}
if(count == 0) return SendClientMessage(playerid, 0xFFFFFFFF, "There are no muted players online."); // if there are no muted players online, it'll return this message
if(count == 1) return SendClientMessage(playerid, 0xFFFFFFFF, "There is 1 player who is muted online."); // if there's just 1 muted player online, it'll returns this message
if(count >= 2) // if there are more than 1 muted players online, the following will occur
{
format(string, sizeof(string), "There are %d amount of players who are online and muted.", count); // sets the string
SendClientMessage(playerid, 0xFFFFFFFF, string); // sends the message
}
return 1;
}
CMD:unmuteall(playerid, params[])
{
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}Only admins can use this command."); // checks if the sender is an RCON logged in admin
new count, string[120]; // new variables
for(new i = 0; i < MAX_PLAYERS; i++) // loops all the players one-by-one
{
if(IsPlayerConnected(i)) // checks if the player is connected
{
if(Mute[i] >= 1) // if the looped player has a mute time more than 0
{
count++; // the count will go up
Mute[i] = 0; // and the mute time will be set to 0
}
}
}
new uname[MAX_PLAYER_NAME]; // this is the name of the sender
GetPlayerName(playerid, uname, sizeof(uname)); // this will get the playerid (sender)'s name
format(string, sizeof(string), "%d players have been admin-unmuted by %s (%d)", count, uname, playerid); // sets the string to say how many players were unmuted and by who
SendClientMessageToAll(0xFFFFFFFF, string); // sends this global message
return 1;
}
CMD:mutecmds(playerid, params[])
{
SendClientMessage(playerid, 0xFFFFFFFF, "/mute - Mute a player");
SendClientMessage(playerid, 0xFFFFFFFF, "/unmute - Unmute a player");
SendClientMessage(playerid, 0xFFFFFFFF, "/mymute - View your own mute time");
SendClientMessage(playerid, 0xFFFFFFFF, "/mutelist - View a global list of all the online players who are muted");
SendClientMessage(playerid, 0xFFFFFFFF, "/unmuteall - Unmute all the players on the server at once");
return 1;
}
pawn Code:
|
switch(count)
{
case 0:
{
SendClientMessage(playerid, 0xFFFFFFFF, "There are no muted players online."); // if there are no muted players online, it'll return this message
return 1;
}
case 1:
{
SendClientMessage(playerid, 0xFFFFFFFF, "There is 1 player who is muted online."); // if there's just 1 muted player online, it'll returns this message
return 1;
}
default:
{
format(string, sizeof(string), "There are %d amount of players who are online and muted.", count); // sets the string
SendClientMessage(playerid, 0xFFFFFFFF, string); // sends the message
return 1;
}
}
Hello Danish,
so for me I'll just suggest you something like if he disconect to the servers when he was muted, when he will come back he will be automatically muted back. (it's possible). Anyways nicely explained. |