1
0

MetalDetectors.pwn 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. #include <YSI\y_hooks>
  2. hook OnPlayerEnterDynamicArea(playerid, areaid)
  3. {
  4. new i = MetDet_GetIDFromArea(areaid);
  5. if(i == -1) return 1;
  6. new wepid, iammo;
  7. for(new idx = 0; idx <= 12; ++idx)
  8. {
  9. GetPlayerWeaponData(playerid, idx, wepid, iammo);
  10. switch(wepid)
  11. {
  12. case 24 .. 40: { MetDet_Alarm(i); break; }
  13. }
  14. }
  15. return 1;
  16. }
  17. hook OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
  18. if(arrAntiCheat[playerid][ac_iFlags][AC_DIALOGSPOOFING] > 0) return 1;
  19. switch(dialogid)
  20. {
  21. case DIALOG_METDET_LIST:
  22. {
  23. if(response)
  24. {
  25. new Float:fPos[3],
  26. iAssignData[2];
  27. GetDynamicObjectPos(arrMetalDetector[listitem][metdet_iObjectID], fPos[0], fPos[1], fPos[2]);
  28. iAssignData[0] = Streamer_GetIntData(STREAMER_TYPE_OBJECT, arrMetalDetector[listitem][metdet_iObjectID], E_STREAMER_WORLD_ID);
  29. iAssignData[1] = Streamer_GetIntData(STREAMER_TYPE_OBJECT, arrMetalDetector[listitem][metdet_iObjectID], E_STREAMER_INTERIOR_ID);
  30. SetPlayerPos(playerid, fPos[0], fPos[1], fPos[2]);
  31. SetPlayerVirtualWorld(playerid, iAssignData[0]);
  32. SetPlayerInterior(playerid, iAssignData[1]);
  33. }
  34. }
  35. }
  36. return 0;
  37. }
  38. MetDet_CreateMetDet(playerid)
  39. {
  40. new Float:fPos[3],
  41. iVW = GetPlayerVirtualWorld(playerid),
  42. iINT = GetPlayerInterior(playerid);
  43. GetPlayerPos(playerid, fPos[0], fPos[1], fPos[2]);
  44. for(new i; i < MAX_METALDETECTORS; ++i)
  45. {
  46. if(!IsValidDynamicObject(arrMetalDetector[i][metdet_iObjectID]))
  47. {
  48. mysql_format(MainPipeline, szMiscArray, sizeof(szMiscArray), "INSERT INTO `metaldetectors` (`id`, `posx`, `posy`, `posz`, `rotx`, `roty`, `rotz`, `vw`, `int`)\
  49. VALUES (%d, %f, %f, %f, %f, %f, %f, %i, %i)", i, fPos[0], fPos[1], fPos[2], 0.0, 0.0, 0.0, iVW, iINT);
  50. mysql_tquery(MainPipeline, szMiscArray, "MetDet_OnCreateMetDet", "iifffii", playerid, i, fPos[0], fPos[1], fPos[2], iVW, iINT);
  51. return 1;
  52. }
  53. }
  54. return SendClientMessageEx(playerid, COLOR_GRAD1, "You have reached the maximum metal detector spawn quotum.");
  55. }
  56. forward MetDet_OnCreateMetDet(playerid, i, Float:X, Float:Y, Float:Z, iVW, iINT);
  57. public MetDet_OnCreateMetDet(playerid, i, Float:X, Float:Y, Float:Z, iVW, iINT)
  58. {
  59. format(szMiscArray, sizeof(szMiscArray), "Successfully created a Metal Detector with ID %d", i);
  60. SendClientMessageEx(playerid, COLOR_WHITE, szMiscArray);
  61. MetDet_Process(i, X, Y, Z, 0.0, 0.0, 0.0, iVW, iINT);
  62. return 1;
  63. }
  64. MetDet_DeleteMetDet(playerid, i)
  65. {
  66. if(!IsValidDynamicObject(arrMetalDetector[i][metdet_iObjectID])) return SendClientMessageEx(playerid, COLOR_GRAD1, "This is an invalid metal detector ID.");
  67. mysql_format(MainPipeline, szMiscArray, sizeof(szMiscArray), "DELETE FROM `metaldetectors` WHERE `id` = %d", i);
  68. return mysql_tquery(MainPipeline, szMiscArray, "MetDet_OnDeleteMetDet", "ii", playerid, i);
  69. }
  70. forward MetDet_OnDeleteMetDet(playerid, i);
  71. public MetDet_OnDeleteMetDet(playerid, i)
  72. {
  73. if(mysql_errno(MainPipeline) == 1) return SendClientMessageEx(playerid, COLOR_GRAD1, "Your query could not be processed.");
  74. DestroyDynamicObject(arrMetalDetector[i][metdet_iObjectID]);
  75. DestroyDynamic3DTextLabel(arrMetalDetector[i][metdet_iTextID]);
  76. DestroyDynamicArea(arrMetalDetector[i][metdet_iAreaID]);
  77. return 1;
  78. }
  79. MetDet_CheckMetDets(playerid)
  80. {
  81. return mysql_tquery(MainPipeline, "SELECT * FROM `metaldetectors` WHERE 1", "MetDet_OnCheckMetDets", "i", playerid);
  82. }
  83. forward MetDet_OnCheckMetDets(playerid);
  84. public MetDet_OnCheckMetDets(playerid)
  85. {
  86. szMiscArray[0] = 0;
  87. new iRows, value;
  88. cache_get_row_count(iRows);
  89. if(!iRows) return SendClientMessageEx(playerid, COLOR_GRAD1, "There are no metaldetectors in the database.");
  90. for(new row; row < iRows; ++row)
  91. {
  92. format(szMiscArray, sizeof(szMiscArray), "%sMetal Detector ID: %d\n", szMiscArray, cache_get_value_name_int(row, "id", value));
  93. }
  94. ShowPlayerDialogEx(playerid, DIALOG_METDET_LIST, DIALOG_STYLE_LIST, "Metal Detectors | Listing all", szMiscArray, "Select", "");
  95. return 1;
  96. }
  97. MetDet_LoadMetDets()
  98. {
  99. return mysql_tquery(MainPipeline, "SELECT * FROM `metaldetectors` WHERE 1", "MetDet_OnLoadMetDets", "");
  100. }
  101. forward MetDet_OnLoadMetDets();
  102. public MetDet_OnLoadMetDets()
  103. {
  104. new iRows,
  105. iCount,
  106. value,
  107. Float:fValue;
  108. cache_get_row_count(iRows);
  109. if(!iRows) return print("[Metal Detectors] There are no metaldetectors in the database.");
  110. while(iCount < iRows)
  111. {
  112. MetDet_Process(iCount, cache_get_value_name_float(iCount, "posx", fValue), cache_get_value_name_float(iCount, "posy", fValue), cache_get_value_name_float(iCount, "posz", fValue),
  113. cache_get_value_name_float(iCount, "rotx", fValue), cache_get_value_name_float(iCount, "roty", fValue), cache_get_value_name_float(iCount, "rotz", fValue),
  114. cache_get_value_name_int(iCount, "vw", value), cache_get_value_name_int(iCount, "int", value));
  115. iCount++;
  116. }
  117. printf("[Metal Detectors] Successfully loaded %d metal detectors", iCount);
  118. return 1;
  119. }
  120. MetDet_Process(id, Float:X = 0.0, Float:Y = 0.0, Float:Z = 0.0, Float:RX = 0.0, Float:RY = 0.0, Float:RZ = 0.0, iVW = 0, iINT = 0)
  121. {
  122. if(IsValidDynamicObject(arrMetalDetector[id][metdet_iObjectID])) DestroyDynamicObject(arrMetalDetector[id][metdet_iObjectID]);
  123. arrMetalDetector[id][metdet_iObjectID] = CreateDynamicObject(1892, X-0.6, Y, Z, RX, RY, RZ, .worldid = iVW, .interiorid = iINT);
  124. if(IsValidDynamic3DTextLabel(arrMetalDetector[id][metdet_iTextID])) DestroyDynamic3DTextLabel(arrMetalDetector[id][metdet_iTextID]);
  125. format(szMiscArray, sizeof(szMiscArray), "Metal Detector (ID: %d)\n\n{FFFF00}Normal", id);
  126. arrMetalDetector[id][metdet_iTextID] = CreateDynamic3DTextLabel(szMiscArray, COLOR_WHITE, X, Y, Z+1.0, 10.0);
  127. if(IsValidDynamicArea(arrMetalDetector[id][metdet_iAreaID])) DestroyDynamicArea(arrMetalDetector[id][metdet_iAreaID]);
  128. arrMetalDetector[id][metdet_iAreaID] = CreateDynamicSphere(X, Y, Z, 3.0, .worldid = iVW, .interiorid = iINT);
  129. // Streamer_SetIntData(STREAMER_TYPE_AREA, arrMetalDetector[id][metdet_iAreaID], E_STREAMER_EXTRA_ID, id);
  130. }
  131. MetDet_Alarm(i)
  132. {
  133. // ProxDetector(20.0, playerid, "** [Metal Detector]: ** ALARM **", COLOR_LIGHTRED, COLOR_LIGHTRED, COLOR_LIGHTRED, COLOR_LIGHTRED, COLOR_LIGHTRED);
  134. UpdateDynamic3DTextLabelText(arrMetalDetector[i][metdet_iTextID], COLOR_WHITE, "Metal Detector \n\n{FF0000}** ALARM **");
  135. SetTimerEx("MetDet_Restore", 5000, false, "i", i);
  136. }
  137. forward MetDet_Restore(i);
  138. public MetDet_Restore(i)
  139. {
  140. szMiscArray[0] = 0;
  141. format(szMiscArray, sizeof(szMiscArray), "Metal Detector (ID: %d)\n\n{FFFF00}Normal", i);
  142. UpdateDynamic3DTextLabelText(arrMetalDetector[i][metdet_iTextID], COLOR_WHITE, szMiscArray);
  143. }
  144. MetDet_GetIDFromArea(areaid) {
  145. for(new i; i < MAX_METALDETECTORS; ++i) {
  146. if(areaid == arrMetalDetector[i][metdet_iAreaID]) return i;
  147. }
  148. return -1;
  149. }
  150. MetDet_SaveMetDet(id)
  151. {
  152. new Float:fPos[6],
  153. iAssignData[2];
  154. GetDynamicObjectPos(arrMetalDetector[id][metdet_iObjectID], fPos[0], fPos[1], fPos[2]);
  155. GetDynamicObjectRot(arrMetalDetector[id][metdet_iObjectID], fPos[3], fPos[4], fPos[5]);
  156. iAssignData[0] = Streamer_GetIntData(STREAMER_TYPE_OBJECT, arrMetalDetector[id][metdet_iObjectID], E_STREAMER_WORLD_ID);
  157. iAssignData[1] = Streamer_GetIntData(STREAMER_TYPE_OBJECT, arrMetalDetector[id][metdet_iObjectID], E_STREAMER_INTERIOR_ID);
  158. mysql_format(MainPipeline, szMiscArray, sizeof(szMiscArray), "UPDATE `metaldetectors` SET `posx` = %f, `posy` = %f, `posz` = %f, `rotx` = %f, `roty` = %f, `rotz` = %f, `vw` = %d, `int` = %d WHERE id = %d",
  159. fPos[0], fPos[1], fPos[2], fPos[3], fPos[4], fPos[5], iAssignData[0], iAssignData[1], id);
  160. mysql_tquery(MainPipeline, szMiscArray, "MetDet_OnSaveMetDets", "i", id);
  161. }
  162. forward MetDet_OnSaveMetDet(id);
  163. public MetDet_OnSaveMetDet(id)
  164. {
  165. if(mysql_errno(MainPipeline) == 1) return printf("[Metal Detectors] Something went wrong when saving ID %d", id);
  166. return 1;
  167. }
  168. CMD:createmetaldetector(playerid, params[])
  169. {
  170. if(PlayerInfo[playerid][pAdmin] > 2) MetDet_CreateMetDet(playerid);
  171. else SendClientMessageEx(playerid, COLOR_GRAD1, "You are not authorized to use this command.");
  172. return 1;
  173. }
  174. CMD:metaldetector(playerid, params[])
  175. {
  176. new Float:fPos[3],
  177. choice[16],
  178. id,
  179. amount,
  180. iAssignData[2];
  181. if(PlayerInfo[playerid][pAdmin] < 2) return SendClientMessageEx(playerid, COLOR_GRAD1, "You are not authorized to use this command.");
  182. if(sscanf(params, "s[32]dD(1)", choice, id, amount))
  183. {
  184. SendClientMessageEx(playerid, COLOR_GRAD1, "Usage: /metaldetector [choice] [ID] [value]");
  185. return SendClientMessageEx(playerid, COLOR_GRAD1, "Available names: tome, goto, Position, Delete");
  186. }
  187. if(!IsValidDynamicObject(arrMetalDetector[id][metdet_iObjectID])) return SendClientMessageEx(playerid, COLOR_GRAD1, "This metal detector doesn't exist.");
  188. if(strcmp(choice, "tome", true) == 0)
  189. {
  190. GetPlayerPos(playerid, fPos[0], fPos[1], fPos[2]);
  191. MetDet_Process(id, fPos[0], fPos[1], fPos[2], 0.0, 0.0, 0.0, GetPlayerVirtualWorld(playerid), GetPlayerInterior(playerid));
  192. MetDet_SaveMetDet(id);
  193. }
  194. if(strcmp(choice, "goto", true) == 0)
  195. {
  196. GetDynamicObjectPos(arrMetalDetector[id][metdet_iObjectID], fPos[0], fPos[1], fPos[2]);
  197. iAssignData[0] = Streamer_GetIntData(STREAMER_TYPE_OBJECT, arrMetalDetector[id][metdet_iObjectID], E_STREAMER_WORLD_ID);
  198. iAssignData[1] = Streamer_GetIntData(STREAMER_TYPE_OBJECT, arrMetalDetector[id][metdet_iObjectID], E_STREAMER_INTERIOR_ID);
  199. SetPlayerPos(playerid, fPos[0], fPos[1], fPos[2]);
  200. SetPlayerVirtualWorld(playerid, iAssignData[0]);
  201. SetPlayerInterior(playerid, iAssignData[1]);
  202. }
  203. if(strcmp(choice, "position", true) == 0)
  204. {
  205. GetPlayerPos(playerid, fPos[0], fPos[1], fPos[2]);
  206. if(!IsPlayerInRangeOfPoint(playerid, 10.0, fPos[0], fPos[1], fPos[2])) return SendClientMessageEx(playerid, COLOR_GRAD1, "You are not in range of the metal detector.");
  207. SetPVarInt(playerid, PVAR_EMETDET, id);
  208. EditDynamicObject(playerid, arrMetalDetector[id][metdet_iObjectID]);
  209. }
  210. if(strcmp(choice, "delete", true) == 0)
  211. {
  212. MetDet_DeleteMetDet(playerid, id);
  213. }
  214. return 1;
  215. }
  216. CMD:metdets(playerid, params[])
  217. {
  218. if(PlayerInfo[playerid][pAdmin] > 2) MetDet_CheckMetDets(playerid);
  219. else SendClientMessageEx(playerid, COLOR_GRAD1, "You are not authorized to use this command.");
  220. return 1;
  221. }