Guest User

HDO

a guest
Feb 26th, 2013
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.62 KB | None | 0 0
  1. //Hide dat Object by riccor
  2.  
  3. #include <a_samp>
  4. #include <streamer> //http://forum.sa-mp.com/showthread.php?t=102865
  5. #include <sscanf2> //http://forum.sa-mp.com/showthread.php?t=120356
  6. #include <zcmd> //http://forum.sa-mp.com/showthread.php?t=91354
  7.  
  8. #define OBJECTS_FILE "HDO/All_Objects.txt" //Credits to [uL]Pottus - http://forum.sa-mp.com/showthread.php?t=415397
  9. #define REMOVED_OBJECTS_FILE "HDO/Removed_Objects.txt"
  10.  
  11. #define MAX_STREAM 400.0
  12. #define MAX_DRAW 400.0
  13.  
  14. #define COLOR_RED 0xFF0000FF
  15. #define COLOR_GREEN 0x53D212FF
  16. #define COLOR_YELLOW 0xFFDD00FF
  17. #define COLOR_WHITE 0xFFFFFFFF
  18.  
  19. #define MAX_SLOTS 36100
  20.  
  21. new Objects[MAX_SLOTS] = {-1, ...};
  22. new Lods[MAX_SLOTS] = {-1, ...};
  23. new Text3D: Labels[MAX_SLOTS];
  24.  
  25. public OnFilterScriptInit()
  26. {
  27. new File: file = fopen(REMOVED_OBJECTS_FILE, io_read);
  28. if(!file) return print("Error accessing at removed objects file!");
  29.  
  30. new line[128], model, lod;
  31. while(fread(file, line, sizeof(line)))
  32. {
  33. if(sscanf(line, "p<,>dd", model, lod)) continue;
  34. for(new p = 0; p < MAX_PLAYERS; p++) if(IsPlayerConnected(p))
  35. {
  36. RemoveBuildingForPlayer(p, model, 0.0, 0.0, 0.0, 10000.0);
  37. if(lod != 65535) RemoveBuildingForPlayer(p, lod, 0.0, 0.0, 0.0, 10000.0);
  38. }
  39. }
  40. fclose(file);
  41. return 1;
  42. }
  43.  
  44. public OnPlayerConnect(playerid)
  45. {
  46. new File: file = fopen(REMOVED_OBJECTS_FILE, io_read);
  47. if(!file) return SendClientMessage(playerid, COLOR_RED, "Error accessing at removed objects file! Contact the owner.");
  48.  
  49. new line[128], model, lod;
  50. while(fread(file, line, sizeof(line)))
  51. {
  52. if(sscanf(line, "p<,>dd", model, lod)) continue;
  53. RemoveBuildingForPlayer(playerid, model, 0.0, 0.0, 0.0, 10000.0);
  54. if(lod != 65535) RemoveBuildingForPlayer(playerid, lod, 0.0, 0.0, 0.0, 10000.0);
  55. }
  56. fclose(file);
  57. return 1;
  58. }
  59.  
  60. CMD:restore(playerid, params[])
  61. {
  62. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "Error: Only RCON admins can use this command.");
  63.  
  64. new m;
  65. if(sscanf(params, "d", m)) return SendClientMessage(playerid, COLOR_YELLOW, "Usage: /restore [Object Model]");
  66.  
  67. new File: rfile = fopen(REMOVED_OBJECTS_FILE, io_read);
  68. if(!rfile) return SendClientMessage(playerid, COLOR_RED, "Error accessing at removed objects file! Contact the owner.");
  69.  
  70. new line[128], model, lod, bool: flag = false;
  71. while(fread(rfile, line, sizeof(line)))
  72. {
  73. if(sscanf(line, "p<,>dd", model, lod)) continue;
  74. if(model == m)
  75. {
  76. flag = true;
  77. break;
  78. }
  79. }
  80. fclose(rfile);
  81.  
  82. if(!flag) return SendClientMessage(playerid, COLOR_RED, "Error: The specified object model was still not removed!");
  83.  
  84. new File: file = fopen(OBJECTS_FILE, io_read);
  85. if(!file) return SendClientMessage(playerid, COLOR_RED, "Error accessing at objects file! Contact the owner.");
  86.  
  87. new Float: x, Float: y, Float: z, Float: rx, Float: ry, Float: rz, counter = 0, i = -1;
  88. while(fread(file, line, sizeof(line)))
  89. {
  90. i++;
  91. if(i >= MAX_SLOTS) break;
  92. if(sscanf(line, "p<,>ddffffff", model, lod, x, y, z, rx, ry, rz)) continue;
  93. if(model != m) continue;
  94.  
  95. if(Objects[i] != -1) DestroyDynamicObject(Objects[i]);
  96. if(Lods[i] != -1) DestroyDynamicObject(Lods[i]);
  97.  
  98. Objects[i] = CreateDynamicObject(m, x, y, z, rx, ry, rz, -1, -1, -1, MAX_STREAM);
  99. Streamer_SetFloatData(STREAMER_TYPE_OBJECT, Objects[i], E_STREAMER_DRAW_DISTANCE, MAX_DRAW);
  100.  
  101. if(lod != 65535)
  102. {
  103. Lods[i] = CreateDynamicObject(lod, x, y, z, rx, ry, rz, -1, -1, -1, MAX_STREAM);
  104. Streamer_SetFloatData(STREAMER_TYPE_OBJECT, Lods[i], E_STREAMER_DRAW_DISTANCE, MAX_DRAW);
  105. }
  106.  
  107. counter++;
  108. }
  109. fclose(file);
  110.  
  111. for(new a = 0; a < MAX_PLAYERS; a++) if(IsPlayerConnected(a)) Streamer_Update(a);
  112.  
  113. new str[64];
  114. format(str, sizeof(str), "%d, %d\r\n", m, lod);
  115.  
  116. if(fexist("tmpfile.tmp")) fremove("tmpfile.tmp");
  117.  
  118. rfile = fopen(REMOVED_OBJECTS_FILE, io_read);
  119. new File: temp = fopen("tmpfile.tmp", io_write);
  120.  
  121. while(fread(rfile, line)) if(strcmp(line, line, true)) fwrite(temp, line);
  122.  
  123. fclose(rfile);
  124. fclose(temp);
  125.  
  126. rfile = fopen(REMOVED_OBJECTS_FILE, io_write);
  127. temp = fopen("tmpfile.tmp", io_read);
  128.  
  129. while(fread(temp, line)) fwrite(rfile, line);
  130.  
  131. fclose(rfile);
  132. fclose(temp);
  133.  
  134. fremove("tmpfile.tmp");
  135.  
  136. new msg[64];
  137. format(msg, sizeof(msg), "Server: %d objects with model %d were restored!", counter, m);
  138. SendClientMessage(playerid, COLOR_YELLOW, msg);
  139. return 1;
  140. }
  141.  
  142. CMD:remove(playerid, params[])
  143. {
  144. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "Error: Only RCON admins can use this command.");
  145.  
  146. new m;
  147. if(sscanf(params, "d", m)) return SendClientMessage(playerid, COLOR_YELLOW, "Usage: /remove [Object Model]");
  148.  
  149. new File: rfile = fopen(REMOVED_OBJECTS_FILE, io_read);
  150. if(!rfile) return SendClientMessage(playerid, COLOR_RED, "Error accessing at removed objects file! Contact the owner.");
  151.  
  152. new line[128], model, lod;
  153. while(fread(rfile, line, sizeof(line)))
  154. {
  155. if(sscanf(line, "p<,>dd", model, lod)) continue;
  156. if(model == m)
  157. {
  158. fclose(rfile);
  159. return SendClientMessage(playerid, COLOR_RED, "Error: The specified object model was already removed!");
  160. }
  161. }
  162. fclose(rfile);
  163.  
  164. new File: file = fopen(OBJECTS_FILE, io_read);
  165. if(!file) return SendClientMessage(playerid, COLOR_RED, "Error accessing at objects file! Contact the owner.");
  166.  
  167. new Float: x, Float: y, Float: z, Float: rx, Float: ry, Float: rz, counter = 0, i = -1;
  168. while(fread(file, line, sizeof(line)))
  169. {
  170. i++;
  171. if(i >= MAX_SLOTS) break;
  172. if(sscanf(line, "p<,>ddffffff", model, lod, x, y, z, rx, ry, rz)) continue;
  173. if(model != m) continue;
  174.  
  175. if(Objects[i] != -1) DestroyDynamicObject(Objects[i]);
  176. if(Lods[i] != -1) DestroyDynamicObject(Lods[i]);
  177.  
  178. if(lod != 65535)
  179. {
  180. for(new p = 0; p < MAX_PLAYERS; p++) if(IsPlayerConnected(p)) RemoveBuildingForPlayer(p, lod, 0.0, 0.0, 0.0, 10000.0);
  181. }
  182.  
  183. counter++;
  184. }
  185. fclose(file);
  186.  
  187. for(new p = 0; p < MAX_PLAYERS; p++) if(IsPlayerConnected(p)) RemoveBuildingForPlayer(p, m, 0.0, 0.0, 0.0, 10000.0);
  188.  
  189. new str[64];
  190. format(str, sizeof(str), "%d, %d\r\n", m, lod);
  191.  
  192. rfile = fopen(REMOVED_OBJECTS_FILE, io_append);
  193. if(!rfile) return SendClientMessage(playerid, COLOR_RED, "Error accessing at removed objects file! Contact the owner.");
  194. fwrite(rfile, str);
  195. fclose(rfile);
  196.  
  197. new msg[64];
  198. format(msg, sizeof(msg), "Server: %d objects with model %d were removed!", counter, m);
  199. SendClientMessage(playerid, COLOR_RED, msg);
  200. return 1;
  201. }
  202.  
  203. CMD:showmodels(playerid, params[])
  204. {
  205. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "Error: Only RCON admins can use this command.");
  206.  
  207. new text[16];
  208.  
  209. new File: file = fopen(OBJECTS_FILE, io_read);
  210. if(!file) return SendClientMessage(playerid, COLOR_RED, "Error accessing at objects file! Contact the owner.");
  211.  
  212. new line[128], model, lod, Float: x, Float: y, Float: z, Float: rx, Float: ry, Float: rz, i = -1;
  213. while(fread(file, line, sizeof(line)))
  214. {
  215. i++;
  216. if(i >= MAX_SLOTS) break;
  217. if(sscanf(line, "p<,>ddffffff", model, lod, x, y, z, rx, ry, rz)) continue;
  218.  
  219. DestroyDynamic3DTextLabel(Labels[i]);
  220. format(text, sizeof(text), "%d", model);
  221. Labels[i] = CreateDynamic3DTextLabel(text, COLOR_WHITE, x, y, z, 50.0);
  222. }
  223. fclose(file);
  224.  
  225. SendClientMessage(playerid, COLOR_GREEN, "Server: Objects model labels on!");
  226. return 1;
  227. }
  228.  
  229. CMD:hidemodels(playerid, params[])
  230. {
  231. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "Error: Only RCON admins can use this command.");
  232. for(new i = 0; i < sizeof(Labels); i++) DestroyDynamic3DTextLabel(Labels[i]);
  233. SendClientMessage(playerid, COLOR_RED, "Server: Objects model labels off!");
  234. return 1;
  235. }
Advertisement
Add Comment
Please, Sign In to add comment