1
0

impound.pwn 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /*
  2. /$$ /$$ /$$$$$$ /$$$$$$$ /$$$$$$$
  3. | $$$ | $$ /$$__ $$ | $$__ $$| $$__ $$
  4. | $$$$| $$| $$ \__/ | $$ \ $$| $$ \ $$
  5. | $$ $$ $$| $$ /$$$$ /$$$$$$| $$$$$$$/| $$$$$$$/
  6. | $$ $$$$| $$|_ $$|______/| $$__ $$| $$____/
  7. | $$\ $$$| $$ \ $$ | $$ \ $$| $$
  8. | $$ \ $$| $$$$$$/ | $$ | $$| $$
  9. |__/ \__/ \______/ |__/ |__/|__/
  10. Dynamic Impound System
  11. Next Generation Gaming, LLC
  12. (created by Next Generation Gaming Development Team)
  13. * Copyright (c) 2016, Next Generation Gaming, LLC
  14. *
  15. * All rights reserved.
  16. *
  17. * Redistribution and use in source and binary forms, with or without modification,
  18. * are not permitted in any case.
  19. *
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  25. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  26. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  27. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. CMD:impoundedit(playerid, params[])
  34. {
  35. if (PlayerInfo[playerid][pAdmin] >= 4 || PlayerInfo[playerid][pASM] >= 1 || PlayerInfo[playerid][pFactionModerator] >= 1)
  36. {
  37. new string[128], choice[32], id, amount;
  38. if(sscanf(params, "s[32]dD", choice, id, amount))
  39. {
  40. SendClientMessageEx(playerid, COLOR_GREY, "USAGE: /impoundedit [name] [id] [amount]");
  41. SendClientMessageEx(playerid, COLOR_GREY, "Available names: Position, Delete");
  42. return 1;
  43. }
  44. if(id >= MAX_IMPOUNDPOINTS)
  45. {
  46. SendClientMessageEx(playerid, COLOR_WHITE, "Invalid Impound Points ID!");
  47. return 1;
  48. }
  49. if(strcmp(choice, "position", true) == 0)
  50. {
  51. GetPlayerPos(playerid, ImpoundPoints[id][impoundPosX], ImpoundPoints[id][impoundPosY], ImpoundPoints[id][impoundPosZ]);
  52. ImpoundPoints[id][impoundInt] = GetPlayerInterior(playerid);
  53. ImpoundPoints[id][impoundVW] = GetPlayerVirtualWorld(playerid);
  54. format(string, sizeof(string), "You have changed the position on impound Point #%d.", id);
  55. SendClientMessageEx(playerid, COLOR_WHITE, string);
  56. DestroyDynamic3DTextLabel(ImpoundPoints[id][impoundTextID]);
  57. format(string, sizeof(string), "Impound Yard #%d\nType /impound to impound a vehicle", id);
  58. ImpoundPoints[id][impoundTextID] = CreateDynamic3DTextLabel(string, COLOR_YELLOW, ImpoundPoints[id][impoundPosX], ImpoundPoints[id][impoundPosY], ImpoundPoints[id][impoundPosZ]+0.6, 5.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, ImpoundPoints[id][impoundVW], ImpoundPoints[id][impoundInt], -1);
  59. SaveImpoundPoint(id);
  60. format(string, sizeof(string), "%s has edited Impound Point ID %d's position.", GetPlayerNameEx(playerid), id);
  61. Log("logs/impoundedit.log", string);
  62. return 1;
  63. }
  64. else if(strcmp(choice, "delete", true) == 0)
  65. {
  66. if(ImpoundPoints[id][impoundPosX] == 0)
  67. {
  68. format(string, sizeof(string), "Impound Point #%d does not exist.", id);
  69. SendClientMessageEx(playerid, COLOR_WHITE, string);
  70. return 1;
  71. }
  72. DestroyDynamic3DTextLabel(ImpoundPoints[id][impoundTextID]);
  73. ImpoundPoints[id][impoundPosX] = 0.0;
  74. ImpoundPoints[id][impoundPosY] = 0.0;
  75. ImpoundPoints[id][impoundPosZ] = 0.0;
  76. ImpoundPoints[id][impoundVW] = 0;
  77. ImpoundPoints[id][impoundInt] = 0;
  78. SaveImpoundPoint(id);
  79. format(string, sizeof(string), "You have deleted Impound Point #%d.", id);
  80. SendClientMessageEx(playerid, COLOR_WHITE, string);
  81. format(string, sizeof(string), "%s has deleted Impound Point ID %d.", GetPlayerNameEx(playerid), id);
  82. Log("logs/impoundedit.log", string);
  83. return 1;
  84. }
  85. }
  86. else SendClientMessageEx(playerid, COLOR_GRAD1, "You are not authorized to use that command.");
  87. return 1;
  88. }
  89. CMD:impoundstatus(playerid, params[])
  90. {
  91. new id;
  92. if(sscanf(params, "i", id))
  93. {
  94. SendClientMessageEx(playerid, COLOR_GREY, "USAGE: /impoundstatus [id]");
  95. return 1;
  96. }
  97. if (PlayerInfo[playerid][pAdmin] >= 4 || PlayerInfo[playerid][pASM] >= 1 || PlayerInfo[playerid][pFactionModerator] >= 1)
  98. {
  99. new string[128];
  100. format(string,sizeof(string),"|___________ Impound Point Status (ID: %d) ___________|", id);
  101. SendClientMessageEx(playerid, COLOR_GREEN, string);
  102. format(string, sizeof(string), "[Position] X: %f | Y: %f | Z: %f | VW: %d | Int: %d", ImpoundPoints[id][impoundPosX], ImpoundPoints[id][impoundPosY], ImpoundPoints[id][impoundPosZ], ImpoundPoints[id][impoundVW], ImpoundPoints[id][impoundInt]);
  103. SendClientMessageEx(playerid, COLOR_WHITE, string);
  104. }
  105. else
  106. {
  107. SendClientMessageEx(playerid, COLOR_GRAD1, "You are not authorized to use that command.");
  108. }
  109. return 1;
  110. }
  111. CMD:impoundnext(playerid, params[])
  112. {
  113. if(PlayerInfo[playerid][pAdmin] >= 4 || PlayerInfo[playerid][pASM] >= 1 || PlayerInfo[playerid][pFactionModerator] == 2)
  114. {
  115. SendClientMessageEx(playerid, COLOR_RED, "* Listing next available Impound Point...");
  116. for(new x = 0; x < MAX_IMPOUNDPOINTS; x++)
  117. {
  118. if(ImpoundPoints[x][impoundPosX] == 0)
  119. {
  120. new string[128];
  121. format(string, sizeof(string), "%d is available to use.", x);
  122. SendClientMessageEx(playerid, COLOR_WHITE, string);
  123. break;
  124. }
  125. }
  126. }
  127. else
  128. {
  129. SendClientMessageEx(playerid, COLOR_GRAD2, "You are not authorized to use that command.");
  130. return 1;
  131. }
  132. return 1;
  133. }
  134. CMD:gotoimpoundpoint(playerid, params[])
  135. {
  136. if(PlayerInfo[playerid][pAdmin] >= 4 || PlayerInfo[playerid][pASM] >= 1 || PlayerInfo[playerid][pFactionModerator] >= 1)
  137. {
  138. new id;
  139. if(sscanf(params, "d", id)) return SendClientMessageEx(playerid, COLOR_GREY, "USAGE: /gotoimpoundpoint [id]");
  140. SetPlayerPos(playerid, ImpoundPoints[id][impoundPosX], ImpoundPoints[id][impoundPosY], ImpoundPoints[id][impoundPosZ]);
  141. SetPlayerInterior(playerid, ImpoundPoints[id][impoundInt]);
  142. PlayerInfo[playerid][pInt] = ImpoundPoints[id][impoundInt];
  143. SetPlayerVirtualWorld(playerid, ImpoundPoints[id][impoundVW]);
  144. PlayerInfo[playerid][pVW] = ImpoundPoints[id][impoundVW];
  145. }
  146. return 1;
  147. }
  148. stock IsAtImpoundingPoint(playerid)
  149. {
  150. if(IsPlayerConnected(playerid))
  151. {
  152. for(new x; x < MAX_IMPOUNDPOINTS; x++)
  153. {
  154. if(ImpoundPoints[x][impoundPosX] != 0)
  155. {
  156. if(IsPlayerInRangeOfPoint(playerid, 4.0, ImpoundPoints[x][impoundPosX], ImpoundPoints[x][impoundPosY], ImpoundPoints[x][impoundPosZ]) && GetPlayerInterior(playerid) == ImpoundPoints[x][impoundInt] && GetPlayerVirtualWorld(playerid) == ImpoundPoints[x][impoundVW]) return 1;
  157. }
  158. }
  159. }
  160. return 0;
  161. }
  162. stock SaveImpoundPoint(id)
  163. {
  164. new string[1024];
  165. mysql_format(MainPipeline, string, sizeof(string), "UPDATE `impoundpoints` SET \
  166. `PosX`=%f, \
  167. `PosY`=%f, \
  168. `PosZ`=%f, \
  169. `VW`=%d, \
  170. `Int`=%d WHERE `id`=%d",
  171. ImpoundPoints[id][impoundPosX],
  172. ImpoundPoints[id][impoundPosY],
  173. ImpoundPoints[id][impoundPosZ],
  174. ImpoundPoints[id][impoundVW],
  175. ImpoundPoints[id][impoundInt],
  176. id
  177. );
  178. mysql_tquery(MainPipeline, string, "OnQueryFinish", "i", SENDDATA_THREAD);
  179. }
  180. stock SaveImpoundPoints()
  181. {
  182. for(new i = 0; i < MAX_ImpoundPoints; i++)
  183. {
  184. SaveImpoundPoint(i);
  185. }
  186. return 1;
  187. }
  188. stock RehashImpoundPoint(id)
  189. {
  190. DestroyDynamic3DTextLabel(ImpoundPoints[id][impoundTextID]);
  191. ImpoundPoints[id][impoundSQLId] = -1;
  192. ImpoundPoints[id][impoundPosX] = 0.0;
  193. ImpoundPoints[id][impoundPosY] = 0.0;
  194. ImpoundPoints[id][impoundPosZ] = 0.0;
  195. ImpoundPoints[id][impoundVW] = 0;
  196. ImpoundPoints[id][impoundInt] = 0;
  197. LoadImpoundPoint(id);
  198. }
  199. stock RehashImpoundPoints()
  200. {
  201. printf("[RehashImpoundPoints] Deleting impound Points from server...");
  202. for(new i = 0; i < MAX_ImpoundPoints; i++)
  203. {
  204. RehashImpoundPoint(i);
  205. }
  206. LoadImpoundPoints();
  207. }
  208. stock LoadImpoundPoint(id)
  209. {
  210. new string[128];
  211. format(string, sizeof(string), "SELECT * FROM `impoundpoints` WHERE `id`=%d", id);
  212. mysql_tquery(MainPipeline, string, "OnLoadImpoundPoint", "i", id);
  213. }
  214. stock LoadImpoundPoints()
  215. {
  216. printf("[LoadImpoundPoints] Loading data from database...");
  217. mysql_tquery(MainPipeline, "SELECT * FROM `impoundpoints`", "OnLoadImpoundPoints", "");
  218. }
  219. forward OnLoadImpoundPoint(index);
  220. public OnLoadImpoundPoint(index)
  221. {
  222. new rows;
  223. szMiscArray[0] = 0;
  224. cache_get_row_count(rows);
  225. for(new row; row < rows; row++)
  226. {
  227. cache_get_value_name_int(row, "id", ImpoundPoints[index][impoundSQLId]);
  228. cache_get_value_name_float(row, "PosX", ImpoundPoints[index][impoundPosX]);
  229. cache_get_value_name_float(row, "PosY", ImpoundPoints[index][impoundPosY]);
  230. cache_get_value_name_float(row, "PosZ", ImpoundPoints[index][impoundPosZ]);
  231. cache_get_value_name_int(row, "VW", ImpoundPoints[index][impoundVW]);
  232. cache_get_value_name_int(row, "Int", ImpoundPoints[index][impoundInt]);
  233. if(ImpoundPoints[index][impoundPosX] != 0)
  234. {
  235. format(szMiscArray, sizeof(szMiscArray), "Impound Yard #%d\nType /impound to impound a vehicle", index);
  236. ImpoundPoints[index][impoundTextID] = CreateDynamic3DTextLabel(szMiscArray, COLOR_YELLOW, ImpoundPoints[index][impoundPosX], ImpoundPoints[index][impoundPosY], ImpoundPoints[index][impoundPosZ]+0.6, 5.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, ImpoundPoints[index][impoundVW], ImpoundPoints[index][impoundInt], -1);
  237. }
  238. }
  239. return 1;
  240. }
  241. forward OnLoadImpoundPoints();
  242. public OnLoadImpoundPoints()
  243. {
  244. new i, rows;
  245. szMiscArray[0] = 0;
  246. cache_get_row_count(rows);
  247. while(i < rows)
  248. {
  249. /*ImpoundPoints[i][impoundSQLId] = cache_get_field_content_int(i, "id", MainPipeline);
  250. ImpoundPoints[i][impoundPosX] = cache_get_field_content_float(i, "PosX", MainPipeline);
  251. ImpoundPoints[i][impoundPosY] = cache_get_field_content_float(i, "PosY", MainPipeline);
  252. ImpoundPoints[i][impoundPosZ] = cache_get_field_content_float(i, "PosZ", MainPipeline);
  253. ImpoundPoints[i][impoundVW] = cache_get_field_content_int(i, "VW", MainPipeline);
  254. ImpoundPoints[i][impoundInt] = cache_get_field_content_int(i, "Int", MainPipeline);
  255. if(ImpoundPoints[i][impoundPosX] != 0)
  256. {
  257. format(szMiscArray, sizeof(szMiscArray), "Impound Yard #%d\nType /impound to impound a vehicle", i);
  258. ImpoundPoints[i][impoundTextID] = CreateDynamic3DTextLabel(szMiscArray, COLOR_YELLOW, ImpoundPoints[i][impoundPosX], ImpoundPoints[i][impoundPosY], ImpoundPoints[i][impoundPosZ]+0.6, 5.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, ImpoundPoints[i][impoundVW], ImpoundPoints[i][impoundInt], -1);
  259. }*/
  260. LoadImpoundPoint(i);
  261. i++;
  262. }
  263. }