mapicons.pwn 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /*
  2. /$$ /$$ /$$$$$$ /$$$$$$$ /$$$$$$$
  3. | $$$ | $$ /$$__ $$ | $$__ $$| $$__ $$
  4. | $$$$| $$| $$ \__/ | $$ \ $$| $$ \ $$
  5. | $$ $$ $$| $$ /$$$$ /$$$$$$| $$$$$$$/| $$$$$$$/
  6. | $$ $$$$| $$|_ $$|______/| $$__ $$| $$____/
  7. | $$\ $$$| $$ \ $$ | $$ \ $$| $$
  8. | $$ \ $$| $$$$$$/ | $$ | $$| $$
  9. |__/ \__/ \______/ |__/ |__/|__/
  10. Map Icon 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. stock LoadDynamicMapIcon(mapiconid)
  34. {
  35. new string[128];
  36. mysql_format(MainPipeline, string, sizeof(string), "SELECT * FROM `dmapicons` WHERE `id`=%d", mapiconid);
  37. mysql_tquery(MainPipeline, string, "OnLoadDynamicMapIcon", "i", mapiconid);
  38. }
  39. stock LoadDynamicMapIcons()
  40. {
  41. printf("[LoadDynamicMapIcons] Loading data from database...");
  42. mysql_tquery(MainPipeline, "SELECT * FROM `dmapicons`", "OnLoadDynamicMapIcons", "");
  43. }
  44. forward OnLoadDynamicMapIcon(index);
  45. public OnLoadDynamicMapIcon(index)
  46. {
  47. new rows;
  48. cache_get_row_count(rows);
  49. for(new row; row < rows; row++)
  50. {
  51. cache_get_value_name_int(row, "id", DMPInfo[index][dmpSQLId]);
  52. cache_get_value_name_int(row, "MarkerType", DMPInfo[index][dmpMarkerType]);
  53. cache_get_value_name_int(row, "Color", DMPInfo[index][dmpColor]);
  54. cache_get_value_name_int(row, "VW", DMPInfo[index][dmpVW]);
  55. cache_get_value_name_int(row, "Int", DMPInfo[index][dmpInt]);
  56. cache_get_value_name_float(row, "PosX", DMPInfo[index][dmpPosX]);
  57. cache_get_value_name_float(row, "PosY", DMPInfo[index][dmpPosY]);
  58. cache_get_value_name_float(row, "PosZ", DMPInfo[index][dmpPosZ]);
  59. if(DMPInfo[index][dmpPosX] != 0.0)
  60. {
  61. if(DMPInfo[index][dmpMarkerType] != 0) DMPInfo[index][dmpMapIconID] = CreateDynamicMapIcon(DMPInfo[index][dmpPosX], DMPInfo[index][dmpPosY], DMPInfo[index][dmpPosZ], DMPInfo[index][dmpMarkerType], DMPInfo[index][dmpColor], DMPInfo[index][dmpVW], DMPInfo[index][dmpInt], -1, 500.0);
  62. }
  63. }
  64. return 1;
  65. }
  66. forward OnLoadDynamicMapIcons();
  67. public OnLoadDynamicMapIcons()
  68. {
  69. new i, rows;
  70. cache_get_row_count(rows);
  71. while(i < rows)
  72. {
  73. /*DMPInfo[i][dmpSQLId] = cache_get_field_content_int(i, "id", MainPipeline);
  74. DMPInfo[i][dmpMarkerType] = cache_get_field_content_int(i, "MarkerType", MainPipeline);
  75. DMPInfo[i][dmpColor] = cache_get_field_content_int(i, "Color", MainPipeline);
  76. DMPInfo[i][dmpVW] = cache_get_field_content_int(i, "VW", MainPipeline);
  77. DMPInfo[i][dmpInt] = cache_get_field_content_int(i, "Int", MainPipeline);
  78. DMPInfo[i][dmpPosX] = cache_get_field_content_float(i, "PosX", MainPipeline);
  79. DMPInfo[i][dmpPosY] = cache_get_field_content_float(i, "PosY", MainPipeline);
  80. DMPInfo[i][dmpPosZ] = cache_get_field_content_float(i, "PosZ", MainPipeline);
  81. if(DMPInfo[i][dmpPosX] != 0.0)
  82. {
  83. if(DMPInfo[i][dmpMarkerType] != 0) DMPInfo[i][dmpMapIconID] = CreateDynamicMapIcon(DMPInfo[i][dmpPosX], DMPInfo[i][dmpPosY], DMPInfo[i][dmpPosZ], DMPInfo[i][dmpMarkerType], DMPInfo[i][dmpColor], DMPInfo[i][dmpVW], DMPInfo[i][dmpInt], -1, 500.0);
  84. }*/
  85. LoadDynamicMapIcon(i);
  86. i++;
  87. }
  88. if(i > 0) printf("[LoadDynamicMapIcons] %d map icons rehashed/loaded.", i);
  89. else printf("[LoadDynamicMapIcons] Failed to load any map icons.");
  90. return 1;
  91. }
  92. stock SaveDynamicMapIcon(mapiconid)
  93. {
  94. new string[512];
  95. mysql_format(MainPipeline, string, sizeof(string), "UPDATE `dmapicons` SET \
  96. `MarkerType`=%d, \
  97. `Color`=%d, \
  98. `VW`=%d, \
  99. `Int`=%d, \
  100. `PosX`=%f, \
  101. `PosY`=%f, \
  102. `PosZ`=%f WHERE `id`=%d",
  103. DMPInfo[mapiconid][dmpMarkerType],
  104. DMPInfo[mapiconid][dmpColor],
  105. DMPInfo[mapiconid][dmpVW],
  106. DMPInfo[mapiconid][dmpInt],
  107. DMPInfo[mapiconid][dmpPosX],
  108. DMPInfo[mapiconid][dmpPosY],
  109. DMPInfo[mapiconid][dmpPosZ],
  110. DMPInfo[mapiconid][dmpSQLId]
  111. ); // Array starts from zero, MySQL starts at 1 (this is why we are adding one).
  112. mysql_tquery(MainPipeline, string, "OnQueryFinish", "i", SENDDATA_THREAD);
  113. }
  114. stock SaveDynamicMapIcons()
  115. {
  116. for(new i = 1; i < MAX_DMAPICONS; i++)
  117. {
  118. SaveDynamicMapIcon(i);
  119. }
  120. return 1;
  121. }
  122. stock RehashDynamicMapIcon(mapiconid)
  123. {
  124. if(IsValidDynamicMapIcon(DMPInfo[mapiconid][dmpMapIconID])) DestroyDynamicMapIcon(DMPInfo[mapiconid][dmpMapIconID]);
  125. DMPInfo[mapiconid][dmpMarkerType] = 0;
  126. DMPInfo[mapiconid][dmpColor] = 0;
  127. DMPInfo[mapiconid][dmpVW] = 0;
  128. DMPInfo[mapiconid][dmpInt] = 0;
  129. DMPInfo[mapiconid][dmpPosX] = 0.0;
  130. DMPInfo[mapiconid][dmpPosY] = 0.0;
  131. DMPInfo[mapiconid][dmpPosZ] = 0.0;
  132. LoadDynamicMapIcon(mapiconid);
  133. }
  134. stock RehashDynamicMapIcons()
  135. {
  136. printf("[RehashDynamicMapIcons] Deleting map icons from server...");
  137. for(new i = 1; i < MAX_DMAPICONS; i++)
  138. {
  139. RehashDynamicMapIcon(i);
  140. }
  141. //LoadDynamicMapIcons();
  142. }
  143. CMD:gotomapicon(playerid, params[])
  144. {
  145. if(PlayerInfo[playerid][pAdmin] < 4 && PlayerInfo[playerid][pASM] < 1 && PlayerInfo[playerid][pBM] < 2)
  146. {
  147. SendClientMessageEx(playerid, COLOR_GRAD2, "You are not authorized to use this command!");
  148. return 1;
  149. }
  150. new mapiconid;
  151. if(sscanf(params, "d", mapiconid)) return SendClientMessageEx(playerid, COLOR_GREY, "USAGE: /gotomapicon [mapiconid]");
  152. if(mapiconid >= MAX_DMAPICONS || mapiconid < 1)
  153. {
  154. SendClientMessageEx(playerid, COLOR_GREY, "USAGE: /gotomapicon [mapiconid]");
  155. return 1;
  156. }
  157. SetPlayerPos(playerid, DMPInfo[mapiconid][dmpPosX], DMPInfo[mapiconid][dmpPosY], DMPInfo[mapiconid][dmpPosZ]);
  158. SetPlayerVirtualWorld(playerid, DMPInfo[mapiconid][dmpVW]);
  159. SetPlayerInterior(playerid, DMPInfo[mapiconid][dmpInt]);
  160. return 1;
  161. }
  162. CMD:dmpnear(playerid, params[])
  163. {
  164. if(PlayerInfo[playerid][pAdmin] >= 4 || PlayerInfo[playerid][pASM] >= 1 || PlayerInfo[playerid][pBM] == 2)
  165. {
  166. SendClientMessageEx(playerid, COLOR_RED, "* Listing all map icons within 30 meters of you");
  167. new Float:X, Float:Y, Float:Z;
  168. GetPlayerPos(playerid, X, Y, Z);
  169. for(new i=1;i<MAX_DMAPICONS;i++)
  170. {
  171. if(IsPlayerInRangeOfPoint(playerid, 30, DMPInfo[i][dmpPosX], DMPInfo[i][dmpPosY], DMPInfo[i][dmpPosZ]))
  172. {
  173. if(DMPInfo[i][dmpMarkerType] != 0)
  174. {
  175. new string[128];
  176. format(string, sizeof(string), "MapIcon ID %d | %f from you", i, GetDistanceBetweenPoints(DMPInfo[i][dmpPosX], DMPInfo[i][dmpPosY], DMPInfo[i][dmpPosZ], X, Y, Z));
  177. SendClientMessageEx(playerid, COLOR_WHITE, string);
  178. }
  179. }
  180. }
  181. }
  182. else
  183. {
  184. SendClientMessageEx(playerid, COLOR_GRAD2, "You are not authorized to use that command.");
  185. }
  186. return 1;
  187. }
  188. CMD:dmpnext(playerid, params[])
  189. {
  190. if(PlayerInfo[playerid][pAdmin] >= 4 || PlayerInfo[playerid][pASM] >= 1 || PlayerInfo[playerid][pBM] == 2)
  191. {
  192. SendClientMessageEx(playerid, COLOR_RED, "* Listing next available map icon...");
  193. for(new x=1;x<MAX_DMAPICONS;x++)
  194. {
  195. if(DMPInfo[x][dmpMarkerType] == 0)
  196. {
  197. new string[128];
  198. format(string, sizeof(string), "%d is available to use.", x);
  199. SendClientMessageEx(playerid, COLOR_WHITE, string);
  200. break;
  201. }
  202. }
  203. }
  204. else
  205. {
  206. SendClientMessageEx(playerid, COLOR_GRAD2, "You are not authorized to use that command.");
  207. return 1;
  208. }
  209. return 1;
  210. }
  211. CMD:dmpedit(playerid, params[])
  212. {
  213. if(PlayerInfo[playerid][pAdmin] < 4 && PlayerInfo[playerid][pASM] < 1 && PlayerInfo[playerid][pBM] < 2)
  214. {
  215. SendClientMessageEx(playerid, COLOR_GRAD2, "You are not authorized to use that command.");
  216. return 1;
  217. }
  218. new string[128], choice[32], mapiconid, amount;
  219. if(sscanf(params, "s[32]dD", choice, mapiconid, amount))
  220. {
  221. SendClientMessageEx(playerid, COLOR_GREY, "USAGE: /dmpedit [name] [mapiconid] [(Optional)amount]");
  222. SendClientMessageEx(playerid, COLOR_GREY, "Available names: Position, Type, Color, Delete");
  223. return 1;
  224. }
  225. if(mapiconid < 1 || mapiconid >= MAX_DMAPICONS)
  226. {
  227. SendClientMessageEx( playerid, COLOR_WHITE, "Invalid Map Icon ID!");
  228. }
  229. if(strcmp(choice, "position", true) == 0)
  230. {
  231. GetPlayerPos(playerid, DMPInfo[mapiconid][dmpPosX], DMPInfo[mapiconid][dmpPosY], DMPInfo[mapiconid][dmpPosZ]);
  232. DMPInfo[mapiconid][dmpInt] = GetPlayerInterior(playerid);
  233. DMPInfo[mapiconid][dmpVW] = GetPlayerVirtualWorld(playerid);
  234. SendClientMessageEx(playerid, COLOR_WHITE, "You have changed the position!");
  235. if(IsValidDynamicMapIcon(DMPInfo[mapiconid][dmpMapIconID])) DestroyDynamicMapIcon(DMPInfo[mapiconid][dmpMapIconID]);
  236. DMPInfo[mapiconid][dmpMapIconID] = CreateDynamicMapIcon(DMPInfo[mapiconid][dmpPosX], DMPInfo[mapiconid][dmpPosY], DMPInfo[mapiconid][dmpPosZ], DMPInfo[mapiconid][dmpMarkerType], DMPInfo[mapiconid][dmpColor], DMPInfo[mapiconid][dmpVW], DMPInfo[mapiconid][dmpInt], -1, 500.0);
  237. SaveDynamicMapIcon(mapiconid);
  238. format(string, sizeof(string), "%s has edited MapIconID %d's Position.", GetPlayerNameEx(playerid), mapiconid);
  239. Log("logs/dmpedit.log", string);
  240. return 1;
  241. }
  242. else if(strcmp(choice, "delete", true) == 0)
  243. {
  244. SendClientMessageEx(playerid, COLOR_WHITE, "You have deleted the map icon!");
  245. DMPInfo[mapiconid][dmpPosX] = 0.0;
  246. DMPInfo[mapiconid][dmpPosY] = 0.0;
  247. DMPInfo[mapiconid][dmpPosZ] = 0.0;
  248. DMPInfo[mapiconid][dmpVW] = 0;
  249. DMPInfo[mapiconid][dmpInt] = 0;
  250. DMPInfo[mapiconid][dmpMarkerType] = 0;
  251. DMPInfo[mapiconid][dmpColor] = 0;
  252. SaveDynamicMapIcon(mapiconid);
  253. if(IsValidDynamicMapIcon(DMPInfo[mapiconid][dmpMapIconID])) DestroyDynamicMapIcon(DMPInfo[mapiconid][dmpMapIconID]);
  254. format(string, sizeof(string), "%s has deleted MapIconID %d.", GetPlayerNameEx(playerid), mapiconid);
  255. Log("logs/dmpedit.log", string);
  256. return 1;
  257. }
  258. else if(strcmp(choice, "type", true) == 0)
  259. {
  260. DMPInfo[mapiconid][dmpMarkerType] = amount;
  261. format(string, sizeof(string), "You have set the marker type to %d.", amount);
  262. SendClientMessageEx(playerid, COLOR_WHITE, string);
  263. if(IsValidDynamicMapIcon(DMPInfo[mapiconid][dmpMapIconID])) DestroyDynamicMapIcon(DMPInfo[mapiconid][dmpMapIconID]);
  264. DMPInfo[mapiconid][dmpMapIconID] = CreateDynamicMapIcon(DMPInfo[mapiconid][dmpPosX], DMPInfo[mapiconid][dmpPosY], DMPInfo[mapiconid][dmpPosZ], DMPInfo[mapiconid][dmpMarkerType], DMPInfo[mapiconid][dmpColor], DMPInfo[mapiconid][dmpVW], DMPInfo[mapiconid][dmpInt], -1, 500.0);
  265. format(string, sizeof(string), "%s has edited MapIconID %d's Marker Type to %d.", GetPlayerNameEx(playerid), mapiconid, amount);
  266. Log("logs/dmpedit.log", string);
  267. }
  268. else if(strcmp(choice, "color", true) == 0)
  269. {
  270. DMPInfo[mapiconid][dmpColor] = amount;
  271. format(string, sizeof(string), "You have set the color to %d.", amount);
  272. SendClientMessageEx(playerid, COLOR_WHITE, string);
  273. if(IsValidDynamicMapIcon(DMPInfo[mapiconid][dmpMapIconID])) DestroyDynamicMapIcon(DMPInfo[mapiconid][dmpMapIconID]);
  274. DMPInfo[mapiconid][dmpMapIconID] = CreateDynamicMapIcon(DMPInfo[mapiconid][dmpPosX], DMPInfo[mapiconid][dmpPosY], DMPInfo[mapiconid][dmpPosZ], DMPInfo[mapiconid][dmpMarkerType], DMPInfo[mapiconid][dmpColor], DMPInfo[mapiconid][dmpVW], DMPInfo[mapiconid][dmpInt], -1, 500.0);
  275. format(string, sizeof(string), "%s has edited MapIconID %d's Color to %d.", GetPlayerNameEx(playerid), mapiconid, amount);
  276. Log("logs/dmpedit.log", string);
  277. }
  278. SaveDynamicMapIcon(mapiconid);
  279. return 1;
  280. }