Advertisement
Lordz

L-Infraction System.

Oct 21st, 2012
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 17.02 KB | None | 0 0
  1. /*____________________________________________________________________________________________________________________
  2.  
  3. ======================================================================================================================
  4.                                             L-Infraction System by  Lordz™.
  5.                                             Copyright(c)2012, L-Infractions.
  6. ======================================================================================================================
  7. _____________________________________________________________________________________________________________________
  8.  
  9. Credits goes to:
  10. Y_Less for sscanf2 and y_ini.
  11. ZeeX for zcmd.
  12. Lordz™ for the script.
  13. */
  14. //==============================================================================
  15. //                              Includes
  16. //==============================================================================
  17. #include <a_samp>
  18. #include <YSI\y_ini>
  19. #include <zcmd>
  20. #include <sscanf2>
  21. //==============================================================================
  22. //                          Color Defines
  23. //==============================================================================
  24. #define red 0xFF0000FF
  25. #define green 0xFF0000
  26. #define yellow 0xFFFF00C8
  27. #define orange 0xFF9900AA
  28. //==============================================================================
  29. //                          Dialogs
  30. //==============================================================================
  31. #define DPERMIT 5000
  32. #define RECIEVE 5001
  33. #define RPERMIT 5003
  34. #define banned 5004
  35. //==============================================================================
  36. //                          Configurations.
  37. //==============================================================================
  38. #define UserPath "L-Infractions/L-Users/%s.ini"
  39. #define LogPath "L-Infractions/Inf_log.txt"
  40. #define Permittedusers "L-Infractions/Permitted_Users.txt"
  41. #define INF_BAN_PATH "L-Infractions/Ban_log.txt"
  42. #define MAX_INFRACTIONS 10 //MAX infraction level, 10 is the default. You can change it.
  43. #define INF_DCHAT 9 //Infraction level, which will disable player's chatting ability. This must not be greater than MAX_INFRACTIONS.
  44. #if INF_DCHAT > MAX_INFRACTIONS
  45. #error "INF_DCHAT must be defined lower than MAX_INFRACTIONS."
  46. #endif
  47. #define INF_FREEZE 8 //Infraction level at which player will be frozen.
  48. #define FREEZE_TIME 1 //Minutes, a player will be frozen.
  49. #define Servername "SERVER" //Change the "SERVER" to your server name. NOTE: Your server name must be inside the quotes.
  50. #define website "www.google.com" //Change this to your website.
  51.  
  52. //==============================================================================
  53. new File:Infban;
  54. new File:Inflog;
  55. new File:Permulog;
  56.  
  57. public OnFilterScriptInit()
  58. {
  59.  printf("---------------------------------------------");
  60.  printf("\nL-Infraction system by Lordz™ Loaded!");
  61.  for(new i; i< MAX_PLAYERS; i++)
  62.  {
  63.   if(IsPlayerConnected(i))
  64.   {
  65.    INI_ParseFile(LPath(i),"loadinfractions", .bExtra = true, .extra = i);
  66.    print("Parsing Infractions");
  67.   }
  68.  }
  69.  print("Parsed Successfully!");
  70.  print("-----------------------------------------");
  71.  return 1;
  72. }
  73.  
  74. public OnFilterScriptExit()
  75. {
  76.  printf("---------------------------------------------");
  77.  printf("\nL-Infraction system by  Lordz™ Unloaded");
  78.  for(new i; i< MAX_PLAYERS; i++)
  79.  {
  80.   if(IsPlayerConnected(i))
  81.   {
  82.    SaveInfractions(i);
  83.    print("Saving Infractions");
  84.   }
  85.  }
  86.  print("Saved Infractions successfully");
  87.  printf("-------------------------------------------\n");
  88.  return 1;
  89. }
  90.  
  91. //==============================================================================
  92. //                          L-Functions
  93. //==============================================================================
  94. //Warning:Do not edit, if you're a newbie/don't know.
  95.  
  96. new FString[1000];
  97. #define LFormat(%0) (format(FString, 1000, %0), FString)
  98. #define LMessage(%0,%1,%2) SendClientMessage(%0, %1, LFormat(%2))
  99. #define LTime(%0,%1,%2) (((%0)*3600+(%1)*60+(%2))*1000)
  100. //==============================================================================
  101. //                             Infractions Info
  102. //==============================================================================
  103.  
  104. enum LInfo
  105. {
  106.   InfPermit,
  107.   Infraction
  108. }
  109.  
  110.  
  111. new LUserInfo[MAX_PLAYERS][LInfo];
  112. new Timer[MAX_PLAYERS];
  113. new FREEZE[MAX_PLAYERS];
  114.  
  115. stock LPath(playerid)
  116. {
  117.   new string[128], Lname[MAX_PLAYER_NAME];
  118.   GetPlayerName(playerid,Lname,sizeof(Lname));
  119.   format(string,sizeof(string),UserPath,Lname);
  120.   return string;
  121. }
  122.  
  123. stock SaveInfractions(playerid)
  124. {
  125.  new Linfname[MAX_PLAYER_NAME];
  126.  GetPlayerName(playerid,Linfname,sizeof(Linfname));
  127.  new INI:Lfile = INI_Open(LPath(playerid));
  128.  new tagstr[30];
  129.  format(tagstr,sizeof(tagstr),"%s's Info", Linfname);
  130.  INI_SetTag(Lfile, tagstr);
  131.  INI_WriteInt(Lfile, "Infractions", LUserInfo[playerid][Infraction]);
  132.  INI_WriteInt(Lfile, "Permitted", LUserInfo[playerid][InfPermit]);
  133.  INI_Close(Lfile);
  134.  return 1;
  135. }
  136.  
  137. stock LBan(playerid)
  138. {
  139.   new str[128];
  140.   new lstr[128];
  141.   new LYear,LMonth,LDay;
  142.   new Lhour, LMin, LSec;
  143.   new LBname[MAX_PLAYER_NAME];
  144.   getdate(LYear,LMonth,LDay);
  145.   gettime(Lhour,LMin,LSec);
  146.   GetPlayerName(playerid,LBname,sizeof(LBname));
  147.   format(lstr,sizeof(lstr),"%s(ID:%d) has been automatically banned. (Reason:Reached MAXIMUM Infraction Level.)", LBname, playerid);
  148.   SendClientMessageToAll(red, lstr);
  149.   format(str,sizeof(str),"%s has been banned for reaching MAXIMUM Infraction Level. [DATE:%02d/%02d/%d] [TIME:%02d-%02d-%02d]\r\n", LBname, LDay, LMonth, LYear, Lhour, LMin, LSec);
  150.   Infban = fopen(INF_BAN_PATH, io_append);
  151.   fwrite(Infban,str);
  152.   fclose(Infban);
  153.   new ip[16];
  154.   GetPlayerIp(playerid, ip, sizeof(ip));
  155.   new bstr[400];
  156.   format(bstr,sizeof(bstr),"{FF0000}You have been banned from %s\nReason:Reached MAXIMUM Infraction Level.\nPlayerName:%s\nID:%d\nIP:%i\nDATE:%02d/%02d/%02d\nTIME:%02d-%02d-%02d\n{FFFFFF}If you feel that you're innocent, please press {FF0000}F8{FFFFFF}(to take snapshot)\n and post this on {FF0000}forums.\nLink:%s", Servername, LBname, playerid, ip, LDay, LMonth, LYear, Lhour, LMin, LSec, website);
  157.   ShowPlayerDialog(playerid, banned, DIALOG_STYLE_MSGBOX,"{FF0000}L-Infractions > BAN INFO", bstr, "Close", "");
  158.   TogglePlayerControllable(playerid,false);
  159.   return Ban(playerid);
  160. }
  161.  
  162. forward loadinfractions(playerid, name[], value[]);
  163.  
  164. public loadinfractions(playerid, name[], value[])
  165. {
  166.  INI_Int("Infractions", LUserInfo[playerid][Infraction]);
  167.  INI_Int("Permitted", LUserInfo[playerid][InfPermit]);
  168.  return 1;
  169. }
  170.  
  171. public OnPlayerConnect(playerid)
  172. {
  173.  INI_ParseFile(LPath(playerid),"loadinfractions", .bExtra = true, .extra = playerid);
  174.  if(LUserInfo[playerid][Infraction] == MAX_INFRACTIONS-1) return LMessage(playerid, red, "WARNING:You are currently having %d Infractions. If you gain one more, you'll be Banned!", MAX_INFRACTIONS-1);
  175.  return 1;
  176. }
  177.  
  178. public OnPlayerDisconnect(playerid, reason)
  179. {
  180.   SaveInfractions(playerid);
  181.   return 1;
  182. }
  183.  
  184. CMD:permit(playerid,params[])
  185. {
  186.  if(!IsPlayerAdmin(playerid)) return LMessage(playerid, red, "You must be logged in as RCON to use this command.");
  187.  new p2;
  188.  new lName[MAX_PLAYER_NAME];
  189.  new pName[MAX_PLAYER_NAME];
  190.  if(sscanf(params,"u",p2))
  191.  {
  192.   LMessage(playerid, red, "Usage: /permit [playerid]");
  193.   return LMessage(playerid, orange, "Function:Will allow the specified player to infract rule breakers.");
  194.  }
  195.  if(p2 == INVALID_PLAYER_ID) return LMessage(playerid, red, "This player ID is invalid.");
  196.  if(LUserInfo[p2][InfPermit] == 1) return LMessage(playerid, red, "Player is already Permitted.");
  197.  if(!IsPlayerConnected(p2)) return LMessage(playerid, red, "Player isn't connected");
  198.  else
  199.  {
  200.  GetPlayerName(playerid,lName,sizeof(lName));
  201.  GetPlayerName(p2,pName,sizeof(pName));
  202.  LUserInfo[p2][InfPermit] = 1;
  203.  LMessage(p2, green, "%s (ID:%d) has permitted you to Infract rule breakers.", lName, playerid);
  204.  LMessage(playerid, green, "You have successfully permitted %s (ID:%d) to infract rule breakers.", pName, p2);
  205.  new string[256];
  206.  format(string,sizeof(string),"{FFFFFF}You have been permitted to Infract rule breakers. \n Permitted by:{FF0000}%s", lName);
  207.  ShowPlayerDialog(playerid, DPERMIT, DIALOG_STYLE_MSGBOX, "{FF0000}L-INFRACTIONS!", string, "Okay", "");
  208.  SaveInfractions(playerid);
  209.  SaveInfractions(p2);
  210.  new lstring[34];
  211.  format(lstring,sizeof(lstring), "%s is permitted\r\n", pName);
  212.  Permulog = fopen(Permittedusers, io_append);
  213.  fwrite(Permulog,lstring);
  214.  fclose(Permulog);
  215.  }
  216.  return 1;
  217. }
  218.  
  219. CMD:rpermit(playerid,params[])
  220. {
  221.  if(!IsPlayerAdmin(playerid)) return LMessage(playerid, red, "You must be logged in as RCON to use this command.");
  222.  new p2;
  223.  new lName[MAX_PLAYER_NAME];
  224.  new pName[MAX_PLAYER_NAME];
  225.  new reason[60];
  226.  if(sscanf(params,"us[60]",p2,reason))
  227.  {
  228.   LMessage(playerid, red, "Usage: /rpermit [playerid] [reason]");
  229.   return LMessage(playerid, orange, "Function:Will remove the infracting permission from specified player.");
  230.  }
  231.  else
  232.  {
  233.  GetPlayerName(playerid,lName,sizeof(lName));
  234.  GetPlayerName(p2,pName,sizeof(pName));
  235.  if(p2 == INVALID_PLAYER_ID) return LMessage(playerid, red, "This player ID is invalid.");
  236.  if(!IsPlayerConnected(p2)) return LMessage(playerid, red, "Player is not connected");
  237.  if(LUserInfo[p2][InfPermit] == 0) return LMessage(playerid, red, "Player %s is not permitted", pName);
  238.  LUserInfo[p2][InfPermit] = 0;
  239.  LMessage(playerid, yellow, "You have successfully removed the Infraction Permit of %s", pName);
  240.  LMessage(p2, red, "Your Infracting Permission has been removed by %s (Reason:%s)", lName, reason);
  241.  new string[128];
  242.  format(string,sizeof(string), "{FFFFFF}Your infracting permission has been removed by {FF0000}%s\n Reason:%s", lName, reason);
  243.  ShowPlayerDialog(p2,RPERMIT,DIALOG_STYLE_MSGBOX, "{FF0000}L-Infractions", string, "Okay", "");
  244.  SaveInfractions(playerid);
  245.  SaveInfractions(p2);
  246.  }
  247.  return 1;
  248. }
  249.  
  250. CMD:infract(playerid,params[])
  251. {
  252.  if(LUserInfo[playerid][InfPermit] == 0) return LMessage(playerid, red, "You don't have permission to use this command.");
  253.  new p2;
  254.  new reason[60];
  255.  new string[400];
  256.  new lName[MAX_PLAYER_NAME];
  257.  new pName[MAX_PLAYER_NAME];
  258.  new Lhour,Lmin,Lsec;
  259.  new Year,month,day;
  260.  if(sscanf(params,"us[60]", p2, reason))
  261.  {
  262.   LMessage(playerid, red, "Usage: /infract [playerid] [reason]");
  263.   return LMessage(playerid, orange, "Function:This command will allow to infract a rule breaker.");
  264.  }
  265.  else
  266.  {
  267.  GetPlayerName(playerid,lName,sizeof(lName));
  268.  GetPlayerName(p2,pName,sizeof(pName));
  269.  gettime(Lhour,Lmin,Lsec);
  270.  getdate(Year,month,day);
  271.  if(p2 == INVALID_PLAYER_ID) return LMessage(playerid, red, "This player ID is invalid");
  272.  LUserInfo[p2][Infraction]++;
  273.  new lstr[128];
  274.  format(lstr,sizeof(lstr),"%s(ID:%d) has issued an infraction to %s(ID:%d) (Reason:%s)", lName, playerid, pName, p2, reason);
  275.  SendClientMessageToAll(red, lstr);
  276.  LMessage(p2, yellow, "%s(ID:%d) has given issued you an Infraction. (Reason:%s)", lName, playerid, reason);
  277.  LMessage(playerid, yellow, "You have infracted %s(ID:%d) (Reason:%s)", pName, p2, reason);
  278.  format(string,sizeof(string),"{FFFFFF}You have recieved an infraction at %s\nIssued by:{FF0000}%s\nReason:%s\n{FFFFFF}Date:%02d/%02d/%d\nTime:\nHour:%02d\nMinute:%02d\nSecond:%02d\nCurrent Infractions:{FF0000}%d/%d\n{FF0000}If you feel that you're innocent, please press F8(to take snapshot)\n and post this on  forums.\nLink:%s", Servername, lName, reason, day, month, Year, Lhour, Lmin, Lsec, LUserInfo[p2][Infraction], MAX_INFRACTIONS, website);
  279.  ShowPlayerDialog(p2, RECIEVE, DIALOG_STYLE_MSGBOX, "{FF0000}L-Infractions > You have recieved an Infraction", string, "Close", "");
  280.  new logstr[128];
  281.  format(logstr,sizeof(logstr),"%s has issued %s an infraction.(Reason:%s) [DATE:%02d/%02d/%d] [Time:%02d-%02d-%02d]\r\n", lName, pName, reason, day, month, Year, Lhour, Lmin, Lsec);
  282.  Inflog = fopen(LogPath, io_append);
  283.  fwrite(Inflog,logstr);
  284.  fclose(Inflog);
  285.  SaveInfractions(playerid);
  286.  SaveInfractions(p2);
  287.  }
  288.  return 1;
  289. }
  290.  
  291. CMD:setinfractions(playerid,params[])
  292. {
  293.  if(!IsPlayerAdmin(playerid)) return LMessage(playerid, red, "You must be logged in as RCON to use this command.");
  294.  new p2;
  295.  new inf;
  296.  new lName[MAX_PLAYER_NAME];
  297.  new pName[MAX_PLAYER_NAME];
  298.  if(sscanf(params,"ui",p2,inf))
  299.  {
  300.   LMessage(playerid, red, "Usage: /setinfractions [playerid]");
  301.   return LMessage(playerid, orange, "Fucntion:Will set the infraction level of a player.");
  302.  }
  303.  else
  304.  {
  305.  if(!IsPlayerConnected(playerid)) return LMessage(playerid, red, "Player is not connected");
  306.  if(p2 == INVALID_PLAYER_ID) return LMessage(playerid, red, "Ivalid player ID");
  307.  if(inf < 0 || inf >= MAX_INFRACTIONS) return LMessage(playerid, red, "Invalid Infraction level. (Available: 0-%d)", MAX_INFRACTIONS-1);
  308.  GetPlayerName(playerid,lName,sizeof(lName));
  309.  GetPlayerName(p2,pName,sizeof(pName));
  310.  LUserInfo[p2][Infraction] = inf;
  311.  LMessage(playerid, green, "[L-Infractions] You have successfully set %s's(ID:%d) Infraction level to %d", pName, p2, inf);
  312.  LMessage(p2, yellow, "[L-Infractions] Your infraction level has been set to %d by %s(ID:%d)", inf, lName, playerid);
  313.  SaveInfractions(playerid);
  314.  SaveInfractions(p2);
  315.  }
  316.  return 1;
  317. }
  318.  
  319. CMD:rinfraction(playerid,params[])
  320. {
  321.  if(LUserInfo[playerid][InfPermit] == 0) return LMessage(playerid, red, "You are not having permission to use this command.");
  322.  if(Timer[playerid] == 1) return LMessage(playerid, red, "You must wait atleast 5 minutes to use this command");
  323.  new p2;
  324.  new lName[MAX_PLAYER_NAME];
  325.  new pName[MAX_PLAYER_NAME];
  326.  if(sscanf(params,"u",p2))
  327.  {
  328.   LMessage(playerid, red, "Usage: /rinfraction [playerid]");
  329.   return LMessage(playerid, orange, "Function:Will reduce the infraction of a player -1.");
  330.  }
  331.  else
  332.  {
  333.  GetPlayerName(playerid,lName,sizeof(lName));
  334.  GetPlayerName(p2, pName, sizeof(pName));
  335.  if(LUserInfo[p2][Infraction] == 0) return LMessage(playerid, red, "Player's Infraction level is 0 and can't be reduced anymore.");
  336.  LUserInfo[p2][Infraction]--;
  337.  LMessage(playerid, green, "You have successfully reduced %s's(ID:%d) Infraction level {FF0000}(-1)", pName, p2);
  338.  LMessage(p2, yellow, "Your Infraction level has been reuced by %s(ID:%d) {FF0000} (-1)", lName, playerid);
  339.  SaveInfractions(playerid);
  340.  SaveInfractions(p2);
  341.  SetTimerEx("InfTimer",LTime(0,5,0),false,"d",playerid);
  342.  Timer[playerid] = 1;
  343.  }
  344.  return 1;
  345. }
  346.  
  347.  
  348. public OnPlayerUpdate(playerid)
  349. {
  350.  if(LUserInfo[playerid][Infraction] == MAX_INFRACTIONS) return LBan(playerid);
  351.  return 1;
  352. }
  353.  
  354. public OnPlayerSpawn(playerid)
  355. {
  356.  if(LUserInfo[playerid][Infraction] == INF_FREEZE)
  357.  {
  358.   FREEZE[playerid] = 1;
  359.   if(FREEZE[playerid] == 1)
  360.   {
  361.   TogglePlayerControllable(playerid,false);
  362.   SetTimerEx("FRZ_TIMER",LTime(0,FREEZE_TIME,0),false,"d",playerid);
  363.   LMessage(playerid, red, "You have been automatically frozen for %d minutes. (Reason:Recieved %d Infractions.)", FREEZE_TIME, INF_FREEZE);
  364.   }
  365.  }
  366.  return 1;
  367. }
  368.  
  369. forward InfTimer(playerid);
  370. forward FRZ_TIMER(playerid);
  371.  
  372. public InfTimer(playerid)
  373. {
  374.  if(Timer[playerid] == 1) return Timer[playerid] = 0;
  375.  return 1;
  376. }
  377.  
  378. public FRZ_TIMER(playerid)
  379. {
  380.  if(FREEZE[playerid] == 1)
  381.  {
  382.   FREEZE[playerid] = 0;
  383.   TogglePlayerControllable(playerid,true);
  384.   LMessage(playerid, green, "You are now unfrozen.");
  385.  }
  386.  return 1;
  387. }
  388.  
  389. public OnPlayerText(playerid, text[])
  390. {
  391.  if(LUserInfo[playerid][Infraction] == INF_DCHAT)
  392.  {
  393.   LMessage(playerid, red, "[L-Infraction]You are not allowed to chat since you have got %d INFRACTIONS.", INF_DCHAT);
  394.  }
  395.  return 0;
  396. }
  397.  
  398. CMD:myinfractions(playerid,params[])
  399. {
  400.  LMessage(playerid, yellow, "You currently have {FF0000}%d Infractions.", LUserInfo[playerid][Infraction]);
  401.  return 1;
  402. }
  403.  
  404. CMD:infractions(playerid,params[])
  405. {
  406.  if(LUserInfo[playerid][InfPermit] == 0) return LMessage(playerid, red, "You do not have permission to use this command.");
  407.  new p2;
  408.  if(sscanf(params,"u",p2))
  409.  {
  410.   LMessage(playerid, red, "Usage: /infractions [playerid]");
  411.   return LMessage(playerid, orange, "Function:Will show how many infractions does a player have.");
  412.  }
  413.  else
  414.  {
  415.  if(p2 == INVALID_PLAYER_ID) return LMessage(playerid, red, "This player ID is not valid.");
  416.  if(!IsPlayerConnected(p2)) return LMessage(playerid, red, "Player is not connected.");
  417.  new lName[MAX_PLAYER_NAME];
  418.  GetPlayerName(p2,lName,sizeof(lName));
  419.  LMessage(playerid, orange, "_________________________________________________");
  420.  LMessage(playerid, orange, "");
  421.  LMessage(playerid, green, "L-Infraction System by  Lordz™");
  422.  LMessage(playerid, orange, "_________________________________________________");
  423.  LMessage(playerid, yellow, "Player %s(ID:%d) currently has %d Infractions", lName, p2, LUserInfo[p2][Infraction]);
  424.  }
  425.  return 1;
  426. }
  427.  
  428. stock Infract(playerid,reason[])
  429. {
  430.  new infName[MAX_PLAYER_NAME];
  431.  GetPlayerName(playerid,infName,sizeof(infName));
  432.  LMessage(playerid, red, "[L-Infraction] %s has been Infracted! (Reason:%s)", infName, reason);
  433.  return LUserInfo[playerid][Infraction]++;
  434. }
  435.  
  436. //==============================================================================
  437. //                              Copyright (c)L-Infractions 2012
  438. //==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement