Advertisement
DarkSkull

Advanced Mute System

Sep 17th, 2014
662
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 10.63 KB | None | 0 0
  1. #define FILTERSCRIPT
  2. // ==============================================
  3. //                  INCLUDES
  4. // ==============================================
  5.  
  6. #include <a_samp>
  7. #include <zcmd>
  8. #include <sscanf2>
  9. #include <YSI\y_ini>
  10.  
  11. // ----------------------------------------------
  12.  
  13. // ==============================================
  14. //               COLOR DEFINES
  15. // ==============================================
  16.  
  17. #define COLOR_RED 0xFF0000FF
  18. #define COLOR_YELLOW 0xFFFF00AA
  19. #define COLOR_LIGHTBLUE 0x33CCFFAA
  20. #define COLOR_TOMATO 0xFF6347AA
  21. #define COLOR_LAWNGREEN 0x7CFC00AA
  22. #define COLOR_LIMEGREEN 0x32CD32AA
  23.  
  24. // ----------------------------------------------
  25.  
  26. // ==============================================
  27. //               SYSTEM CONFIG
  28. // ==============================================
  29.  
  30. #define PATH "/AMS/%s.ini" // Path to save the data.
  31. #define MAX_WARNINGS 3    //  Maximum warning while speaking when muted.
  32. #define RANDOM_MSG_TIME 2 // Random messages interval (In Minutes).
  33.  
  34. // ----------------------------------------------
  35.  
  36. // ==============================================
  37. //                 PLAYER INFO
  38. // ==============================================
  39.  
  40. enum pInfo
  41. {
  42.     Muted,
  43.     MutedReason[128],
  44.     MuteWarnings,
  45.     SpamMute,
  46.     TotalMute
  47. }
  48. new PlayerInfo[MAX_PLAYERS][pInfo];
  49.  
  50. // -----------------------------------------------
  51.  
  52. // ===============================================
  53. //              RANDOM MESSAGES
  54. // ===============================================
  55.  
  56. new RandomMessages[][] =
  57. {
  58.        "*Use /minfo [playerid] to view players total mutes.",
  59.        "*Use /requestunmute to send unmute request to online admins.",
  60.        "*Use /mlist to view online muted players."
  61. };
  62.  
  63. forward SendRandomMessages();
  64. public SendRandomMessages()
  65. {
  66.      SendClientMessageToAll(COLOR_YELLOW, RandomMessages[random(sizeof(RandomMessages))]);
  67.      return 1;
  68. }
  69.  
  70. // -----------------------------------------------
  71.  
  72. // ===============================================
  73. //                CUSTOM FUNCTIONS
  74. // ===============================================
  75.  
  76. stock UserPath(playerid)
  77. {
  78.     new string[128],playername[MAX_PLAYER_NAME];
  79.     GetPlayerName(playerid,playername,sizeof(playername));
  80.     format(string,sizeof(string),PATH,playername);
  81.     return string;
  82. }
  83.  
  84. forward LoadUser_data(playerid,name[],value[]);
  85. public LoadUser_data(playerid,name[],value[])
  86. {
  87.     INI_Int("Muted",PlayerInfo[playerid][Muted]);
  88.     INI_String("MutedReason",PlayerInfo[playerid][MutedReason], 128);
  89.     INI_Int("MuteWarnings",PlayerInfo[playerid][MuteWarnings]);
  90.     INI_Int("SpamMute",PlayerInfo[playerid][SpamMute]);
  91.     INI_Int("TotalMute",PlayerInfo[playerid][TotalMute]);
  92.     return 1;
  93. }
  94.  
  95. forward KickDelay(playerid);
  96. public KickDelay(playerid)
  97. {
  98.     Kick(playerid);
  99. }
  100.  
  101. stock IsPlayerMuted(playerid) {
  102.     if (PlayerInfo[playerid][Muted] == 1 || PlayerInfo[playerid][SpamMute] == 1)
  103.         return true;
  104.     return false;
  105. }
  106.  
  107. stock IsAnyMutedPlayerOnline() {
  108.     new count;
  109.     for (new i=0; i < MAX_PLAYERS; i++) {
  110.         if (IsPlayerConnected(i) && IsPlayerMuted(i)) {
  111.             count++;
  112.         }
  113.     }
  114.    
  115.     if (count == 0) {
  116.         return false;
  117.     } else {
  118.         return true;
  119.     }
  120.  
  121. }
  122.  
  123. // ------------------------------------------------
  124.  
  125. public OnFilterScriptInit()
  126. {
  127.     print("\n--------------------------------------");
  128.     print(" Advanced Mute System by DarkSkull");
  129.     print("--------------------------------------\n");
  130.     SetTimer("SendRandomMessages",RANDOM_MSG_TIME*60000,1);
  131.     return 1;
  132. }
  133.  
  134. public OnFilterScriptExit()
  135. {
  136.     return 1;
  137. }
  138.  
  139. public OnPlayerText(playerid, text[])
  140. {
  141.     if (PlayerInfo[playerid][Muted] == 1){
  142.         PlayerInfo[playerid][MuteWarnings]++;
  143.         new msg1[128];
  144.         format(msg1, sizeof(msg1), "*You're Muted, You can't talk. (Warnings: %d/%d)", PlayerInfo[playerid][MuteWarnings], MAX_WARNINGS);
  145.         SendClientMessage(playerid, COLOR_YELLOW, msg1);
  146.         if (PlayerInfo[playerid][MuteWarnings] >= MAX_WARNINGS) {
  147.             new msg2[128], name[MAX_PLAYER_NAME];
  148.             SendClientMessage(playerid, COLOR_RED, "*You've been kicked due to Mute spamming!");
  149.             PlayerInfo[playerid][Muted] = 0;
  150.             PlayerInfo[playerid][MuteWarnings] = 0;
  151.             format(PlayerInfo[playerid][MutedReason], 128, "None");
  152.             SetTimerEx("KickDelay", 1000, false, "d", playerid);
  153.             GetPlayerName(playerid,name, sizeof(name));
  154.             format(msg2, sizeof(msg2), "[KICK]: %s has been kicked [Reason: Mute Spamming].", name);
  155.             SendClientMessageToAll(COLOR_YELLOW, msg2);
  156.         }
  157.         return 0;
  158.     }
  159.     return 1;
  160. }
  161.  
  162. public OnPlayerConnect(playerid)
  163. {
  164.     if(fexist(UserPath(playerid)))
  165.     {
  166.         INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
  167.     }
  168.     else
  169.     {
  170.         new INI:File = INI_Open(UserPath(playerid));
  171.         INI_SetTag(File,"data");
  172.         INI_WriteInt(File,"Muted",0);
  173.         INI_WriteString(File,"MutedReason", "None");
  174.         INI_WriteInt(File,"MuteWarnings",0);
  175.         INI_WriteInt(File,"SpamMute", 0);
  176.         INI_WriteInt(File,"TotalMute",0);
  177.         INI_Close(File);
  178.     }
  179.    
  180.     if (IsPlayerMuted(playerid)) {
  181.         new string[128];
  182.         SendClientMessage(playerid, COLOR_TOMATO, "*You have been muted since you last left the game.");
  183.         format(string, sizeof(string), "[Reason: %s | Warnings: %d/%d]", PlayerInfo[playerid][MutedReason], PlayerInfo[playerid][MuteWarnings], MAX_WARNINGS);
  184.         SendClientMessage(playerid, COLOR_TOMATO, string);
  185.     }
  186.     return 1;
  187. }
  188.  
  189. public OnPlayerDisconnect(playerid, reason)
  190. {
  191.     new INI:File = INI_Open(UserPath(playerid));
  192.     INI_SetTag(File,"data");
  193.     INI_WriteInt(File,"Muted",PlayerInfo[playerid][Muted]);
  194.     INI_WriteString(File,"MutedReason",PlayerInfo[playerid][MutedReason]);
  195.     INI_WriteInt(File,"MuteWarnings",PlayerInfo[playerid][MuteWarnings]);
  196.     INI_WriteInt(File,"SpamMute",PlayerInfo[playerid][SpamMute]);
  197.     INI_WriteInt(File,"TotalMute",PlayerInfo[playerid][TotalMute]);
  198.     INI_Close(File);
  199.  
  200.     return 1;
  201. }
  202.  
  203.  
  204. // ==============================================
  205. //                  COMMANDS
  206. // ==============================================
  207.  
  208. CMD:mute(playerid, params[]) {
  209.     if (IsPlayerAdmin(playerid)) {
  210.         new targetid, aname[MAX_PLAYER_NAME], tname[MAX_PLAYER_NAME], msg1[128], reason[128];
  211.         if(sscanf(params, "us[64]", targetid, reason)) return SendClientMessage(playerid, COLOR_LIGHTBLUE,"[USAGE]: /mute [playerid] [reason]" );
  212.         if(targetid == INVALID_PLAYER_ID) return SendClientMessage( playerid, COLOR_RED,"[ERROR]: Player Is Not Connected!" );
  213.         if (IsPlayerMuted(playerid)) return SendClientMessage(playerid, COLOR_RED, "[ERROR]: That player is already muted.");
  214.  
  215.         GetPlayerName(playerid, aname, sizeof(aname));
  216.         GetPlayerName(targetid, tname, sizeof(tname));
  217.         PlayerInfo[targetid][MutedReason] = reason;
  218.         PlayerInfo[targetid][Muted] = 1;
  219.         PlayerInfo[targetid][MuteWarnings] = 0;
  220.         PlayerInfo[targetid][SpamMute] = 0;
  221.         PlayerInfo[targetid][TotalMute]++;
  222.         new string[128];
  223.         format(string, sizeof(string), "Reason: %s", PlayerInfo[targetid][MutedReason]);
  224.  
  225.         format(msg1, sizeof(msg1), "*Administrator %s has muted %s. [Reason: %s]", aname, tname, PlayerInfo[targetid][MutedReason]);
  226.         SendClientMessageToAll(COLOR_LIGHTBLUE, msg1);
  227.  
  228.         PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
  229.         PlayerPlaySound(targetid,1057,0.0,0.0,0.0);
  230.  
  231.     } else {
  232.         SendClientMessage(playerid, COLOR_RED, "*Only admins can use that command.");
  233.     }
  234.     return 1;
  235. }
  236. CMD:unmute(playerid, params[]) {
  237.     if (IsPlayerAdmin(playerid)) {
  238.         new targetid, aname[MAX_PLAYER_NAME], tname[MAX_PLAYER_NAME], msg1[128];
  239.         if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, COLOR_LIGHTBLUE,"[USAGE]: /unmute [playerid]" );
  240.         if(targetid == INVALID_PLAYER_ID) return SendClientMessage( playerid, COLOR_RED,"[ERROR]: Player Is Not Connected!" );
  241.         if (!IsPlayerMuted(playerid)) return SendClientMessage(playerid, COLOR_RED, "[ERROR]: That player is not muted.");
  242.  
  243.         GetPlayerName(playerid, aname, sizeof(aname));
  244.         GetPlayerName(targetid, tname, sizeof(tname));
  245.  
  246.         format(msg1, sizeof(msg1), "*Administrator %s has unmuted %s.", aname, tname);
  247.         SendClientMessageToAll(COLOR_LIGHTBLUE, msg1);
  248.         PlayerInfo[targetid][Muted] = 0;
  249.         format(PlayerInfo[targetid][MutedReason], 128, "None");
  250.         PlayerInfo[targetid][MuteWarnings] = 0;
  251.         PlayerInfo[targetid][SpamMute] = 0;
  252.         PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
  253.         PlayerPlaySound(targetid,1057,0.0,0.0,0.0);
  254.  
  255.     } else {
  256.         SendClientMessage(playerid, COLOR_RED, "*Only admins can use that command!");
  257.     }
  258.     return 1;
  259. }
  260. CMD:mlist(playerid) {
  261.     SendClientMessage(playerid, COLOR_LAWNGREEN, "_______| Online Muted Players |______");
  262.     if (IsAnyMutedPlayerOnline()) {
  263.         for (new i=0; i < MAX_PLAYERS; i++) {
  264.             if (IsPlayerConnected(i) && IsPlayerMuted(i)) {
  265.                 new string[128], name[MAX_PLAYER_NAME];
  266.                 GetPlayerName(i, name, sizeof(name));
  267.                 format(string, sizeof(string), "%s[ID: %d]: Reason: %s | Warnings: %d/%d", name, i, PlayerInfo[i][MutedReason], PlayerInfo[i][MuteWarnings], MAX_WARNINGS);
  268.                 SendClientMessage(playerid, COLOR_LIMEGREEN, string);
  269.             }
  270.         }
  271.     } else {
  272.         SendClientMessage(playerid, COLOR_RED, "No muted players online.");
  273.     }
  274.     SendClientMessage(playerid, COLOR_LAWNGREEN, "____________________________________");
  275.     return 1;
  276. }
  277. CMD:requestunmute(playerid) {
  278.     if (IsPlayerMuted(playerid)) {
  279.         if (IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "* You can unmute yourself, Idiot!");
  280.         new string[128], name[MAX_PLAYER_NAME];
  281.         GetPlayerName(playerid, name, sizeof(name));
  282.         format(string, sizeof(string), "*%s is requesting to unmute him. Reason: %s | Warning: %d/%d", name, PlayerInfo[playerid][MutedReason], PlayerInfo[playerid][MuteWarnings], MAX_WARNINGS);
  283.         for (new i=0; i < MAX_PLAYERS; i++) {
  284.             if (IsPlayerConnected(i) && IsPlayerAdmin(i)) {
  285.                 SendClientMessage(i, COLOR_YELLOW, string);
  286.             }
  287.         }
  288.         SendClientMessage(playerid, COLOR_YELLOW, "*You're request has been sent to online admins.");
  289.     } else {
  290.         SendClientMessage(playerid, COLOR_RED, "*You are not muted");
  291.     }
  292.     return 1;
  293. }
  294. CMD:minfo(playerid, params[]) {
  295.     new targetid, string[128], name[MAX_PLAYER_NAME];
  296.     if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, COLOR_LIGHTBLUE,"[USAGE]: /minfo [playerid]" );
  297.     if(targetid == INVALID_PLAYER_ID) return SendClientMessage( playerid, COLOR_RED,"[ERROR]: Player Is Not Connected!" );
  298.     GetPlayerName(targetid, name, sizeof(name));
  299.     format(string, sizeof(string), "Player Name: %s | Total Mutes: %d", name, PlayerInfo[targetid][TotalMute]);
  300.     SendClientMessage(playerid, COLOR_LAWNGREEN, string);
  301.     return 1;
  302. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement