Advertisement
Kwarde

BugReport v0.1.22-RC

May 13th, 2013
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.34 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           22
  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.  
  41. #define DIALOG_BREPORT          666
  42. #define DIALOG_BREPORT_CONFIRM  667
  43.  
  44. public OnFilterScriptInit()
  45. {
  46.     print(" ");
  47.     print(">> BugReport v"#FS_VERS_MAJOR"."#FS_VERS_MINOR"."#FS_VERS_BUILD"-"#FS_VERS_TAG" loaded <<");
  48.     print(">> BugReport created by Kwarde (contact: kwarde@mail.com) <<");
  49.     print(" ");
  50.     return 1;
  51. }
  52.  
  53. public OnFilterScriptExit()
  54. {
  55.     for (new i = 0; i < MAX_PLAYERS; i++)
  56.     {
  57.         if (!IsPlayerConnected(i) || IsPlayerNPC(i)) continue;
  58. #if defined USE_INGAME_ADVERTISE
  59.         DeletePVar(i, "BR_FirstSpawn");
  60. #endif
  61.         DeletePVar(i, "BR_BugReport");
  62.     }
  63.     print(">> Filterscript BugReport (made by Kwarde) unloaded <<");
  64.     return 1;
  65. }
  66.  
  67. public OnPlayerConnect(playerid)
  68. {
  69. #if defined USE_INGAME_ADVERTISE
  70.     new str[128];
  71.     SetPVarInt(playerid, "BR_FirstSpawn", 0);
  72.     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);
  73.     SendClientMessage(playerid, COLOR_GRAY, str);
  74. #endif
  75.     return 0;
  76. }
  77.  
  78. #if defined USE_INGAME_ADVERTISE
  79. public OnPlayerSpawn(playerid)
  80. {
  81.     if (GetPVarInt(playerid, "BR_FirstSpawn") == 0)
  82.     {
  83.         SendClientMessage(playerid, COLOR_WHITE, "SERVER: We are using BugReport so that you can report bugs! ({FF0000}/reportbug{FFFFFF})");
  84.         SendClientMessage(playerid, COLOR_WHITE, "SERVER: BugReport is created by Kwarde (for more info, contact {FFFF00}kwarde@mail.com{FFFFFF})");
  85.         SetPVarInt(playerid, "BR_FirstSpawn", 1);
  86.     }
  87.     return 0;
  88. }
  89. #endif
  90.  
  91. public OnPlayerDisconnect(playerid)
  92. {
  93.     DeletePVar(playerid, "BR_BugReport");
  94. #if defined USE_INGAME_ADVERTISE
  95.     DeletePVar(playerid, "BR_FirstSpawn");
  96. #endif
  97.     return 0;
  98. }
  99.  
  100. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  101. {
  102.     switch (dialogid)
  103.     {
  104.         case DIALOG_BREPORT:
  105.         {
  106.             if (!response)
  107.                 return SendClientMessage(playerid, COLOR_GRAY, "Bug report cancelled.");
  108.                
  109.             if (isnull(inputtext) || strlen(inputtext) < 10 || strlen(inputtext) > 100)
  110.             {
  111.                 SendClientMessage(playerid, COLOR_RED, "[ERROR] {FFFFFF}You must fill in the report bug, with a length of 10 to 100 characters!");
  112.                 ShowDialog(playerid, DIALOG_BREPORT);
  113.                 return 1;
  114.             }
  115.  
  116.             SetPVarString(playerid, "BR_BugReport", inputtext);
  117.             ShowDialog(playerid, DIALOG_BREPORT_CONFIRM);
  118.             return 1;
  119.         }
  120.         case DIALOG_BREPORT_CONFIRM:
  121.         {
  122.             if (!response)
  123.                 return ShowDialog(playerid, DIALOG_BREPORT);
  124.  
  125.             new str[128], pName[MAX_PLAYER_NAME], bug[100];
  126.             GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
  127.             GetPVarString(playerid, "BR_BugReport", bug, 100);
  128.             BugReport(playerid, bug);
  129.             SendClientMessage(playerid, COLOR_GREEN, "Thank you very much! The bug has been reported!");
  130.             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);
  131.             for (new i = 0; i < MAX_PLAYERS; i++)
  132.             {
  133.                 if (!IsPlayerConnected(i) || IsPlayerNPC(i) || !IsAdmin(i)) continue;
  134.                 SendClientMessage(i, COLOR_LIGHTBLUE, str);
  135.             }
  136.             DeletePVar(playerid, "BR_BugReport");
  137.             return 1;
  138.         }
  139.     }
  140.     return 0;
  141. }
  142.  
  143. stock IsAdmin(playerid) //Check out 'IsAdmin_examples.pwn' so that this function makes more sense ;)
  144. {
  145.     if (IsPlayerAdmin(playerid))
  146.         return true;
  147.     return false;
  148. }
  149.  
  150. stock BugReport(playerid, bugTxt[])
  151. {
  152.     new pName[MAX_PLAYER_NAME];
  153.     new File:bugReportFile = fopen(BUG_REPORT_FILE, io_append);
  154.     new writeStr[200];
  155.     GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
  156.     format(writeStr, 200, "%s|%s\n", pName, bugTxt);
  157.     fwrite(bugReportFile, writeStr);
  158.     fclose(bugReportFile);
  159.     return 1;
  160. }
  161.  
  162. stock GetFileLines(file[])
  163. {
  164.     if (!fexist(file)) return 0;
  165.     new File:readFile = fopen(file, io_read);
  166.     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"
  167.     while (fread(readFile, readStr))
  168.         lines++;
  169.     fclose(readFile);
  170.     return lines;
  171. }
  172.  
  173. stock ShowDialog(playerid, dialogid)
  174. {
  175.     switch (dialogid)
  176.     {
  177.         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");
  178.         case DIALOG_BREPORT_CONFIRM:
  179.         {
  180.             new str[210], bug[100];
  181.             GetPVarString(playerid, "BR_BugReport", bug, 100);
  182.             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);
  183.             ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_MSGBOX, "Bug report: Confirm", str, "Yes", "No");
  184.         }
  185.     }
  186.     return 1;
  187. }
  188.  
  189. CMD:reportbug(playerid, params[])
  190. {
  191.     ShowDialog(playerid, DIALOG_BREPORT);
  192.     return 1;
  193. }
  194.  
  195. CMD:checkbugs(playerid, params[])
  196. {
  197.     if (!IsAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "[ERROR] {FFFFFF}This command is for admins only!");
  198.     if (!fexist(BUG_REPORT_FILE)) return SendClientMessage(playerid, COLOR_GRAY, "[NOTICE] {FFFFFF}There are nog bugs reported");
  199.     for (new i = 0; i < 10; i++) SendClientMessage(playerid, -1, " ");
  200.     SendClientMessage(playerid, COLOR_WHITE, "|---------- {FFFF00}Bug reports {FFFFFF}----------|");
  201.     new File:bugReportFile = fopen(BUG_REPORT_FILE, io_read);
  202.     new readStr[200], str[128], curLine = 1;
  203.     new totalLines = GetFileLines(BUG_REPORT_FILE);
  204.     new start;
  205.     if (totalLines <= 11) start = 1;
  206.     else start = totalLines - 8;
  207.     while (fread(bugReportFile, readStr))
  208.     {
  209.         curLine++;
  210.         if (curLine < start) continue;
  211.         new strName[MAX_PLAYER_NAME], strBug[100];
  212.         sscanf(readStr, "p<|>s[24]s[100]", strName, strBug);
  213.         format(str, 128, "%s: {AFAFAF}%s", strName, strBug);
  214.         SendClientMessage(playerid, COLOR_WHITE, str);
  215.     }
  216.     fclose(bugReportFile);
  217.     return 1;
  218. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement