casefile.pwn 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /*
  2. /$$ /$$ /$$$$$$ /$$$$$$$ /$$$$$$$
  3. | $$$ | $$ /$$__ $$ | $$__ $$| $$__ $$
  4. | $$$$| $$| $$ \__/ | $$ \ $$| $$ \ $$
  5. | $$ $$ $$| $$ /$$$$ /$$$$$$| $$$$$$$/| $$$$$$$/
  6. | $$ $$$$| $$|_ $$|______/| $$__ $$| $$____/
  7. | $$\ $$$| $$ \ $$ | $$ \ $$| $$
  8. | $$ \ $$| $$$$$$/ | $$ | $$| $$
  9. |__/ \__/ \______/ |__/ |__/|__/
  10. Casefile System
  11. Winterfield
  12. Next Generation Gaming, LLC
  13. (created by Next Generation Gaming Development Team)
  14. * Copyright (c) 2016, Next Generation Gaming, LLC
  15. *
  16. * All rights reserved.
  17. *
  18. * Redistribution and use in source and binary forms, with or without modification,
  19. * are not permitted in any case.
  20. *
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  25. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  26. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  27. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  30. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  31. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <YSI\y_hooks>
  35. CMD:casefile(playerid, params[])
  36. {
  37. if(arrGroupData[PlayerInfo[playerid][pMember]][gLEOArrest] != INVALID_RANK && PlayerInfo[playerid][pRank] > arrGroupData[PlayerInfo[playerid][pMember]][gLEOArrest])
  38. {
  39. ShowCasefileDialog(playerid);
  40. }
  41. return 1;
  42. }
  43. CMD:casefiles(playerid, params[])
  44. {
  45. if(arrGroupData[PlayerInfo[playerid][pMember]][gLEOArrest] != INVALID_RANK && PlayerInfo[playerid][pRank] > arrGroupData[PlayerInfo[playerid][pMember]][gLEOArrest])
  46. {
  47. ListCasefiles(playerid, PlayerInfo[playerid][pMember]);
  48. }
  49. return 1;
  50. }
  51. hook OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  52. {
  53. switch(dialogid)
  54. {
  55. case DIALOG_CASEFILE:
  56. {
  57. if(!response) return ShowPlayerDialog(playerid, DIALOG_CASEFILE_QUIT, DIALOG_STYLE_MSGBOX, "Casefile - Cancel", "Are you sure you would like to exit out of the casefile creation?\n(Note: This will reset all of your work)", "Yes", "No");
  58. switch(listitem)
  59. {
  60. case 0: return ShowPlayerDialog(playerid, DIALOG_CASEFILE_NAME, DIALOG_STYLE_INPUT, "Casefile - Name", "Please enter the name of the suspect. (( Firstname_Lastname ))", "Select", "Cancel");
  61. case 1: return ShowPlayerDialog(playerid, DIALOG_CASEFILE_INFO, DIALOG_STYLE_INPUT, "Casefile - Information", "Please enter a description of the casefile. (( Maximum 256 characters. ))", "Select", "Cancel");
  62. case 2:
  63. {
  64. if(!GetPVarType(playerid, "CasefileName")) return ShowPlayerDialog(playerid, DIALOG_CASEFILE_NAME, DIALOG_STYLE_INPUT, "Casefile - Name", "Please enter the name of the suspect. (( Firstname_Lastname ))", "Select", "Cancel");
  65. else if(!GetPVarType(playerid, "CasefileInfo")) return ShowPlayerDialog(playerid, DIALOG_CASEFILE_INFO, DIALOG_STYLE_INPUT, "Casefile - Information", "Please enter a description for the casefile. (( Maximum 256 characters. ))", "Select", "Cancel");
  66. else
  67. {
  68. new CasefileName[MAX_PLAYER_NAME], CasefileInfo[256];
  69. szMiscArray[0] = 0;
  70. GetPVarString(playerid, "CasefileName", CasefileName, sizeof(CasefileName));
  71. GetPVarString(playerid, "CasefileInfo", CasefileInfo, sizeof(CasefileInfo));
  72. mysql_format(MainPipeline, szMiscArray, sizeof(szMiscArray), "INSERT INTO `casefiles` (`suspect`, `issuer`, `information`, `group`, `active`) VALUES (`%s`, `%s`, `%s`, `%d`, `1`)", CasefileName, GetPlayerNameEx(playerid), CasefileInfo, PlayerInfo[playerid][pMember]);
  73. mysql_tquery(MainPipeline, szMiscArray, "OnQueryFinish", "ii", SENDDATA_THREAD, playerid);
  74. }
  75. }
  76. }
  77. }
  78. case DIALOG_CASEFILE_NAME:
  79. {
  80. if(!response) return ShowCasefileDialog(playerid);
  81. else
  82. {
  83. if(strlen(inputtext) == 0)
  84. {
  85. SendClientMessage(playerid, -1, "You have reset the casefile name.");
  86. DeletePVar(playerid, "CasefileName");
  87. }
  88. szMiscArray[0] = 0;
  89. new escapeName[MAX_PLAYER_NAME];
  90. mysql_escape_string(inputtext, escapeName);
  91. SetPVarString(playerid, "CasefileName", escapeName);
  92. mysql_format(MainPipeline, szMiscArray, sizeof(szMiscArray), "SELECT `Username` FROM `accounts` WHERE `Username` = '%e'", inputtext);
  93. mysql_tquery(MainPipeline, szMiscArray, "OnCasefileName", "i", playerid);
  94. }
  95. }
  96. case DIALOG_CASEFILE_INFO:
  97. {
  98. if(!response) return ShowCasefileDialog(playerid);
  99. else
  100. {
  101. if(strlen(inputtext) == 0)
  102. {
  103. DeletePVar(playerid, "CasefileInfo");
  104. return SendClientMessage(playerid, -1, "You have reset the casefile information.");
  105. }
  106. else if(strlen(inputtext) < 257)
  107. {
  108. new escapeName[MAX_PLAYER_NAME];
  109. mysql_escape_string(inputtext, escapeName);
  110. SetPVarString(playerid, "CasefileInfo", escapeName);
  111. ShowCasefileDialog(playerid);
  112. }
  113. }
  114. }
  115. case DIALOG_CASEFILE_QUIT:
  116. {
  117. if(!response) ShowCasefileDialog(playerid);
  118. else
  119. {
  120. DeletePVar(playerid, "CasefileName");
  121. DeletePVar(playerid, "CasefileInfo");
  122. }
  123. }
  124. }
  125. return 1;
  126. }
  127. ShowCasefileDialog(playerid)
  128. {
  129. new string[156], CasefileName[MAX_PLAYER_NAME];
  130. szMiscArray[0] = 0;
  131. if(!GetPVarType(playerid, "CasefileName")) format(CasefileName, sizeof(CasefileName), "Nobody");
  132. else GetPVarString(playerid, "CasefileName", CasefileName, sizeof(CasefileName));
  133. format(string, 156, "%s - Casefile", arrGroupData[PlayerInfo[playerid][pMember]][g_szGroupName]);
  134. format(szMiscArray, sizeof(szMiscArray), "Name: %s\n\
  135. Information\n\
  136. Submit", CasefileName);
  137. return ShowPlayerDialog(playerid, DIALOG_CASEFILE, DIALOG_STYLE_LIST, string, szMiscArray, "Select", "Cancel");
  138. }
  139. ListCasefiles(playerid, group)
  140. {
  141. szMiscArray[0] = 0;
  142. mysql_format(MainPipeline, szMiscArray, sizeof(szMiscArray), "SELECT * FROM `casefiles` WHERE `active` = 1 AND `group` = '%d'", group);
  143. mysql_tquery(MainPipeline, szMiscArray, "OnCasefileList", "i", playerid);
  144. return 1;
  145. }
  146. forward OnCasefileName(playerid);
  147. public OnCasefileName(playerid)
  148. {
  149. if(IsPlayerConnected(playerid))
  150. {
  151. new rows;
  152. cache_get_row_count(rows);
  153. if(rows) return ShowCasefileDialog(playerid);
  154. else
  155. {
  156. DeletePVar(playerid, "CasefileName");
  157. return SendClientMessageEx(playerid, COLOR_WHITE, "This name does not exist.");
  158. }
  159. }
  160. else DeletePVar(playerid, "CasefileName");
  161. return 1;
  162. }
  163. forward OnCasefileList(playerid);
  164. public OnCasefileList(playerid)
  165. {
  166. if(IsPlayerConnected(playerid))
  167. {
  168. new rows;
  169. cache_get_row_count(rows);
  170. if(rows)
  171. {
  172. new PlayerName[MAX_PLAYER_NAME], suspect[MAX_PLAYER_NAME], issuer[MAX_PLAYER_NAME], information[256];
  173. for(new i; i < rows; i++)
  174. {
  175. cache_get_value_name(i, "suspect", suspect);
  176. cache_get_value_name(i, "issuer", issuer);
  177. cache_get_value_name(i, "information", information);
  178. foreach(new d: Player)
  179. {
  180. GetPlayerName(d, PlayerName, sizeof(PlayerName));
  181. if(strfind(PlayerName, suspect, true) != -1)
  182. {
  183. format(szMiscArray, sizeof szMiscArray, "%s (ID: %d) | Issuer: %s | Information: %s", GetPlayerNameEx(d), d, issuer, information);
  184. SendClientMessageEx(playerid, COLOR_GREEN, szMiscArray);
  185. }
  186. }
  187. }
  188. for(new i; i < rows; i++)
  189. {
  190. cache_get_value_name(i, "suspect", suspect);
  191. cache_get_value_name(i, "issuer", issuer);
  192. cache_get_value_name(i, "information", information);
  193. format(szMiscArray, sizeof szMiscArray, "%s | Issuer: %s | Information: %s",suspect, issuer, information);
  194. SendClientMessageEx(playerid, COLOR_GREY, szMiscArray);
  195. }
  196. }
  197. else return SendClientMessageEx(playerid, COLOR_WHITE, "Your group does not have any casefiles.");
  198. }
  199. return 1;
  200. }