Advertisement
Guest User

Kinetic

a guest
Mar 21st, 2009
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.20 KB | None | 0 0
  1. #include <ai>
  2. #include <aicolor>
  3. #include <lrp>
  4. /*#include <a_samp>
  5. #include <a_players>
  6. #include <float>
  7.  
  8. #define teal1 0x00bbbb00
  9. #define teal3 0x00999900*/
  10.  
  11. #define maxplayers 200
  12. //----[Quick Stats]-------------------------------------------------------------
  13. new mphtext = 0; // 0 = textdraw, 1 = gamemodetext.
  14. new style = 0; // The Default Style 0 = mph, 1 = kmph.
  15. new incar = 0; // Display speedo only in car. 0 = yes, 1 = no.
  16. new timeramt= 300;// Speed of the speedometer timer in milliseconds.
  17. new spcolor = 0; // Default Color. 0 = blue, 1 = green, 2 = red, 3 = purple, 4 = yellow.
  18. //------------------------------------------------------------------------------
  19.  
  20. new Mphtext[maxplayers];
  21. new Style[maxplayers];
  22. new Color[maxplayers];
  23.  
  24. new timer;
  25.  
  26. new Text:Speedometer[maxplayers];
  27. new ToggleSpeedometer[maxplayers];
  28. new Displaying[maxplayers];
  29.  
  30. enum pos
  31. {
  32. Float:x,
  33. Float:y,
  34. Float:z
  35. }
  36. new Pos[maxplayers][pos];
  37. new Pos2[maxplayers][pos];
  38.  
  39. new Float:DistanceX[maxplayers];
  40. new Float:DistanceY[maxplayers];
  41. new Float:DistanceX2[maxplayers];
  42. new Float:DistanceY2[maxplayers];
  43. new Float:Distance[maxplayers];
  44.  
  45. new Float:S1[maxplayers];
  46. new Float:S2[maxplayers];
  47. new Float:S3[maxplayers];
  48. new SpeedStep[maxplayers];
  49.  
  50. new Float:TotalSpeed[maxplayers];
  51.  
  52. forward Timer();
  53. forward PlayerMessage(playerid, color, string[]);
  54.  
  55. public OnFilterScriptInit() // OnFilterScriptInit
  56. {
  57. print(" ");
  58. print(" >> AI Speed initiated");
  59. print(" ");
  60.  
  61. timer = SetTimer("Timer", timeramt, true);
  62.  
  63. return 1;
  64. } //----------
  65.  
  66. public OnFilterScriptExit() // OnFilterScriptExit
  67. {
  68. print(" ");
  69. print(" >> AI Speed shut down...");
  70. print(" ");
  71.  
  72. KillTimer(timer);
  73. for(new i=0; i<=GetMaxPlayers(); i++)
  74. {
  75. TextDrawDestroy(Speedometer[i]);
  76. }
  77. return 1;
  78. } //----------
  79.  
  80. public OnPlayerConnect(playerid) // OnPlayerConnect
  81. {
  82. Mphtext[playerid] = mphtext;
  83. Style[playerid] = style;
  84. Color[playerid] = spcolor;
  85. Displaying[playerid] = 1;
  86. Speedometer[playerid] = TextDrawCreate(300, 400, " ");
  87. //Speedometer[playerid] = TextDrawCreate(502, 110, " "); Used for my script
  88. TextDrawAlignment(Speedometer[playerid],1);
  89. TextDrawSetProportional(Speedometer[playerid],1);
  90. TextDrawSetOutline(Speedometer[playerid], 1);
  91. TextDrawFont(Speedometer[playerid], 2);
  92. TextDrawShowForPlayer(playerid, Speedometer[playerid]);
  93. return 1;
  94. } //----------
  95.  
  96. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  97. {
  98. if(ToggleSpeedometer[playerid] == 1)
  99. {
  100. TextDrawShowForPlayer(playerid, Speedometer[playerid]);
  101. return 1;
  102. }
  103. return 1;
  104. }
  105.  
  106. public Timer() // Timer
  107. {
  108. for(new i=0; i<=GetMaxPlayers(); i++)
  109. {
  110. if(IsPlayerConnected(i))
  111. {
  112. if(ToggleSpeedometer[i] == 1)
  113. {
  114. new str[64];
  115. new cstr[64];
  116. if(SpeedStep[i] == 0)
  117. {
  118. GetPlayerPos(i, Pos[i][x], Pos[i][y], Pos[i][z]);
  119. }
  120. if(SpeedStep[i] == 1)
  121. {
  122. GetPlayerPos(i, Pos2[i][x], Pos2[i][y], Pos2[i][z]);
  123. DistanceX[i] = Pos[i][x] - Pos2[i][x];
  124. DistanceY[i] = Pos[i][y] - Pos2[i][y];
  125. DistanceX2[i] = DistanceX[i] * DistanceX[i];
  126. DistanceY2[i] = DistanceY[i] * DistanceY[i];
  127. Distance[i] = (DistanceX2[i] + DistanceY2[i])/2;
  128. S1[i] = Distance[i];
  129. }
  130. if(SpeedStep[i] == 2)
  131. {
  132. GetPlayerPos(i, Pos[i][x], Pos[i][y], Pos[i][z]);
  133. }
  134. if(SpeedStep[i] == 3)
  135. {
  136. GetPlayerPos(i, Pos2[i][x], Pos2[i][y], Pos2[i][z]);
  137. DistanceX[i] = Pos[i][x] - Pos2[i][x];
  138. DistanceY[i] = Pos[i][y] - Pos2[i][y];
  139. DistanceX2[i] = DistanceX[i] * DistanceX[i];
  140. DistanceY2[i] = DistanceY[i] * DistanceY[i];
  141. Distance[i] = (DistanceX2[i] + DistanceY2[i])/2;
  142. S2[i] = Distance[i];
  143. }
  144. if(SpeedStep[i] == 4)
  145. {
  146. GetPlayerPos(i, Pos[i][x], Pos[i][y], Pos[i][z]);
  147. }
  148. if(SpeedStep[i] == 5)
  149. {
  150. GetPlayerPos(i, Pos2[i][x], Pos2[i][y], Pos2[i][z]);
  151. DistanceX[i] = Pos[i][x] - Pos2[i][x];
  152. DistanceY[i] = Pos[i][y] - Pos2[i][y];
  153. DistanceX2[i] = DistanceX[i] * DistanceX[i];
  154. DistanceY2[i] = DistanceY[i] * DistanceY[i];
  155. Distance[i] = (DistanceX2[i] + DistanceY2[i])/2;
  156. S3[i] = Distance[i];
  157. }
  158.  
  159. TotalSpeed[i] = (S1[i]+S2[i]+S3[i])/3;
  160. if(Mphtext[i] == 0)
  161. {
  162. if(incar == 0)
  163. {
  164. if(!IsPlayerInAnyVehicle(i))
  165. {
  166. TextDrawHideForPlayer(i, Speedometer[i]);
  167. }
  168. if(IsPlayerInAnyVehicle(i))
  169. {
  170. TextDrawShowForPlayer(i, Speedometer[i]);
  171. if(Style[i] == 0)
  172. {
  173. if(Displaying[i] == 0)
  174. {
  175. Speedometer[i] = TextDrawCreate(300, 400, " ");
  176. //Speedometer[playerid] = TextDrawCreate(502, 110, " "); Used for my script
  177. TextDrawAlignment(Speedometer[i],1);
  178. TextDrawSetProportional(Speedometer[i],1);
  179. TextDrawSetOutline(Speedometer[i], 1);
  180. TextDrawFont(Speedometer[i], 2);
  181. TextDrawShowForPlayer(i, Speedometer[i]);
  182. Displaying[i] = 1;
  183. }
  184. format(str, sizeof(str), "mph:~w~%.0f",TotalSpeed[i]);
  185. if(Color[i] == 0)
  186. {
  187. format(cstr, sizeof(cstr), "~b~%s", str);
  188. }
  189. if(Color[i] == 1)
  190. {
  191. format(cstr, sizeof(cstr), "~g~%s", str);
  192. }
  193. if(Color[i] == 2)
  194. {
  195. format(cstr, sizeof(cstr), "~r~%s", str);
  196. }
  197. if(Color[i] == 3)
  198. {
  199. format(cstr, sizeof(cstr), "~p~%s", str);
  200. }
  201. if(Color[i] == 4)
  202. {
  203. format(cstr, sizeof(cstr), "~y~%s", str);
  204. }
  205. if(Color[i] == 5)
  206. {
  207. format(cstr, sizeof(cstr), "~l~%s", str);
  208. }
  209. TextDrawSetString(Speedometer[i], cstr);
  210. }
  211. if(Style[i] == 1)
  212. {
  213. if(Displaying[i] == 0)
  214. {
  215. Speedometer[i] = TextDrawCreate(300, 400, " ");
  216. //Speedometer[playerid] = TextDrawCreate(502, 110, " "); Used for my script
  217. TextDrawAlignment(Speedometer[i],1);
  218. TextDrawSetProportional(Speedometer[i],1);
  219. TextDrawSetOutline(Speedometer[i], 1);
  220. TextDrawFont(Speedometer[i], 2);
  221. TextDrawShowForPlayer(i, Speedometer[i]);
  222. Displaying[i] = 1;
  223. }
  224. format(str, sizeof(str), "kmph:~w~%.0f",TotalSpeed[i]*1.609);
  225. if(Color[i] == 0)
  226. {
  227. format(cstr, sizeof(cstr), "~b~%s", str);
  228. }
  229. if(Color[i] == 1)
  230. {
  231. format(cstr, sizeof(cstr), "~g~%s", str);
  232. }
  233. if(Color[i] == 2)
  234. {
  235. format(cstr, sizeof(cstr), "~r~%s", str);
  236. }
  237. if(Color[i] == 3)
  238. {
  239. format(cstr, sizeof(cstr), "~p~%s", str);
  240. }
  241. if(Color[i] == 4)
  242. {
  243. format(cstr, sizeof(cstr), "~y~%s", str);
  244. }
  245. if(Color[i] == 5)
  246. {
  247. format(cstr, sizeof(cstr), "~l~%s", str);
  248. }
  249. TextDrawSetString(Speedometer[i], cstr);
  250. }
  251. }
  252. }
  253. if(incar == 1)
  254. {
  255. TextDrawShowForPlayer(i, Speedometer[i]);
  256. if(Style[i] == 0)
  257. {
  258. if(Displaying[i] == 0)
  259. {
  260. Speedometer[i] = TextDrawCreate(300, 400, " ");
  261. //Speedometer[playerid] = TextDrawCreate(502, 110, " "); Used for my script
  262. TextDrawAlignment(Speedometer[i],1);
  263. TextDrawSetProportional(Speedometer[i],1);
  264. TextDrawSetOutline(Speedometer[i], 1);
  265. TextDrawFont(Speedometer[i], 2);
  266. TextDrawShowForPlayer(i, Speedometer[i]);
  267. Displaying[i] = 1;
  268. }
  269. format(str, sizeof(str), "mph:~w~%.0f",TotalSpeed[i]);
  270. if(Color[i] == 0)
  271. {
  272. format(cstr, sizeof(cstr), "~b~%s", str);
  273. }
  274. if(Color[i] == 1)
  275. {
  276. format(cstr, sizeof(cstr), "~g~%s", str);
  277. }
  278. if(Color[i] == 2)
  279. {
  280. format(cstr, sizeof(cstr), "~r~%s", str);
  281. }
  282. if(Color[i] == 3)
  283. {
  284. format(cstr, sizeof(cstr), "~p~%s", str);
  285. }
  286. if(Color[i] == 4)
  287. {
  288. format(cstr, sizeof(cstr), "~y~%s", str);
  289. }
  290. if(Color[i] == 5)
  291. {
  292. format(cstr, sizeof(cstr), "~l~%s", str);
  293. }
  294. TextDrawSetString(Speedometer[i], cstr);
  295. }
  296. if(Style[i] == 1)
  297. {
  298. if(Displaying[i] == 0)
  299. {
  300. Speedometer[i] = TextDrawCreate(300, 400, " ");
  301. //Speedometer[playerid] = TextDrawCreate(502, 110, " "); Used for my script
  302. TextDrawAlignment(Speedometer[i],1);
  303. TextDrawSetProportional(Speedometer[i],1);
  304. TextDrawSetOutline(Speedometer[i], 1);
  305. TextDrawFont(Speedometer[i], 2);
  306. TextDrawShowForPlayer(i, Speedometer[i]);
  307. Displaying[i] = 1;
  308. }
  309. format(str, sizeof(str), "kmph:~w~%.0f",TotalSpeed[i]*1.609);
  310. if(Color[i] == 0)
  311. {
  312. format(cstr, sizeof(cstr), "~b~%s", str);
  313. }
  314. if(Color[i] == 1)
  315. {
  316. format(cstr, sizeof(cstr), "~g~%s", str);
  317. }
  318. if(Color[i] == 2)
  319. {
  320. format(cstr, sizeof(cstr), "~r~%s", str);
  321. }
  322. if(Color[i] == 3)
  323. {
  324. format(cstr, sizeof(cstr), "~p~%s", str);
  325. }
  326. if(Color[i] == 4)
  327. {
  328. format(cstr, sizeof(cstr), "~y~%s", str);
  329. }
  330. if(Color[i] == 5)
  331. {
  332. format(cstr, sizeof(cstr), "~l~%s", str);
  333. }
  334. TextDrawSetString(Speedometer[i], cstr);
  335. }
  336. }
  337. }
  338. if(Mphtext[i] == 1)
  339. {
  340. if(incar == 0)
  341. {
  342. if(Style[i] == 0)
  343. {
  344. if(Color[i] == 0)
  345. {
  346. format(str, sizeof(str), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~b~mph:~w~%.0f", TotalSpeed[i]);
  347. }
  348. if(Color[i] == 1)
  349. {
  350. format(str, sizeof(str), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~g~mph:~w~%.0f", TotalSpeed[i]);
  351. }
  352. if(Color[i] == 2)
  353. {
  354. format(str, sizeof(str), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~r~mph:~w~%.0f", TotalSpeed[i]);
  355. }
  356. if(Color[i] == 3)
  357. {
  358. format(str, sizeof(str), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~p~mph:~w~%.0f", TotalSpeed[i]);
  359. }
  360. if(Color[i] == 4)
  361. {
  362. format(str, sizeof(str), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~y~mph:~w~%.0f", TotalSpeed[i]);
  363. }
  364. if(Color[i] == 5)
  365. {
  366. format(str, sizeof(str), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~l~mph:~w~%.0f", TotalSpeed[i]);
  367. }
  368. GameTextForPlayer(i, str, timeramt, 3);
  369. }
  370. if(Style[i] == 1)
  371. {
  372. if(Color[i] == 0)
  373. {
  374. format(str, sizeof(str), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~b~kmph:~w~%.0f", TotalSpeed[i]);
  375. }
  376. if(Color[i] == 1)
  377. {
  378. format(str, sizeof(str), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~g~kmph:~w~%.0f", TotalSpeed[i]);
  379. }
  380. if(Color[i] == 2)
  381. {
  382. format(str, sizeof(str), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~r~kmph:~w~%.0f", TotalSpeed[i]);
  383. }
  384. if(Color[i] == 3)
  385. {
  386. format(str, sizeof(str), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~p~kmph:~w~%.0f", TotalSpeed[i]);
  387. }
  388. if(Color[i] == 4)
  389. {
  390. format(str, sizeof(str), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~y~kmph:~w~%.0f", TotalSpeed[i]);
  391. }
  392. if(Color[i] == 5)
  393. {
  394. format(str, sizeof(str), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~l~kmph:~w~%.0f", TotalSpeed[i]);
  395. }
  396. GameTextForPlayer(i, str, timeramt, 3);
  397. }
  398. }
  399. }
  400. SpeedStep[i] ++;
  401. if(SpeedStep[i] == 6)
  402. {
  403. SpeedStep[i] = 0;
  404. }
  405. }
  406. }
  407. }
  408. return 1;
  409. } //----------
  410.  
  411. public OnPlayerPrivmsg(playerid, recieverid, text[]) // OnPlayerPrivmsg
  412. {
  413. return 0;
  414. } //----------
  415.  
  416. public OnPlayerCommandText(playerid, cmdtext[]) // OnPlayerCommandText
  417. {
  418. if (strcmp("/speedometer", cmdtext, true) == 0)
  419. {
  420. if(ToggleSpeedometer[playerid] == 0)
  421. {
  422. ToggleSpeedometer[playerid] = 1;
  423. PlayerMessage(playerid, teal3, " >> Speedometer turned on.");
  424. PlayerPlaySound(playerid, 1053, 0, 0, 0);
  425. TextDrawShowForPlayer(playerid, Speedometer[playerid]);
  426. return 1;
  427. }
  428. if(ToggleSpeedometer[playerid] == 1)
  429. {
  430. ToggleSpeedometer[playerid] = 0;
  431. PlayerMessage(playerid, teal3, " >> Speedometer turned off.");
  432. PlayerPlaySound(playerid, 1053, 0, 0, 0);
  433. TextDrawHideForPlayer(playerid, Speedometer[playerid]);
  434. return 1;
  435. }
  436. return 1;
  437. }
  438.  
  439. if(strcmp("/mph", cmdtext, true) == 0)
  440. {
  441. Style[playerid] = 0;
  442. PlayerMessage(playerid, teal3, " >> Speedometer set to mph.");
  443. PlayerPlaySound(playerid, 1053, 0, 0, 0);
  444. return 1;
  445. }
  446.  
  447. if(strcmp("/kmph", cmdtext, true) == 0 || strcmp("/kph", cmdtext, true) == 0)
  448. {
  449. Style[playerid] = 1;
  450. PlayerMessage(playerid, teal3, " >> Speedometer set to kmph.");
  451. PlayerPlaySound(playerid, 1053, 0, 0, 0);
  452. return 1;
  453. }
  454.  
  455. if(strcmp("/blue", cmdtext, true) == 0)
  456. {
  457. Color[playerid] = 0;
  458. PlayerMessage(playerid, teal3, " >> Speedometer color set to blue.");
  459. PlayerPlaySound(playerid, 1053, 0, 0, 0);
  460. return 1;
  461. }
  462.  
  463. if(strcmp("/green", cmdtext, true) == 0)
  464. {
  465. Color[playerid] = 1;
  466. PlayerMessage(playerid, teal3, " >> Speedometer color set to green.");
  467. PlayerPlaySound(playerid, 1053, 0, 0, 0);
  468. return 1;
  469. }
  470.  
  471. if(strcmp("/red", cmdtext, true) == 0)
  472. {
  473. Color[playerid] = 2;
  474. PlayerMessage(playerid, teal3, " >> Speedometer color set to red.");
  475. PlayerPlaySound(playerid, 1053, 0, 0, 0);
  476. return 1;
  477. }
  478.  
  479. if(strcmp("/purple", cmdtext, true) == 0)
  480. {
  481. Color[playerid] = 3;
  482. PlayerMessage(playerid, teal3, " >> Speedometer color set to purple.");
  483. PlayerPlaySound(playerid, 1053, 0, 0, 0);
  484. return 1;
  485. }
  486.  
  487. if(strcmp("/yellow", cmdtext, true) == 0)
  488. {
  489. Color[playerid] = 4;
  490. PlayerMessage(playerid, teal3, " >> Speedometer color set to yellow.");
  491. PlayerPlaySound(playerid, 1053, 0, 0, 0);
  492. return 1;
  493. }
  494.  
  495. if(strcmp("/black", cmdtext, true) == 0)
  496. {
  497. Color[playerid] = 5;
  498. PlayerMessage(playerid, teal3, " >> Speedometer color set to black.");
  499. PlayerPlaySound(playerid, 1053, 0, 0, 0);
  500. return 1;
  501. }
  502.  
  503. if(strcmp("/mphtext", cmdtext, true) == 0)
  504. {
  505. if(Mphtext[playerid] == 0)
  506. {
  507. Mphtext[playerid] = 1;
  508. PlayerMessage(playerid, teal3, " >> Speedometer set to gamemodetext.");
  509. TextDrawHideForPlayer(playerid, Speedometer[playerid]);
  510. PlayerPlaySound(playerid, 1053, 0, 0, 0);
  511. return 1;
  512. }
  513. if(Mphtext[playerid] == 1)
  514. {
  515. Mphtext[playerid] = 0;
  516. PlayerMessage(playerid, teal3, " >> Speedometer set to text draw.");
  517. PlayerPlaySound(playerid, 1053, 0, 0, 0);
  518. return 1;
  519. }
  520. return 1;
  521. }
  522.  
  523. if(strcmp("/help", cmdtext, true) == 0)
  524. {
  525. PlayerMessage(playerid, teal1, " >> Help");
  526. PlayerMessage(playerid, teal1, " >> /speedometer (toggles on and off)");
  527. PlayerMessage(playerid, teal1, " >> /mphtext (toggles textdraw and gamemodetext)");
  528. PlayerMessage(playerid, teal1, " >> /mph /kmph (switches to the style of your choosing.)");
  529. PlayerMessage(playerid, teal1, " >> /blue /green /red /purple /yellow /black (switches the color of the mph/kmph display.)");
  530. return 1;
  531. }
  532. return 0;
  533. } //----------
  534.  
  535. public PlayerMessage(playerid, color, string[]) // PlayerMessage
  536. {
  537. SendClientMessage(playerid, color, string);
  538. return 1;
  539. } //----------
  540.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement