Advertisement
Kwarde

BugReport v0.1.28-RC

May 14th, 2013
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 8.49 KB | None | 0 0
  1. /*
  2.     Filterscript made by Kwarde:
  3.         * SA-MP Forums: forum.sa-mp.com/member.php?u=70717
  4.         * E-Mail:       kwarde@mail.com
  5.        
  6.     For information about this filterscript and its defines, check out the 'BugReport_README.txt' file!
  7.    
  8.     YOU MAY:
  9.         - Use this script ;-)
  10.         - Edit this script (but don't re-release it!)
  11.         - Remove ingame credits (checkout USE_INGAME_ADVERTISE), but please keep the prints (so you see my name yay :3)
  12.         - Put this into your gamemode
  13.         - Remove this annoying text (the one from start 'till '#define FILTERSCRIPT')
  14.     YOU MAY NOT:
  15.         - Re-release this script
  16.         - Re-release this script and claim it for your own (That is just very pathethic and dumb)
  17.         - Claim the script for your own without re-releasing it
  18.         - Kill other people or steal from other people (re-releasing / claiming as your own is stealing!)
  19.        
  20.     Enjoy the filterscript :)
  21. */
  22. #define FILTERSCRIPT
  23. #include <a_samp>
  24. #include <sscanf2>
  25. #include <zcmd>
  26.  
  27. #define COLOR_WHITE             0xFFFFFFAA
  28. #define COLOR_RED               0xFF0000AA
  29. #define COLOR_GREEN             0x00FF00AA
  30. #define COLOR_LIGHTBLUE         0x00FFFFAA
  31. #define COLOR_GRAY              0xAFAFAFAA
  32.  
  33. #define FS_VERS_MAJOR           0
  34. #define FS_VERS_MINOR           1
  35. #define FS_VERS_BUILD           28
  36. #define FS_VERS_TAG             "RC" //A(lpha), B(eta), R(elease) C(andidate)
  37.  
  38. #define BUG_REPORT_FILE         "ServerBugReports.txt"
  39. #define USE_INGAME_ADVERTISE    
  40. #define REPORT_INTERVAL         30 //Ammount in seconds before a player can report a bug again
  41.  
  42. #define DIALOG_BREPORT          666
  43. #define DIALOG_BREPORT_CONFIRM  667
  44.  
  45. #define CB:%0(%1)               forward %0(%1); public %0(%1)
  46. #define ploop(%0)               for (new %0 = 0; %0 < MAX_PLAYERS; %0++) if (IsPlayerConnected(%0) && !IsPlayerNPC(%0))
  47.  
  48. new bool:pCanReport[MAX_PLAYERS] = true,
  49.     pReportTimer[MAX_PLAYERS] = (-1);
  50.  
  51. public OnFilterScriptInit()
  52. {
  53.     print(" ");
  54.     print(">> BugReport v"#FS_VERS_MAJOR"."#FS_VERS_MINOR"."#FS_VERS_BUILD"-"#FS_VERS_TAG" loaded <<");
  55.     print(">> BugReport created by Kwarde (contact: kwarde@mail.com) <<");
  56.     print(" ");
  57.     return 1;
  58. }
  59.  
  60. public OnFilterScriptExit()
  61. {
  62.     ploop(i)
  63.     {
  64. #if defined USE_INGAME_ADVERTISE
  65.         DeletePVar(i, "BR_FirstSpawn");
  66. #endif
  67.         DeletePVar(i, "BR_BugReport");
  68.         if (pReportTimer[i] != -1) KillTimer(pReportTimer[i]); //Not sure if it's needed
  69.     }
  70.     print(">> Filterscript BugReport (made by Kwarde) unloaded <<");
  71.     return 1;
  72. }
  73.  
  74. public OnPlayerConnect(playerid)
  75. {
  76. #if defined USE_INGAME_ADVERTISE
  77.     new str[128];
  78.     SetPVarInt(playerid, "BR_FirstSpawn", 0);
  79.     format(str, 128, "This server is using {FFFFFF}BugReport v%d.%d.%d-%s", FS_VERS_MAJOR, FS_VERS_MINOR, FS_VERS_BUILD, FS_VERS_TAG);
  80.     SendClientMessage(playerid, COLOR_GRAY, str);
  81. #endif
  82.     return 0;
  83. }
  84.  
  85. #if defined USE_INGAME_ADVERTISE
  86. public OnPlayerSpawn(playerid)
  87. {
  88.     if (GetPVarInt(playerid, "BR_FirstSpawn") == 0)
  89.     {
  90.         SendClientMessage(playerid, COLOR_WHITE, "SERVER: We are using BugReport so that you can report bugs! ({FF0000}/reportbug{FFFFFF})");
  91.         SendClientMessage(playerid, COLOR_WHITE, "SERVER: BugReport is created by Kwarde (for more info, contact {FFFF00}kwarde@mail.com{FFFFFF})");
  92.         SetPVarInt(playerid, "BR_FirstSpawn", 1);
  93.     }
  94.     return 0;
  95. }
  96. #endif
  97.  
  98. public OnPlayerDisconnect(playerid)
  99. {
  100.     if (pReportTimer[playerid] != -1)
  101.     {
  102.         KillTimer(pReportTimer[playerid]);
  103.         pReportTimer[playerid] = (-1);
  104.     }
  105.     pCanReport[playerid] = true;
  106.     DeletePVar(playerid, "BR_BugReport");
  107. #if defined USE_INGAME_ADVERTISE
  108.     DeletePVar(playerid, "BR_FirstSpawn");
  109. #endif
  110.     return 0;
  111. }
  112.  
  113. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  114. {
  115.     switch (dialogid)
  116.     {
  117.         case DIALOG_BREPORT:
  118.         {
  119.             if (!response)
  120.                 return SendClientMessage(playerid, COLOR_GRAY, "Bug report cancelled.");
  121.                
  122.             if (isnull(inputtext) || strlen(inputtext) < 10 || strlen(inputtext) > 100)
  123.             {
  124.                 SendClientMessage(playerid, COLOR_RED, "[ERROR] {FFFFFF}You must fill in the report bug, with a length of 10 to 100 characters!");
  125.                 ShowDialog(playerid, DIALOG_BREPORT);
  126.                 return 1;
  127.             }
  128.  
  129.             SetPVarString(playerid, "BR_BugReport", inputtext);
  130.             ShowDialog(playerid, DIALOG_BREPORT_CONFIRM);
  131.             return 1;
  132.         }
  133.         case DIALOG_BREPORT_CONFIRM:
  134.         {
  135.             if (!response)
  136.                 return ShowDialog(playerid, DIALOG_BREPORT);
  137.  
  138.             new str[128], pName[MAX_PLAYER_NAME], bug[100];
  139.             GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
  140.             GetPVarString(playerid, "BR_BugReport", bug, 100);
  141.             BugReport(playerid, bug);
  142.             SendClientMessage(playerid, COLOR_GREEN, "Thank you very much! The bug has been reported!");
  143.             format(str, 128, "[NOTICE] %s (ID: %d) reported a bug! Use /checkbugs to see the report! (You'll see the last 9 bug reports)", pName, playerid);
  144.             for (new i = 0; i < MAX_PLAYERS; i++)
  145.             {
  146.                 if (!IsPlayerConnected(i) || IsPlayerNPC(i) || !IsAdmin(i)) continue;
  147.                 SendClientMessage(i, COLOR_LIGHTBLUE, str);
  148.             }
  149.             DeletePVar(playerid, "BR_BugReport");
  150.             pCanReport[playerid] = false;
  151.             pReportTimer[playerid] = SetTimerEx("PReportOn", REPORT_INTERVAL * 1000, false, "i", playerid);
  152.             return 1;
  153.         }
  154.     }
  155.     return 0;
  156. }
  157.  
  158. CB:PReportOn(playerid)
  159. {
  160.     pReportTimer[playerid] = (-1);
  161.     pCanReport[playerid] = true;
  162.     SendClientMessage(playerid, COLOR_LIGHTBLUE, "[NOTICE] {FFFFFF}You can use /reportbug again to report bugs!");
  163.     return 1;
  164. }
  165.  
  166. stock IsAdmin(playerid) //Check out 'IsAdmin_examples.pwn' so that this function makes more sense ;)
  167. {
  168.     if (IsPlayerAdmin(playerid))
  169.         return true;
  170.     return false;
  171. }
  172.  
  173. stock BugReport(playerid, bugTxt[])
  174. {
  175.     new pName[MAX_PLAYER_NAME];
  176.     new File:bugReportFile = fopen(BUG_REPORT_FILE, io_append);
  177.     new writeStr[200];
  178.     GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
  179.     format(writeStr, 200, "%s|%s\n", pName, bugTxt);
  180.     fwrite(bugReportFile, writeStr);
  181.     fclose(bugReportFile);
  182.     return 1;
  183. }
  184.  
  185. stock GetFileLines(file[])
  186. {
  187.     if (!fexist(file)) return 0;
  188.     new File:readFile = fopen(file, io_read);
  189.     new readStr[200], lines = 1; //readStr[255] - I preferred 'readStr[1]', but it only seems to work if the length is as long as the line (I tested, and [1] didn't work on the next file content: "1\n2\n3\n4\n5"
  190.     while (fread(readFile, readStr))
  191.         lines++;
  192.     fclose(readFile);
  193.     return lines;
  194. }
  195.  
  196. stock ShowDialog(playerid, dialogid)
  197. {
  198.     switch (dialogid)
  199.     {
  200.         case DIALOG_BREPORT: ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_INPUT, "Bug report", "Please fill in the bug you've detected.\nIt's recommended that you report it as short as possible and also include information on how it happened.\nExample: \"The command /reportbug is nog working!\" or \"My vehicle doesn't spawn when I use /veh\"", "Report", "Cancel");
  201.         case DIALOG_BREPORT_CONFIRM:
  202.         {
  203.             new str[210], bug[100];
  204.             GetPVarString(playerid, "BR_BugReport", bug, 100);
  205.             format(str, 210, "{FFFFFF}You are going to report the next bug:\n{FF0000}%s\n{FFFFFF}Are you sure you want to report that?", bug);
  206.             ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_MSGBOX, "Bug report: Confirm", str, "Yes", "No");
  207.         }
  208.     }
  209.     return 1;
  210. }
  211.  
  212. CMD:reportbug(playerid, params[])
  213. {
  214.     if (pCanReport[playerid])
  215.         ShowDialog(playerid, DIALOG_BREPORT);
  216.     else
  217.     {
  218.         SendClientMessage(playerid, COLOR_RED, "[ERROR] {FFFFFF}You can't report a bug at the time (in order to prevent spamming).");
  219.         SendClientMessage(playerid, COLOR_RED, "[ERROR] {FFFFFF}You'll receive a message when you can use this command again");
  220.         return 1;
  221.     }
  222.     return 1;
  223. }
  224.  
  225. CMD:checkbugs(playerid, params[])
  226. {
  227.     if (!IsAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "[ERROR] {FFFFFF}This command is for admins only!");
  228.     if (!fexist(BUG_REPORT_FILE)) return SendClientMessage(playerid, COLOR_GRAY, "[NOTICE] {FFFFFF}There are nog bugs reported");
  229.     for (new i = 0; i < 10; i++) SendClientMessage(playerid, -1, " ");
  230.     SendClientMessage(playerid, COLOR_WHITE, "|---------- {FFFF00}Bug reports {FFFFFF}----------|");
  231.     new File:bugReportFile = fopen(BUG_REPORT_FILE, io_read);
  232.     new readStr[200], str[128], curLine = 1;
  233.     new totalLines = GetFileLines(BUG_REPORT_FILE);
  234.     new start;
  235.     if (totalLines <= 11) start = 1;
  236.     else start = totalLines - 8;
  237.     while (fread(bugReportFile, readStr))
  238.     {
  239.         curLine++;
  240.         if (curLine < start) continue;
  241.         new strName[MAX_PLAYER_NAME], strBug[100];
  242.         sscanf(readStr, "p<|>s[24]s[100]", strName, strBug);
  243.         format(str, 128, "%s: {AFAFAF}%s", strName, strBug);
  244.         SendClientMessage(playerid, COLOR_WHITE, str);
  245.     }
  246.     fclose(bugReportFile);
  247.     return 1;
  248. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement