Advertisement
Guest User

Mauzen

a guest
Aug 27th, 2009
733
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.13 KB | None | 0 0
  1. #include <a_samp>
  2. #include <a_sampmysql>
  3.  
  4. #define COLOR_GREY 0xAFAFAFAA
  5. #define COLOR_DARKGRAY 0x33333366
  6. #define COLOR_GREEN 0x33AA33AA
  7. #define COLOR_RED 0xAA3333AA
  8. #define COLOR_YELLOW 0xFFFF00AA
  9. #define COLOR_WHITE 0xFFFFFFAA
  10. #define COLOR_BLUE 0x4444C0AA
  11.  
  12. #define MYSQL_ADDRESS "localhost"
  13. #define MYSQL_NAME "root"
  14. #define MYSQL_PW "abc123"
  15. #define MYSQL_DBNAME "samp"
  16.  
  17. #define MAX_BOMBS 16
  18. #define MAX_BASES 8
  19.  
  20. #define FILTERSCRIPT
  21.  
  22. forward AutoAim(base, playerid, runs, fast, Float:x, Float:y, Float:z);
  23. forward Rotator(base, Float:wanted);
  24. forward GetKeyPressed(code, key);
  25. forward Float:floatrandom(Float:max);
  26. forward Float:GetGroundZ(Float:x, Float:y);
  27. forward FireArtillery(base, playerid, Float:spo, Float:al, Float:r);
  28. forward FireStationaryArtillery(playerid, base);
  29. forward MoveBomb(base, id);
  30. forward FireBomb(playerid, base, id);
  31. forward RenewTowers();
  32. forward Float:GetPlayerDistanceToPoint(playerid, Float:x, Float:y, Float:z);
  33. forward SatelliteScan(base, playerid);
  34. forward MoveScan(base, playerid);
  35. forward AddBase(Float:x, Float:y, Float:z);
  36. forward GetClosestPlayer(Float:x, Float:y, Float:z);
  37. forward Follower(playerid, base, target);
  38. forward RemoveBase(base);
  39. forward ShowControlMenu(playerid, base);
  40. forward HasPlayerControl(playerid, base, sscan);
  41. forward SetRotation(playerid, base, Float:wa);
  42. forward SetAngle(playerid, base, Float:wa);
  43.  
  44. new Float:sx[MAX_BASES];
  45. new Float:sy[MAX_BASES];
  46. new Float:sz[MAX_BASES];
  47. new Float:flighttime[MAX_BASES][MAX_BOMBS];
  48. new Float:speedo[MAX_BASES][MAX_BOMBS];
  49. new Float:g = 9.81;
  50. new Float:alpha[MAX_BASES][MAX_BOMBS];
  51. new Float:rot[MAX_BASES][MAX_BOMBS];
  52. new bomb[MAX_BASES][MAX_BOMBS];
  53. new bombtimer[MAX_BASES][MAX_BOMBS];
  54. new firecount[MAX_BASES];
  55. new bombcount[MAX_BASES];
  56.  
  57. new Float:lastcurx[MAX_BASES][MAX_BOMBS];
  58. new Float:curx[MAX_BASES][MAX_BOMBS];
  59. new Float:cury[MAX_BASES][MAX_BOMBS];
  60. new Float:lastcurz[MAX_BASES][MAX_BOMBS];
  61. new Float:curz[MAX_BASES][MAX_BOMBS];
  62. new Float:xo[MAX_BASES][MAX_BOMBS];
  63. new Float:yo[MAX_BASES][MAX_BOMBS];
  64. new Float:sp[MAX_BASES][MAX_BOMBS];
  65.  
  66. new Float:arotz[MAX_BASES];
  67. new Float:aangle[MAX_BASES];
  68. new Float:apower[MAX_BASES];
  69. new Float:streuung[MAX_BASES];
  70. new delay[MAX_BASES];
  71. new arotator[MAX_BASES];
  72. new Float:tx[MAX_BASES];
  73. new Float:ty[MAX_BASES];
  74. new Float:tz[MAX_BASES];
  75. new Float:t;
  76. new ttimer;
  77. new basecount = 0;
  78.  
  79. new Float:atime = 0.1;
  80. new nomysql = 0;
  81.  
  82. new Float:scanx[MAX_PLAYERS];
  83. new Float:scany[MAX_PLAYERS];
  84. new Float:scanz[MAX_PLAYERS];
  85. new scanactive[MAX_PLAYERS];
  86. new scanaimed[MAX_PLAYERS];
  87.  
  88. new followtimer[MAX_BASES];
  89. new followtarget[MAX_BASES];
  90.  
  91. new atower[MAX_BASES];
  92. new abase[MAX_BASES];
  93.  
  94. #if defined FILTERSCRIPT
  95.  
  96. public OnFilterScriptInit()
  97. {
  98. print("\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
  99. print("X Artillery filterscript V0.93 X");
  100. print("X created by Mauzen 2008/2009 X");
  101. print("XxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxX");
  102. if(nomysql) print("Alternative GetZ-Mode is FORCED");
  103. else if(!(samp_mysql_connect(MYSQL_ADDRESS, MYSQL_NAME, MYSQL_PW) == 1) || !(samp_mysql_select_db(MYSQL_DBNAME) == 1)) {
  104. print("No Database available, using alternative mode...");
  105. nomysql = 1;
  106. }
  107. print("XxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxX\n");
  108. SetTimer("RenewTowers", 60000, 1);
  109. AddBase(1609.4414,1654.029,23.3);
  110. AddBase(208.935,1931.253,23.142);
  111.  
  112. return 1;
  113. }
  114.  
  115. public OnFilterScriptExit()
  116. {
  117. samp_mysql_close();
  118. for(new i = 0; i < basecount; i ++) {
  119. DestroyObject(abase[i]);
  120. DestroyObject(atower[i]);
  121. }
  122. return 1;
  123. }
  124. #endif
  125.  
  126. public OnPlayerCommandText(playerid, cmdtext[])
  127. {
  128. new idx;
  129. new cmd[256];
  130. cmd = strtok(cmdtext, idx);
  131.  
  132. if(strcmp(cmd, "/addbase", true) == 0) {
  133. if(IsPlayerAdmin(playerid) ) {
  134. new Float:px;
  135. new Float:py;
  136. new Float:pz;
  137. GetPlayerPos(playerid, px, py, pz);
  138. SetPlayerPosFindZ(playerid, px, py, pz + 10);
  139. new tmp[64];
  140. format(tmp, 64, "Added a new base! ID: %d", AddBase(px, py, pz - 0.5));
  141. SendClientMessage(playerid, COLOR_RED, tmp);
  142. } else SendClientMessage(playerid, COLOR_RED, "This is an Admin-Only command!");
  143. return 1;
  144. }
  145. if(strcmp(cmd, "/removebase", true) == 0) {
  146. if(IsPlayerAdmin(playerid) ) {
  147. new tmp[32];
  148. tmp = strtok(cmdtext, idx);
  149. if(!strlen(tmp)) {
  150. SendClientMessage(playerid, COLOR_RED, "Wrong syntax! Use /Removebase <id>");
  151. return 1;
  152. }
  153. RemoveBase(strval(tmp));
  154. SendClientMessage(playerid, COLOR_BLUE, "Base removed!");
  155. } else SendClientMessage(playerid, COLOR_RED, "This is an Admin-Only command!");
  156. return 1;
  157. }
  158.  
  159. if(strcmp(cmd, "/sscan", true) == 0) {
  160. new base = strval(strtok(cmdtext, idx));
  161. if(HasPlayerControl(playerid, base, 1)) {
  162. SatelliteScan(base, playerid);
  163. } else SendClientMessage(playerid, COLOR_RED, "You do not have the permittance to do that!");
  164. return 1;
  165. }
  166.  
  167. if(strcmp(cmd, "/forcenomysql", true) == 0) {
  168. if(IsPlayerAdmin(playerid) ) {
  169. nomysql = strval(strtok(cmdtext, idx));
  170. } else SendClientMessage(playerid, COLOR_RED, "This is an Admin-Only command!");
  171. return 1;
  172. }
  173.  
  174. if(strcmp(cmd, "/setrotation", true) == 0) {
  175. new tmp[32];
  176. tmp = strtok(cmdtext, idx);
  177. if(!strlen(tmp)) return 0;
  178. new base = strval(tmp);
  179. if(HasPlayerControl(playerid, base, 0)) {
  180. tmp = strtok(cmdtext, idx);
  181. if(!strlen(tmp)) return 0;
  182. new Float:wa = floatstr(tmp);
  183. SetRotation(playerid, base, wa);
  184. } else SendClientMessage(playerid, COLOR_RED, "You do not have the permittance to do that!");
  185. return 1;
  186. }
  187.  
  188. if(strcmp(cmd, "/setfirecount", true) == 0) {
  189. new base = strval(strtok(cmdtext, idx));
  190. if(HasPlayerControl(playerid, base, 0)) {
  191. firecount[base] = strval(strtok(cmdtext, idx));
  192. SendClientMessage(playerid, COLOR_YELLOW, "Firecount set!");
  193. } else SendClientMessage(playerid, COLOR_RED, "You do not have the permittance to do that!");
  194. return 1;
  195. }
  196.  
  197. if(strcmp(cmd, "/setspread", true) == 0) {
  198. new base = strval(strtok(cmdtext, idx));
  199. if(HasPlayerControl(playerid, base, 0)) {
  200. streuung[base] = floatstr(strtok(cmdtext, idx));
  201. SendClientMessage(playerid, COLOR_YELLOW, "Spread set!");
  202. } else SendClientMessage(playerid, COLOR_RED, "You do not have the permittance to do that!");
  203. return 1;
  204. }
  205.  
  206. if(strcmp(cmd, "/setangle", true) == 0) {
  207. new base = strval(strtok(cmdtext, idx));
  208. new Float:wa = floatstr(strtok(cmdtext, idx));
  209. if(HasPlayerControl(playerid, base, 0)) {
  210. SetAngle(playerid, base, wa);
  211. new tmp[64];
  212. format(tmp, 64, "Base %d: Angle adjusted to %f! Distance changed to ~%dm", base, aangle[base], floatround((floatpower(floatround(apower[base]), 2) / 10) * floatsin(floatround(2 * aangle[base]), degrees)));
  213. SendClientMessage(playerid, COLOR_YELLOW, tmp);
  214. } else SendClientMessage(playerid, COLOR_RED, "You do not have the permittance to do that!");
  215. return 1;
  216. }
  217.  
  218. if(strcmp(cmd, "/setpower", true) == 0) {
  219. new base = strval(strtok(cmdtext, idx));
  220. if(HasPlayerControl(playerid, base, 0)) {
  221. apower[base] = floatstr(strtok(cmdtext, idx));
  222. new tmp[64];
  223. format(tmp, 64, "Base %d: Power set to %f! Distance changed to ~%dm", base, apower[base], floatround((floatpower(floatround(apower[base]), 2) / 10) * floatsin(floatround(2 * aangle[base]), degrees)));
  224. SendClientMessage(playerid, COLOR_YELLOW, tmp);
  225. t = 0;
  226. } else SendClientMessage(playerid, COLOR_RED, "You do not have the permittance to do that!");
  227. return 1;
  228. }
  229.  
  230. if(strcmp(cmd, "/setdelay", true) == 0) {
  231. new base = strval(strtok(cmdtext, idx));
  232. if(HasPlayerControl(playerid, base, 0)) {
  233. delay[base] = strval(strtok(cmdtext, idx));
  234. new tmp[64];
  235. format(tmp, 64, "Base %d: Firedelay adjusted to %d!", base, delay[base]);
  236. SendClientMessage(playerid, COLOR_YELLOW, tmp);
  237. } else SendClientMessage(playerid, COLOR_RED, "You do not have the permittance to do that!");
  238. return 1;
  239. }
  240.  
  241. if(strcmp(cmd, "/fire", true) == 0) {
  242. new tmp[32] = "0";
  243. new base;
  244. while(strlen(tmp)) {
  245. tmp = strtok(cmdtext, idx);
  246. if(strlen(tmp) > 0) {
  247. base = strval(tmp);
  248. if(HasPlayerControl(playerid, base, 0)) FireStationaryArtillery(playerid, base);
  249. }
  250. }
  251. return 1;
  252. }
  253.  
  254. if(strcmp(cmd, "/check", true) == 0) {
  255. new base = strval(strtok(cmdtext, idx));
  256. if(HasPlayerControl(playerid, base, 0)) {
  257. new tmp[64];
  258. format(tmp, 64, "Parameters - Base %d", base);
  259. SendClientMessage(playerid, COLOR_BLUE, tmp);
  260. format(tmp, 64, "Rotation: %f/%f", arotz[base], aangle[base]);
  261. SendClientMessage(playerid, COLOR_BLUE, tmp);
  262. format(tmp, 64, "Power: %f (%d bombs/fire)", apower[base], firecount[base]);
  263. SendClientMessage(playerid, COLOR_BLUE, tmp);
  264. format(tmp, 64, "Spread: %f", streuung[base]);
  265. SendClientMessage(playerid, COLOR_BLUE, tmp);
  266. format(tmp, 64, "Airdistance (estimated): %dm", floatround((floatpower(floatround(apower[base]), 2) / 10) * floatsin(floatround(2 * aangle[base]), degrees)));
  267. SendClientMessage(playerid, COLOR_BLUE, tmp);
  268. if(followtimer[base] > -1) {
  269. format(tmp, 64, " - Following Player %d - ", followtarget[base]);
  270. SendClientMessage(playerid, COLOR_BLUE, tmp);
  271. }
  272. } else SendClientMessage(playerid, COLOR_RED, "You do not have the permittance to do that!");
  273. return 1;
  274. }
  275.  
  276. if(strcmp(cmd, "/follow", true) == 0) {
  277. new base = strval(strtok(cmdtext, idx));
  278. if(HasPlayerControl(playerid, base, 0)) {
  279. if(followtimer[base] == -1) {
  280. new tmp[32];
  281. followtarget[base] = strval(strtok(cmdtext, idx));
  282. followtimer[base] = SetTimerEx("Follower", 50, 1, "iii", playerid, base, followtarget[base]);
  283. format(tmp, 64, "Base %d: Following Player %d", base, followtarget[base]);
  284. SendClientMessage(playerid, COLOR_BLUE, tmp);
  285. return 1;
  286. }
  287. } else SendClientMessage(playerid, COLOR_RED, "You do not have the permittance to do that!");
  288. }
  289.  
  290. if(strcmp(cmd, "/stopfollow", true) == 0) {
  291. new base = strval(strtok(cmdtext, idx));
  292. if(HasPlayerControl(playerid, base, 0)) {
  293. new tmp[32];
  294. KillTimer(followtimer[base]);
  295. followtimer[base] = -1;
  296. format(tmp, 64, "Base %d: Stopped following Player %d", base, followtarget[base]);
  297. SendClientMessage(playerid, COLOR_BLUE, tmp);
  298. } else SendClientMessage(playerid, COLOR_RED, "You do not have the permittance to do that!");
  299. return 1;
  300. }
  301.  
  302. if(strcmp(cmd, "/autoaim", true) == 0) {
  303. AutoAim(strval(strtok(cmdtext, idx)), playerid, strval(strtok(cmdtext, idx)), 0, floatstr(strtok(cmdtext, idx)), floatstr(strtok(cmdtext, idx)), floatstr(strtok(cmdtext, idx)));
  304. return 1;
  305. }
  306.  
  307. if(strcmp(cmd, "/pos", true) == 0) { //still some debugging stuff - can be used for aiming ;)
  308. new Float:tax;
  309. new Float:tay;
  310. new Float:taz;
  311. new tmp[64];
  312. GetPlayerPos(playerid, tax, tay, taz);
  313. format(tmp, 64, "%f %f %f", tax, tay, taz);
  314. SendClientMessage(playerid, COLOR_BLUE, tmp);
  315. return 1;
  316. }
  317.  
  318. return 0;
  319. }
  320.  
  321.  
  322. public Follower(playerid, base, target) {
  323. new Float:tax;
  324. new Float:tay;
  325. new Float:taz;
  326. GetPlayerPos(target, tax, tay, taz);
  327. AutoAim(base, playerid, 500, 1, tax, tay, taz);
  328. return 1;
  329. }
  330.  
  331. public Rotator(base, Float:wanted) {
  332. //new Float:realrot;
  333. if((arotz[base] <= wanted) && (arotz[base] + 2 >= wanted)) {
  334. arotz[base] = wanted;
  335. SendClientMessage(0, COLOR_YELLOW, "Rotation adjusted!");
  336. SetObjectRot(atower[base], 0, 0, wanted * -1 + 360.0);
  337. KillTimer(arotator[base]);
  338. arotator[base] = -1;
  339. } else {
  340. if(wanted - arotz[base] >= arotz[base] - wanted) arotz[base] += 2.0;
  341. else arotz[base] -= 2.0;
  342. if(arotz[base] > 360.0) arotz[base] -= 360.0;
  343. if(arotz[base] < 0) arotz[base] += 360.0;
  344. SetObjectRot(atower[base], 0, 0, arotz[base] * -1 + 360.0);
  345. }
  346. }
  347.  
  348. // -----------------------------------------------------------------------------
  349.  
  350. //useful stuff
  351.  
  352. strtok(const string[], &index)
  353. {
  354. new length = strlen(string);
  355. while ((index < length) && (string[index] <= ' '))
  356. {
  357. index++;
  358. }
  359.  
  360. new offset = index;
  361. new result[20];
  362. while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  363. {
  364. result[index - offset] = string[index];
  365. index++;
  366. }
  367. result[index - offset] = EOS;
  368. return result;
  369. }
  370.  
  371. public GetKeyPressed(code, key) {
  372. for(new i = 65536; i > 0; i = i / 2) {
  373. if(code >= i) {
  374. code = code - i;
  375. if(i == key) return 1;
  376. }
  377. }
  378. return 0;
  379. }
  380.  
  381. public Float:floatrandom(Float:max) {
  382. new Float:rand;
  383. max = max * 100000;
  384. rand = floatdiv(float(random(floatround(max))), 100000.0);
  385. return rand;
  386. }
  387.  
  388. public Float:GetPlayerDistanceToPoint(playerid, Float:x, Float:y, Float:z) {
  389. new Float:px;
  390. new Float:py;
  391. new Float:pz;
  392. GetPlayerPos(playerid, px, py, pz);
  393. return floatsqroot( floatadd( floatadd( floatpower(floatsub(x, px), 2), floatpower(floatsub(y, py), 2) ), floatpower(floatsub(z, pz), 2) ) );
  394. }
  395.  
  396. public GetClosestPlayer(Float:x, Float:y, Float:z) {
  397. new Float:p;
  398. new closestp;
  399. new Float:closest = 999999;
  400. for(new i = 0; i < MAX_PLAYERS; i++) {
  401. if(IsPlayerConnected(i)) {
  402. p = GetPlayerDistanceToPoint(i, x, y, z);
  403. if(p < closest) {
  404. closest = p;
  405. closestp = i;
  406. }
  407. }
  408. }
  409. return closestp;
  410. }
  411.  
  412. public Float:GetGroundZ(Float:x, Float:y) {
  413. new Float:gz;
  414. new Float:px;
  415. new Float:py;
  416. if(nomysql == 0) {
  417. new rxy[96];
  418. x = 5.0 * floatround(x / 5.0); //Replace 5.0 by your "map resolution"
  419. y = 5.0 * floatround(y / 5.0); //Replace 5.0 by your "map resolution"
  420. format(rxy, 96, "SELECT z FROM hfull WHERE x = %d AND y = %d;", floatround(x), floatround(y));
  421. samp_mysql_query(rxy);
  422. samp_mysql_store_result();
  423. samp_mysql_fetch_row(rxy);
  424. gz = floatstr(rxy);
  425. if(gz != 0 && samp_mysql_num_rows() == 1) return gz;
  426. }
  427. GetPlayerPos(GetClosestPlayer(x, y, 0), px, py, gz);
  428. return gz;
  429. }
  430.  
  431. // ----------------------- Externalized Controls -------------------------------------
  432. // -----------------------------------------------------------------------------------
  433.  
  434. public SetRotation(playerid, base, Float:wa) {
  435. if(followtimer[base] == -1) {
  436. if(arotator[base] == -1) {
  437. SendClientMessage(playerid, COLOR_YELLOW, "Adjusting rotation...");
  438. if(wa > 360.0) {
  439. while(wa > 360.0) {
  440. wa -= 360.0;
  441. }
  442. } else if(wa < 0.0) {
  443. while(wa < 0.0) {
  444. wa += 360.0;
  445. }
  446. }
  447. t = 0;
  448. arotator[base] = SetTimerEx("Rotator", 50, 1, "if", base, wa);
  449. }
  450. }
  451. }
  452.  
  453. public SetAngle(playerid, base, Float:wa) {
  454. if(wa > 90.0) {
  455. while(wa > 90.0) {
  456. wa -= 90.0;
  457. }
  458. } else if(wa < 0.0) {
  459. while(wa < 0.0) {
  460. wa += 90.0;
  461. }
  462. }
  463. aangle[base] = wa;
  464. t = 0;
  465. }
  466.  
  467. public SatelliteScan(base, playerid) {
  468. new Float:startx;
  469. new Float:starty;
  470. new Float:startz;
  471. GetPlayerPos(playerid, startx, starty, startz);
  472. scanactive[playerid] = SetTimerEx("MoveScan", 50, 1, "ii", base, playerid);
  473. scanx[playerid] = startx;
  474. scany[playerid] = starty;
  475. scanz[playerid] = startz + 5;
  476. SetPlayerCameraPos(playerid, scanx[playerid], scany[playerid] + 0.01, scanz[playerid]);
  477. SetPlayerCameraLookAt(playerid, scanx[playerid], scany[playerid], 0);
  478. TogglePlayerControllable(playerid, 0);
  479. return 1;
  480. }
  481.  
  482. public AutoAim(base, playerid, runs, fast, Float:x, Float:y, Float:z) {
  483. new Float:w;
  484. new Float:v = 50;
  485. new Float:wanted;
  486. new Float:ox;
  487. new Float:oy;
  488. new Float:oz;
  489. new updown;
  490. new Float:step = 4;
  491. tx[base] = x;
  492. ty[base] = y;
  493. tz[base] = z;
  494. GetObjectPos(atower[base], ox, oy, oz);
  495. wanted = floatsqroot(floatpower(ox - x, 2) + floatpower(oy - y, 2));
  496. new i;
  497. for(i = 0; i < runs; i ++) {
  498. w = ( (v * floatcos(aangle[base], degrees)) * (v * floatsin(aangle[base], degrees) + floatsqroot( floatpower(v, 2) * floatpower(floatsin(aangle[base], degrees), 2) + 2 * g * floatsub(oz, z)) ) ) / g;
  499. if(w < wanted) {
  500. if(updown == 1) step = step / 4;
  501. v += step;
  502. updown = 0;
  503. } else if(w > wanted) {
  504. if(updown == 0) step = step / 4;
  505. v -= step;
  506. updown = 1;
  507. } else {
  508. break;
  509. }
  510. }
  511. z = w;
  512. apower[base] = v;
  513. w = atan2(ox - x, oy - y) + 180;
  514. t = ( v * floatsin(aangle[base], degrees) + floatsqroot( floatpower (v, 2) * floatpower ( floatsin(aangle[base], degrees), 2 ) + 2 * g * floatsub(oz, z) ) ) / g;
  515. if(!fast) {
  516. arotator[base] = SetTimerEx("Rotator", 50, 1, "if", base, w);
  517. new tmp[64];
  518. format(tmp, 64, "Autoaiming - Base %d", base);
  519. SendClientMessage(0, COLOR_BLUE, tmp);
  520. format(tmp, 64, "Rotation: %f/%f", arotz[base], aangle[base]);
  521. SendClientMessage(playerid, COLOR_BLUE, tmp);
  522. format(tmp, 64, "Power: %f (%d bombs/fire)", apower[base], firecount[base]);
  523. SendClientMessage(playerid, COLOR_BLUE, tmp);
  524. format(tmp, 64, "Spread: %f", streuung[base]);
  525. SendClientMessage(playerid, COLOR_BLUE, tmp);
  526. format(tmp, 64, "Airdistance (estimated): %dm", floatround((floatpower(floatround(apower[base]), 2) / 10) * floatsin(floatround(2 * aangle[base]), degrees)));
  527. SendClientMessage(playerid, COLOR_BLUE, tmp);
  528. //format(tmp, 64, "Tolerance / runs: %f / %d", wanted - z, i); //some debugging stuff
  529. //SendClientMessage(0, COLOR_BLUE, tmp);
  530. format(tmp, 64, "Airtime: %f", t);
  531. SendClientMessage(0, COLOR_BLUE, tmp);
  532. } else {
  533. arotz[base] = w;
  534. SetObjectRot(atower[base], 0, 0, arotz[base] * -1 + 360.0);
  535. }
  536. return 1;
  537. }
  538.  
  539. public FireStationaryArtillery(playerid, base) {
  540. if(abase[base] > 0) {
  541. GetObjectPos(atower[base], sx[base], sy[base], sz[base]);
  542. sz[base] ++;
  543. bombcount[base] = 0;
  544. new id = 0;
  545. while((id < MAX_BOMBS) && (bombcount[base] < firecount[base])) {
  546. if(bomb[base][id] == 0) {
  547. bomb[base][id] = -1;
  548. curz[base][id] = sz[base];
  549. flighttime[base][id] = 0.0;
  550. lastcurz[base][id] = 0.0;
  551. bombcount[base] ++;
  552. SetTimerEx("FireBomb", delay[base] * bombcount[base] + 100, 0, "iii", playerid, base, id);
  553. }
  554. id ++;
  555. }
  556. }
  557. }
  558.  
  559. public MoveBomb(base, id) {
  560. lastcurx[base][id] = xo[base][id];
  561. sp[base][id] = floatsqroot( floatpower(speedo[base][id], 2) - 2 * speedo[base][id] * g * (flighttime[base][id] + 2 * atime) * floatsin(alpha[base][id], degrees) + floatpower(g, 2) * floatpower((flighttime[base][id] + 2 * atime), 2));
  562. xo[base][id] = speedo[base][id] * floatcos(alpha[base][id], degrees) * (flighttime[base][id] + 2 * atime);
  563. yo[base][id] = (-1) * (g / 2) * floatpower((flighttime[base][id] + 2 * atime), 2) + speedo[base][id] * floatsin(alpha[base][id], degrees) * (flighttime[base][id] + 2 * atime);
  564.  
  565. curx[base][id] = sx[base] + floatsin(rot[base][id], degrees) * xo[base][id];
  566. cury[base][id] = sy[base] + floatcos(rot[base][id], degrees) * xo[base][id];
  567. lastcurz[base][id] = curz[base][id];
  568. curz[base][id] = sz[base] + yo[base][id];
  569. if(lastcurz[base][id] != 0.0) SetObjectRot(bomb[base][id], atan2(curz[base][id] - lastcurz[base][id], xo[base][id] - lastcurx[base][id]), 0, -1 * rot[base][id]);
  570. else SetObjectRot(bomb[base][id], alpha[base][id], 0, -1 * rot[base][id]);
  571. MoveObject(bomb[base][id], curx[base][id], cury[base][id], curz[base][id], sp[base][id]);
  572. for(new i = 0; i < MAX_PLAYERS; i++) {
  573. if(GetPlayerDistanceToPoint(i, curx[base][id], cury[base][id], curz[base][id]) < 5) {
  574. //new tmp[64];
  575. //format(tmp, 64, "Base %d: Bomb %d hit ground", base, id);
  576. //SendClientMessage(0, COLOR_YELLOW, tmp);
  577. CreateExplosion(curx[base][id], cury[base][id], curz[base][id], 6, 6.0);
  578. DestroyObject(bomb[base][id]);
  579. bomb[base][id] = 0;
  580. KillTimer(bombtimer[base][id]);
  581. KillTimer(ttimer);
  582. RemovePlayerMapIcon(0, 0);
  583. SetPlayerMapIcon(0, 0, curx[base][id], cury[base][id], curz[base][id], 19, 0x00000000);
  584. break;
  585. }
  586. }
  587. flighttime[base][id] += atime;
  588.  
  589. if((curz[base][id] <= GetGroundZ(curx[base][id], cury[base][id]) - 1.5)) {
  590. //new tmp[64];
  591. //format(tmp, 64, "Base %d: Bomb %d hit ground", base, id);
  592. //SendClientMessage(0, COLOR_YELLOW, tmp);
  593. CreateExplosion(curx[base][id], cury[base][id], curz[base][id], 6, 6.0);
  594. DestroyObject(bomb[base][id]);
  595. bomb[base][id] = 0;
  596. KillTimer(bombtimer[base][id]);
  597. KillTimer(ttimer);
  598. RemovePlayerMapIcon(0, 0);
  599. SetPlayerMapIcon(0, 0, curx[base][id], cury[base][id], curz[base][id], 19, 0x00000000);
  600. }
  601. }
  602.  
  603. public FireBomb(playerid, base, id) {
  604. if(id == 0 || id == 4 || id == 8 || id == 12) {
  605. bomb[base][id] = CreateObject(345, sx[base] - 1, sy[base], sz[base] + 1, 0, alpha[base][id], -1 * rot[base][id]);
  606. } else if(id == 1 || id == 5 || id == 9 || id == 13) {
  607. bomb[base][id] = CreateObject(345, sx[base] + 1, sy[base], sz[base] + 1, 0, alpha[base][id], -1 * rot[base][id]);
  608. } else if(id == 2 || id == 6 || id == 10 || id == 14) {
  609. bomb[base][id] = CreateObject(345, sx[base] + 1, sy[base], sz[base] - 1, 0, alpha[base][id], -1 * rot[base][id]);
  610. } else if(id == 3 || id == 7 || id == 11 || id == 15) {
  611. bomb[base][id] = CreateObject(345, sx[base] - 1, sy[base], sz[base] - 1, 0, alpha[base][id], -1 * rot[base][id]);
  612. } else bomb[base][id] = CreateObject(345, sx[base], sy[base], sz[base], 0, alpha[base][id], -1 * rot[base][id]);
  613. speedo[base][id] = apower[base] + floatrandom(bombcount[base] * (streuung[base] * 0.5) + 0.2) - bombcount[base] * (streuung[base] * 0.25) - 0.1;
  614. alpha[base][id] = aangle[base] + floatrandom(bombcount[base] * streuung[base] + 0.4) - bombcount[base] * (streuung[base] / 2) - 0.2;
  615. rot[base][id] = arotz[base] + floatrandom(bombcount[base] * streuung[base] + 0.4) - bombcount[base] * (streuung[base] / 2) - 0.2;
  616. bombtimer[base][id] = SetTimerEx("MoveBomb", floatround(atime * 1000), 1, "ii", base, id);
  617. new tmp[64];
  618. format(tmp, 64, "Base %d: Bomb %d fired!", base, id);
  619. SendClientMessage(playerid, COLOR_YELLOW, tmp);
  620. }
  621.  
  622. public RenewTowers() {
  623. new Float:x;
  624. new Float:y;
  625. new Float:z;
  626. for(new i = 0; i < basecount; i ++) {
  627. GetObjectPos(atower[i], x, y, z);
  628. DestroyObject(atower[i]);
  629. DestroyObject(abase[i]);
  630. atower[i] = CreateObject(3267, x, y, z, 0, 0, -1 * arotz[i] + 360.0);
  631. abase[i] = CreateObject(3277, x, y, z, 0, 0, 0);
  632. }
  633. return 1;
  634. }
  635.  
  636. public MoveScan(base, playerid) {
  637. new key1;
  638. new key2;
  639. new key3;
  640. GetPlayerKeys(playerid, key1, key2, key3);
  641. if(key3 == 65408) {
  642. scanx[playerid] = scanx[playerid] + 0.02 * scanz[playerid];
  643. } else if(key3 == 128) {
  644. scanx[playerid] = scanx[playerid] - 0.02 * scanz[playerid];
  645. }
  646. if(key2 == 65408) {
  647. scany[playerid] = scany[playerid] - 0.02 * scanz[playerid];
  648. } else if(key2 == 128) {
  649. scany[playerid] = scany[playerid] + 0.02 * scanz[playerid];
  650. }
  651. if(key1 == 32) {
  652. scanz[playerid] = scanz[playerid] + 1;
  653. } else if(key1 == 4) {
  654. scanz[playerid] = scanz[playerid] - 1;
  655. }
  656. SetPlayerCameraPos(playerid, scanx[playerid], scany[playerid] + 0.01, scanz[playerid]);
  657. SetPlayerCameraLookAt(playerid, scanx[playerid], scany[playerid], 0);
  658. if(key1 == 1) {
  659. SetCameraBehindPlayer(playerid);
  660. KillTimer(scanactive[playerid]);
  661. scanactive[playerid] = 0;
  662. TogglePlayerControllable(playerid, 1);
  663. DisablePlayerCheckpoint(playerid);
  664. }
  665. if(key1 == 2 && scanaimed[playerid] != 1) {
  666. if(arotator[base] == -1) {
  667. AutoAim(base, playerid, 2500, 0, scanx[playerid], scany[playerid], GetGroundZ(scanx[playerid], scany[playerid]));
  668. SetPlayerCheckpoint(playerid, scanx[playerid], scany[playerid], GetGroundZ(scanx[playerid], scany[playerid]), streuung[base] * 5);
  669. scanaimed[playerid] = 1;
  670. } else SendClientMessage(playerid, COLOR_YELLOW, "Wait a moment, the tower is still rotating...");
  671. }
  672. if(key1 == 0 && scanaimed[playerid] == 1) {
  673. scanaimed[playerid] = 0;
  674. }
  675. return 1;
  676. }
  677.  
  678. public AddBase(Float:x, Float:y, Float:z) {
  679. if(basecount < MAX_BASES) {
  680. for(new i = 0; i < MAX_BASES; i ++) {
  681. if(abase[i] == 0) {
  682. atower[i] = CreateObject(3267, x, y, z, 0.0, 0.0, 0.0);
  683. abase[i] = CreateObject(3277, x, y, z, 0, 0, 0);
  684. arotator[i] = -1;
  685. apower[i] = 25;
  686. aangle[i] = 45;
  687. firecount[i] = 1;
  688. streuung[i] = 1;
  689. delay[i] = 500;
  690. followtimer[i] = -1;
  691. basecount ++;
  692. return i;
  693. }
  694. }
  695. }
  696. return 0;
  697. }
  698.  
  699. public RemoveBase(base) {
  700. if(abase[base] > 0) {
  701. DestroyObject(atower[base]);
  702. DestroyObject(abase[base]);
  703. abase[base] = 0;
  704. basecount --;
  705. }
  706. }
  707.  
  708. public HasPlayerControl(playerid, base, sscan) {
  709. if(sscan) {
  710. //return 1 here, if <playerid> should be allowed to use the satellite aiming mode of base <base>
  711. //return 0, if he is not
  712. return 1;
  713. } else {
  714. //return 1 here, if <playerid> should be allowed to control everything else of base <base>, like power, rotation and fire
  715. //return 0, if he is not
  716. return 1;
  717. }
  718. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement