Guest User

Ultimate Vehicle Controller by Babica

a guest
May 18th, 2012
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.69 KB | None | 0 0
  1. //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=Ultimate Vehicle Control=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  2. //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=Credits: Babica=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  3. //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=Do Not Remove Credits Please=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  4.  
  5.  
  6.  
  7. //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=Includes=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  8.  
  9. #include <a_samp>
  10. #include <zcmd>
  11.  
  12. //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=Defines=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  13.  
  14. #define FILTERSCRIPT
  15. #if defined FILTERSCRIPT
  16. #define PRESSED(%0) \
  17. (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
  18. #define BLINK_RATE 400
  19. #define PFLASH_RATE 300
  20. #define LIGHT_KEY KEY_SUBMISSION
  21. #define COLOR_PURPLE 0xC2A2DAAA
  22. #define COLOR_YELLOW 0xFFFF00AA
  23. #define COLOR_LIGHTRED 0xFF6347AA
  24. #define COLOR_ROSUAPRINS 0xE80000FF
  25. #define COLOR_BLUE 0x2641FEAA
  26. #define COLOR_GREEN 0x33AA33AA
  27. #define COLOR_2RED 0xFF0606FF
  28. #define SCM SendClientMessage
  29.  
  30. new engine,lights,alarm,doors,bonnet,boot,objective;
  31. new BlinkTime[MAX_PLAYERS];
  32. new EngineStatus[MAX_PLAYERS];
  33.  
  34. //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=OnFilterScriptInit=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  35.  
  36. public OnFilterScriptInit()
  37. {
  38. print("\n--------------------------------------");
  39. print(" Vehicle Control By Mr.Babica");
  40. print("--------------------------------------\n");
  41. return 1;
  42. }
  43.  
  44. //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=OnFilterScriptExit=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  45.  
  46. public OnFilterScriptExit()
  47. {
  48. return 1;
  49. }
  50.  
  51. #else
  52.  
  53. main()
  54. {
  55. print("\n----------------------------------");
  56. print(" Vehicle Control By Babica");
  57. print("----------------------------------\n");
  58. }
  59.  
  60. #endif
  61.  
  62.  
  63. //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=OnPlayerConnect=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  64.  
  65. public OnPlayerConnect(playerid)
  66. {
  67. EngineStatus[playerid] = 0;
  68. return 1;
  69. }
  70.  
  71. //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=OnPlayerEnterVehicle=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  72.  
  73. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  74. {
  75. if(!ispassenger)
  76. {
  77. GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
  78. SetVehicleParamsEx(vehicleid,VEHICLE_PARAMS_OFF,lights,alarm,doors,bonnet,boot,objective);
  79. EngineStatus[playerid] = 0;
  80. }
  81. return 1;
  82. }
  83.  
  84. //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=OnPlayerStateChange=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  85.  
  86. public OnPlayerStateChange(playerid, newstate, oldstate)
  87. {
  88. if(newstate == PLAYER_STATE_DRIVER)
  89. {
  90. new panels,tires;
  91. new carid = GetPlayerVehicleID(playerid);
  92. GetVehicleDamageStatus(carid, panels, doors, lights, tires);
  93. lights = encode_lights(1, 1, 1, 1);
  94. SetPVarInt(playerid, "vMainOn", 0);
  95. UpdateVehicleDamageStatus(carid, panels, doors, lights, tires);
  96. }
  97. else if(newstate == PLAYER_STATE_ONFOOT)
  98. {
  99. KillTimer(BlinkTime[playerid]);
  100. SetPVarInt(playerid, "CopFlash", 0);
  101. }
  102. return 1;
  103. }
  104.  
  105. //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=OnPlayerKeyStateChange=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  106.  
  107. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  108. {
  109. if(PRESSED(LIGHT_KEY))
  110. {
  111. if(IsPlayerInAnyVehicle(playerid) && GetPlayerVehicleSeat(playerid) == 0)
  112. {
  113. if(GetPVarInt(playerid, "CopFlash") == 0)
  114. {
  115. new panels,tires;
  116. new carid = GetPlayerVehicleID(playerid);
  117. GetVehicleDamageStatus(carid, panels, doors, lights, tires);
  118. switch(GetPVarInt(playerid, "vMainOn"))
  119. {
  120. case 0:{
  121. lights = encode_lights(0, 0, 0, 0);
  122. SetPVarInt(playerid, "vMainOn", 1);
  123. }
  124. case 1:{
  125. lights = encode_lights(1, 1, 1, 1);
  126. SetPVarInt(playerid, "vMainOn", 0);
  127. }
  128. }
  129. UpdateVehicleDamageStatus(carid, panels, doors, lights, tires);
  130. }
  131. }
  132. }
  133. if(PRESSED(KEY_CROUCH))
  134. {
  135. if(IsPublicService(GetPlayerVehicleID(playerid)) && GetPlayerVehicleSeat(playerid) == 0)
  136. {
  137. switch(GetPVarInt(playerid, "CopFlash"))
  138. {
  139. case 0:{
  140. KillTimer(BlinkTime[playerid]);
  141. BlinkTime[playerid] = SetTimerEx("vBlinker", PFLASH_RATE, 1, "i", playerid);
  142. SetPVarInt(playerid, "CopFlash", 1);
  143. }
  144. case 1:{
  145. KillTimer(BlinkTime[playerid]);
  146. new panels,tires;
  147. new carid = GetPlayerVehicleID(playerid);
  148. GetVehicleDamageStatus(carid, panels, doors, lights, tires);
  149. lights = encode_lights(1, 1, 1, 1);
  150. UpdateVehicleDamageStatus(carid, panels, doors, lights, tires);
  151. SetPVarInt(playerid, "CopFlash", 0);
  152. }
  153. }
  154. }
  155. }
  156. new vehicleid = GetPlayerVehicleID(playerid);
  157. GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
  158. SetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
  159. if(PRESSED(KEY_ANALOG_UP))
  160. {
  161. if(GetPVarInt(playerid, "Bonnet") == 0)
  162. {
  163. SetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,true,boot,objective);
  164. SetPVarInt(playerid, "Bonnet", 1);
  165. }
  166. else if(GetPVarInt(playerid, "Bonnet") == 1)
  167. {
  168. SetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,false,boot,objective);
  169. SetPVarInt(playerid, "Bonnet", 0);
  170. }
  171.  
  172. }
  173. if(PRESSED(KEY_ANALOG_DOWN))
  174. {
  175. if(GetPVarInt(playerid, "Boot") == 0)
  176. {
  177. SetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,true,objective);
  178. SetPVarInt(playerid, "Boot", 1);
  179. }
  180. else if(GetPVarInt(playerid, "Boot") == 1)
  181. {
  182. SetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,false,objective);
  183. SetPVarInt(playerid, "Boot", 0);
  184. }
  185.  
  186. }
  187. if (PRESSED(KEY_NO))
  188. {
  189. if(IsPlayerInAnyVehicle(playerid))
  190. {
  191. new veh = GetPlayerVehicleID(playerid);
  192. if(veh != INVALID_VEHICLE_ID)
  193. {
  194. if(EngineStatus[playerid] == 0 && (GetPlayerState(playerid)==PLAYER_STATE_DRIVER))
  195. {
  196. new string[256];
  197. new sendername[MAX_PLAYER_NAME];
  198. GetPlayerName(playerid, sendername, sizeof(sendername));
  199. GetVehicleParamsEx(veh,engine,lights,alarm,doors,bonnet,boot,objective);
  200. SetVehicleParamsEx(veh,VEHICLE_PARAMS_ON,lights,alarm,doors,bonnet,boot,objective);
  201. EngineStatus[playerid] = 1;
  202. SendClientMessage(playerid, 0xFFFFFFAA, "{FFFFFF}You have {2F991A}turn off {FFFFFF} engine!");
  203. format(string, sizeof(string), "* %s turn on engine.", sendername);
  204. ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
  205. }
  206. else if(EngineStatus[playerid] == 1 && (GetPlayerState(playerid)==PLAYER_STATE_DRIVER))
  207. {
  208. new string[256];
  209. new sendername[MAX_PLAYER_NAME];
  210. GetPlayerName(playerid, sendername, sizeof(sendername));
  211. GetVehicleParamsEx(veh,engine,lights,alarm,doors,bonnet,boot,objective);
  212. SetVehicleParamsEx(veh,VEHICLE_PARAMS_OFF,lights,alarm,doors,bonnet,boot,objective);
  213. EngineStatus[playerid] = 0;
  214. SendClientMessage(playerid, 0xFFFFFFAA, "{FFFFFF}You have {E31919}turn on {FFFFFF} engine!");
  215. format(string, sizeof(string), "* %s turn off engine.", sendername);
  216. ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
  217. }
  218. }
  219. }
  220. }
  221. return 1;
  222. }
  223.  
  224.  
  225. //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=ProxDetector=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  226.  
  227. forward ProxDetector(Float:radi, playerid, string[],col1,col2,col3,col4,col5);
  228. public ProxDetector(Float:radi, playerid, string[],col1,col2,col3,col4,col5)
  229. {
  230. if(IsPlayerConnected(playerid))
  231. {
  232. new Float:posx, Float:posy, Float:posz;
  233. new Float:oldposx, Float:oldposy, Float:oldposz;
  234. new Float:tempposx, Float:tempposy, Float:tempposz;
  235. GetPlayerPos(playerid, oldposx, oldposy, oldposz);
  236. //radi = 2.0; //Trigger Radius
  237. for(new i = 0; i < MAX_PLAYERS; i++)
  238. {
  239. if(IsPlayerConnected(i))
  240. {
  241. GetPlayerPos(i, posx, posy, posz);
  242. tempposx = (oldposx -posx);
  243. tempposy = (oldposy -posy);
  244. tempposz = (oldposz -posz);
  245. //printf("DEBUG: X:%f Y:%f Z:%f",posx,posy,posz);
  246. if (((tempposx < radi/16) && (tempposx > -radi/16)) && ((tempposy < radi/16) && (tempposy > -radi/16)) && ((tempposz < radi/16) && (tempposz > -radi/16)))
  247. {
  248. SendClientMessage(i, col1, string);
  249. }
  250. else if (((tempposx < radi/8) && (tempposx > -radi/8)) && ((tempposy < radi/8) && (tempposy > -radi/8)) && ((tempposz < radi/8) && (tempposz > -radi/8)))
  251. {
  252. SendClientMessage(i, col2, string);
  253. }
  254. else if (((tempposx < radi/4) && (tempposx > -radi/4)) && ((tempposy < radi/4) && (tempposy > -radi/4)) && ((tempposz < radi/4) && (tempposz > -radi/4)))
  255. {
  256. SendClientMessage(i, col3, string);
  257. }
  258. else if (((tempposx < radi/2) && (tempposx > -radi/2)) && ((tempposy < radi/2) && (tempposy > -radi/2)) && ((tempposz < radi/2) && (tempposz > -radi/2)))
  259. {
  260. SendClientMessage(i, col4, string);
  261. }
  262. else if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
  263. {
  264. SendClientMessage(i, col5, string);
  265. }
  266. }
  267. }
  268. }//not connected
  269. return 1;
  270. }
  271.  
  272. //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=vBlinker=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  273.  
  274. forward vBlinker(playerid);
  275. public vBlinker(playerid)
  276. {
  277. if(IsPlayerInAnyVehicle(playerid) && GetPVarInt(playerid, "CopFlash") != 1)
  278. {
  279. new Key;
  280. new ud, lr, panels,tires;
  281. new carid = GetPlayerVehicleID(playerid);
  282. GetPlayerKeys(playerid, Key, ud, lr);
  283. GetVehicleDamageStatus(carid, panels, doors, lights, tires);
  284.  
  285. if(lr > 0)
  286. {
  287. if(GetPVarInt(playerid, "vBLeft") == 1)
  288. {
  289. KillTimer(BlinkTime[playerid]);
  290. switch(GetPVarInt(playerid, "vMainOn")){
  291. case 0:{
  292. lights = encode_lights(1, 1, 1, 1);
  293. }
  294. case 1:{
  295. lights = encode_lights(0, 0, 0, 0);
  296. }
  297. }
  298. UpdateVehicleDamageStatus(carid, panels, doors, lights, tires);
  299. SetPVarInt(playerid, "vBLeft", 0);
  300. return 1;
  301. }
  302. }
  303. else if(lr < 0)
  304. {
  305. if(GetPVarInt(playerid, "vBRight") == 1)
  306. {
  307. KillTimer(BlinkTime[playerid]);
  308. switch(GetPVarInt(playerid, "vMainOn")){
  309. case 0:{
  310. lights = encode_lights(1, 1, 1, 1);
  311. }
  312. case 1:{
  313. lights = encode_lights(0, 0, 0, 0);
  314. }
  315. }
  316. UpdateVehicleDamageStatus(carid, panels, doors, lights, tires);
  317. SetPVarInt(playerid, "vBRight", 0);
  318. return 1;
  319. }
  320. }
  321.  
  322. if(GetPVarInt(playerid, "vBRight") == 1)
  323. {
  324. switch(GetPVarInt(playerid, "vMainOn")){
  325. case 0:{
  326. switch(GetPVarInt(playerid, "vBlinkOn")){
  327. case 0:{
  328. lights = encode_lights(1, 1, 0, 0);
  329. SetPVarInt(playerid, "vBlinkOn", 1);
  330. }
  331. case 1:{
  332. lights = encode_lights(1, 1, 1, 1);
  333. SetPVarInt(playerid, "vBlinkOn", 0);
  334. }
  335. }
  336. }
  337. case 1:{
  338. switch(GetPVarInt(playerid, "vBlinkOn")){
  339. case 0:{
  340. lights = encode_lights(0, 0, 1, 1);
  341. SetPVarInt(playerid, "vBlinkOn", 1);
  342. }
  343. case 1:{
  344. lights = encode_lights(0, 0, 0, 0);
  345. SetPVarInt(playerid, "vBlinkOn", 0);
  346. }
  347. }
  348. }
  349. }
  350. }
  351.  
  352. if(GetPVarInt(playerid, "vBLeft") == 1)
  353. {
  354. switch(GetPVarInt(playerid, "vMainOn")){
  355. case 0:{
  356. switch(GetPVarInt(playerid, "vBlinkOn")){
  357. case 0:{
  358. lights = encode_lights(0, 0, 1, 1);
  359. SetPVarInt(playerid, "vBlinkOn", 1);
  360. }
  361. case 1:{
  362. lights = encode_lights(1, 1, 1, 1);
  363. SetPVarInt(playerid, "vBlinkOn", 0);
  364. }
  365. }
  366. }
  367. case 1:{
  368. switch(GetPVarInt(playerid, "vBlinkOn")){
  369. case 0:{
  370. lights = encode_lights(1, 1, 0, 0);
  371. SetPVarInt(playerid, "vBlinkOn", 1);
  372. }
  373. case 1:{
  374. lights = encode_lights(0, 0, 0, 0);
  375. SetPVarInt(playerid, "vBlinkOn", 0);
  376. }
  377. }
  378. }
  379. }
  380. }
  381. UpdateVehicleDamageStatus(carid, panels, doors, lights, tires);
  382. }
  383. else if(GetPVarInt(playerid, "CopFlash") == 1)
  384. {
  385. new d[4];
  386. new carid = GetPlayerVehicleID(playerid);
  387. GetVehicleDamageStatus(carid, d[0], d[1], d[2], d[3]);
  388.  
  389. switch(GetPVarInt(playerid, "vBlinkOn"))
  390. {
  391. case 0:{
  392. d[2] = encode_lights(1, 1, 0, 0);
  393. SetPVarInt(playerid, "vBlinkOn", 1);
  394. }
  395. case 1:{
  396. d[2] = encode_lights(0, 0, 1, 1);
  397. SetPVarInt(playerid, "vBlinkOn", 0);
  398. }
  399. }
  400. UpdateVehicleDamageStatus(carid, d[0], d[1], d[2], d[3]);
  401. return 1;
  402. }
  403. return 1;
  404. }
  405.  
  406. //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=OnPlayerCommandText=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  407.  
  408. public OnPlayerCommandText(playerid, cmdtext[])
  409. {
  410. if (strcmp("/vehiclecontrol", cmdtext, true, 15) == 0)
  411. {
  412. SCM(playerid, COLOR_YELLOW, "__________________________________________Vehicle Control_____________________________________________");
  413. SCM(playerid,COLOR_LIGHTRED,"");
  414. SCM(playerid, COLOR_ROSUAPRINS,"Key N: Start/Stop engine");
  415. SCM(playerid, COLOR_BLUE,"Key num 8: Open/Close hood");
  416. SCM(playerid, COLOR_GREEN,"Key num 2: Open/Close trunk");
  417. SCM(playerid, COLOR_2RED,"Key 2: Turn on/off lights");
  418. SCM(playerid, COLOR_YELLOW, "");
  419. SCM(playerid, COLOR_YELLOW, "__________________________________________Vehicle Control_____________________________________________");
  420. return 1;
  421. }
  422. return 0;
  423. }
  424.  
  425. //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=Encode Lights=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  426.  
  427. encode_lights(light1, light2, light3, light4)
  428. {
  429.  
  430. return light1 | (light2 << 1) | (light3 << 2) | (light4 << 3);
  431.  
  432. }
  433.  
  434. //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=IsPublicService=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  435.  
  436. IsPublicService(carid)
  437. {
  438. new PS[11] = { 416, 427, 490, 528, 407, 544, 596, 598, 597, 599, 601 };
  439. for(new i = 0; i < sizeof(PS); i++)
  440. {
  441. if(GetVehicleModel(carid) == PS[i]) return 1;
  442. }
  443. return 0;
  444. }
  445. //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=The End.Do Not Remove Credits Please=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Advertisement
Add Comment
Please, Sign In to add comment