Advertisement
Guest User

Mauzen

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