Guest User

HomerJay

a guest
Sep 18th, 2008
3,188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.31 KB | None | 0 0
  1. /*
  2. .:: Vehicle Functions ::.
  3. .:: Coded by HomerJay ::.
  4. .:: Version: V3 ::.
  5. .:: (c) Copyrights X-Tras.Net ::.
  6.  
  7. */
  8.  
  9. #include <a_samp>
  10.  
  11. #define YELLOW 0xFFFF00AA
  12. #define WHITE 0xFFFFFFAA
  13. #define MAX_GAS 100 // Change as u wanna
  14. #define GAS_PRICE 20 // Per liter
  15.  
  16. new VehicleGas[MAX_VEHICLES];
  17. new VehicleStarted[MAX_VEHICLES];
  18. new Filling[MAX_PLAYERS];
  19.  
  20. new Menu:Gas;
  21. new FuelTimer;
  22. new RefillTimer;
  23.  
  24. new VehicleTittle[][] =
  25. {
  26. "Landstalker", "Bravura", "Buffalo", "Linerunner", "Perrenial", "Sentinel",
  27. "Dumper", "Firetruck", "Trashmaster", "Stretch", "Manana", "Infernus", "Voodoo",
  28. "Pony", "Mule", "Cheetah", "Ambulance", "Leviathan", "Moonbeam", "Esperanto",
  29. "Taxi", "Washington", "Bobcat", "Whoopee", "BF Injection", "Hunter", "Premier",
  30. "Enforcer", "Securicar", "Banshee", "Predator", "Bus", "Rhino", "Barracks",
  31. "Hotknife", "Trailer 1", "Previon", "Coach", "Cabbie", "Stallion", "Rumpo",
  32. "RC Bandit", "Romero", "Packer", "Monster", "Admiral", "Squalo", "Seasparrow",
  33. "Pizzaboy", "Tram", "Trailer 2", "Turismo", "Speeder", "Reefer", "Tropic", "Flatbed",
  34. "Yankee", "Caddy", "Solair", "Berkley's RC Van", "Skimmer", "PCJ-600", "Faggio",
  35. "Freeway", "RC Baron", "RC Raider", "Glendale", "Oceanic", "Sanchez", "Sparrow",
  36. "Patriot", "Quad", "Coastguard", "Dinghy", "Hermes", "Sabre", "Rustler", "ZR-350",
  37. "Walton", "Regina", "Comet", "BMX", "Burrito", "Camper", "Marquis", "Baggage",
  38. "Dozer", "Maverick", "News Chopper", "Rancher", "FBI Rancher", "Virgo", "Greenwood",
  39. "Jetmax", "Hotring", "Sandking", "Blista Compact", "Police Maverick", "Boxvillde",
  40. "Benson", "Mesa", "RC Goblin", "Hotring Racer A", "Hotring Racer B", "Bloodring Banger",
  41. "Rancher", "Super GT", "Elegant", "Journey", "Bike", "Mountain Bike", "Beagle",
  42. "Cropduster", "Stunt", "Tanker", "Roadtrain", "Nebula", "Majestic", "Buccaneer",
  43. "Shamal", "Hydra", "FCR-900", "NRG-500", "HPV1000", "Cement Truck", "Tow Truck",
  44. "Fortune", "Cadrona", "FBI Truck", "Willard", "Forklift", "Tractor", "Combine",
  45. "Feltzer", "Remington", "Slamvan", "Blade", "Freight", "Streak", "Vortex", "Vincent",
  46. "Bullet", "Clover", "Sadler", "Firetruck", "Hustler", "Intruder", "Primo", "Cargobob",
  47. "Tampa", "Sunrise", "Merit", "Utility", "Nevada", "Yosemite", "Windsor", "Monster",
  48. "Monster", "Uranus", "Jester", "Sultan", "Stratum", "Elegy", "Raindance", "RC Tiger",
  49. "Flash", "Tahoma", "Savanna", "Bandito", "Freight Flat", "Streak Carriage", "Kart",
  50. "Mower", "Dune", "Sweeper", "Broadway", "Tornado", "AT-400", "DFT-30", "Huntley",
  51. "Stafford", "BF-400", "News Van", "Tug", "Trailer 3", "Emperor", "Wayfarer", "Euros",
  52. "Hotdog", "Club", "Freight Box", "Trailer", "Andromada", "Dodo", "RC Cam", "Launch",
  53. "LSPD Car", "SFPD Car", "LVPD Car", "Police Ranger", "Picador", "S.W.A.T Tank", "Alpha",
  54. "Phoenix", "Glendale", "Sadler", "Luggage Trailer 1", "Luggage Trailer 2", "Stairs Trailer",
  55. "Boxville", "Utility Trailer 1", "Utility Trailer 2"
  56. };
  57.  
  58. forward FuelUpdate();
  59. forward SpeedUpdate();
  60. forward IsAtGasStation(playerid);
  61. forward ReFill(playerid);
  62. forward Start(playerid);
  63.  
  64. public OnFilterScriptInit()
  65. {
  66. FuelTimer = SetTimer("FuelUpdate",11000,1);
  67. for(new c;c<MAX_VEHICLES;c++)
  68. {
  69. VehicleGas[c] = 100;
  70. }
  71. Gas = CreateMenu("~r~G~w~as Station",1,50,220,200,200);
  72. AddMenuItem(Gas,0,"Natural 95");
  73. AddMenuItem(Gas,0,"Normal 98");
  74. AddMenuItem(Gas,0,"Diesel");
  75. AddMenuItem(Gas,0,"Exit");
  76. return 1;
  77. }
  78.  
  79. public OnFilterScriptExit()
  80. {
  81. DestroyMenu(Gas);
  82. KillTimer(FuelTimer);
  83. return 1;
  84. }
  85.  
  86. public OnPlayerConnect(playerid)
  87. {
  88. Filling[playerid] = 0;
  89. return 1;
  90. }
  91.  
  92. public OnVehicleSpawn(vehicleid)
  93. {
  94. VehicleGas[vehicleid] = 100;
  95. return 1;
  96. }
  97.  
  98. public OnVehicleDeath(vehicleid, killerid)
  99. {
  100. return 1;
  101. }
  102.  
  103. public OnPlayerCommandText(playerid, cmdtext[])
  104. {
  105. new VID = GetPlayerVehicleID(playerid);
  106. new MOD = GetVehicleModel(playerid);
  107.  
  108. if(strcmp(cmdtext, "/gas", true) == 0)
  109. {
  110. if(IsPlayerConnected(playerid))
  111. {
  112. if(!IsPlayerInAnyVehicle(playerid) || MOD == 510 || MOD == 509 || MOD == 481)
  113. {
  114. SendClientMessage(playerid,WHITE,"* You are not in a Vehicle / You can't fill that Vehicle!");
  115. return 1;
  116. }
  117. if(!IsAtGasStation(playerid))
  118. {
  119. SendClientMessage(playerid,WHITE,"* You are not at the Gas Station!");
  120. return 1;
  121. }
  122. if(VehicleGas[VID] < MAX_GAS)
  123. {
  124. ShowMenuForPlayer(Gas,playerid);
  125. TogglePlayerControllable(playerid,0);
  126. }
  127. else
  128. {
  129. SendClientMessage(playerid,WHITE,"* The Tank is full!");
  130. }
  131. }
  132. return 1;
  133. }
  134. if(strcmp(cmdtext, "/exit", true) == 0)
  135. {
  136. if(IsPlayerConnected(playerid))
  137. {
  138. if(IsPlayerInAnyVehicle(playerid))
  139. {
  140. RemovePlayerFromVehicle(playerid);
  141. SendClientMessage(playerid,YELLOW,"* You left the vehicle.");
  142. TogglePlayerControllable(playerid,1);
  143. }
  144. else
  145. {
  146. SendClientMessage(playerid,WHITE,"* You are not in a Vehicle!");
  147. }
  148. }
  149. return 1;
  150. }
  151. return 0;
  152. }
  153.  
  154. public OnPlayerStateChange(playerid, newstate, oldstate)
  155. {
  156. new VID = GetPlayerVehicleID(playerid);
  157. new MOD = GetVehicleModel(playerid);
  158. new string[128];
  159.  
  160. if(newstate == PLAYER_STATE_DRIVER)
  161. {
  162. format(string, sizeof(string), "~g~%s",VehicleTittle[GetVehicleModel(VID)-400]);
  163. GameTextForPlayer(playerid,string,3500,1);
  164. if(VehicleStarted[VID] == 0 && MOD != 510 && MOD != 509 && MOD != 481)
  165. {
  166. TogglePlayerControllable(playerid,0);
  167. SendClientMessage(playerid,WHITE,"* This Vehicle is not Started yet. You can start it with key: 'TAB'");
  168. }
  169. else
  170. {
  171. SendClientMessage(playerid,YELLOW,"* This Vehicle is already started!");
  172. }
  173. if(VehicleGas[VID] < 1)
  174. {
  175. SendClientMessage(playerid,WHITE,"* No fuel in Vehicle!");
  176. }
  177. }
  178. return 1;
  179. }
  180.  
  181. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  182. {
  183. if(newkeys == KEY_ACTION)
  184. {
  185. if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
  186. {
  187. if(IsPlayerConnected(playerid))
  188. {
  189. new VID = GetPlayerVehicleID(playerid);
  190. if(VehicleStarted[VID] == 0)
  191. {
  192. SendClientMessage(playerid,YELLOW,"* Starting Vehicle ...");
  193. SetTimerEx("Start",3500,0,"i",playerid);
  194. }
  195. }
  196. }
  197. }
  198. return 1;
  199. }
  200.  
  201. public OnPlayerSelectedMenuRow(playerid, row)
  202. {
  203. new Menu:Current = GetPlayerMenu(playerid);
  204. if(Current == Gas)
  205. {
  206. switch(row)
  207. {
  208. case 0:
  209. {
  210. GameTextForPlayer(playerid,"~b~Natural 95 ~n~ ~w~Refueling vehicle ~n~~g~Please wait..",4000,3);
  211. RefillTimer = SetTimerEx("ReFill",2000,1,"i",playerid);
  212. Filling[playerid] = 1;
  213. TogglePlayerControllable(playerid,0);
  214. }
  215. case 1:
  216. {
  217. GameTextForPlayer(playerid,"~b~Natural 98 ~n~ ~w~Refueling vehicle ~n~~g~Please wait..",4000,3);
  218. RefillTimer = SetTimerEx("ReFill",2000,1,"i",playerid);
  219. Filling[playerid] = 1;
  220. TogglePlayerControllable(playerid,0);
  221. }
  222. case 2:
  223. {
  224. GameTextForPlayer(playerid,"~b~Super Diesel ~n~ ~w~Refueling vehicle ~n~~g~Please wait..",4000,3);
  225. RefillTimer = SetTimerEx("ReFill",2000,1,"i",playerid);
  226. Filling[playerid] = 1;
  227. TogglePlayerControllable(playerid,0);
  228. }
  229. case 3:
  230. {
  231. HideMenuForPlayer(Gas,playerid);
  232. TogglePlayerControllable(playerid,1);
  233. }
  234. }
  235. }
  236. return 1;
  237. }
  238.  
  239. public OnPlayerExitedMenu(playerid)
  240. {
  241. TogglePlayerControllable(playerid,1);
  242. return 1;
  243. }
  244.  
  245. public FuelUpdate()
  246. {
  247. new string[256];
  248. for(new i=0;i<MAX_PLAYERS;i++)
  249. {
  250. new VID = GetPlayerVehicleID(i);
  251. new MOD = GetVehicleModel(i);
  252. if(GetPlayerState(i) == PLAYER_STATE_DRIVER)
  253. {
  254. if(IsPlayerConnected(i))
  255. {
  256. if(Filling[i] == 0 && VehicleStarted[VID] == 1 && MOD != 510 && MOD != 509 && MOD != 481)
  257. {
  258. if(VehicleGas[VID] >= 1)
  259. {
  260. VehicleGas[VID] -= 1;
  261. format(string, sizeof(string),"~n~~n~~n~~n~~n~~n~~n~~n~~n~~w~|~b~FUEL: ~w~%d%|",VehicleGas[VID]);
  262. GameTextForPlayer(i,string,11500,3);
  263. }
  264. else
  265. {
  266. TogglePlayerControllable(i,0);
  267. GameTextForPlayer(i,"~n~~n~~n~~n~~b~Your car is without fuel!",2500,3);
  268. SendClientMessage(i,WHITE,"* Your Vehicle is without an Gas! Use '/exit' to get out.");
  269. }
  270. }
  271. }
  272. }
  273. }
  274. return 1;
  275. }
  276.  
  277. public ReFill(playerid)
  278. {
  279. new VID = GetPlayerVehicleID(playerid);
  280. new string[128];
  281. if(IsPlayerConnected(playerid))
  282. {
  283. if(IsPlayerInAnyVehicle(playerid))
  284. {
  285. if(VehicleGas[VID] < 100)
  286. {
  287. if(GetPlayerMoney(playerid) >= 200)
  288. {
  289. VehicleGas[VID] += 5;
  290. format(string, sizeof(string),"~n~~n~~n~~y~FUEL: ~w~%d%",VehicleGas[VID]);
  291. GameTextForPlayer(playerid,string,2000,3);
  292. GivePlayerMoney(playerid,-200);
  293. }
  294. else
  295. {
  296. format(string, sizeof(string),"* You don't have $%d to pay!",GAS_PRICE);
  297. SendClientMessage(playerid,WHITE,string);
  298. TogglePlayerControllable(playerid,1);
  299. Filling[playerid] = 0;
  300. KillTimer(RefillTimer);
  301. }
  302. }
  303. else
  304. {
  305. SendClientMessage(playerid,YELLOW,"* Your Vehicle has been successfully Filled Up!");
  306. VehicleGas[VID] = 100;
  307. Filling[playerid] = 0;
  308. KillTimer(RefillTimer);
  309. TogglePlayerControllable(playerid,1);
  310. }
  311. }
  312. }
  313. return 1;
  314. }
  315.  
  316. public Start(playerid)
  317. {
  318. new VID = GetPlayerVehicleID(playerid);
  319. new RandStart = random(2);
  320. if(IsPlayerConnected(playerid))
  321. {
  322. if(IsPlayerInAnyVehicle(playerid))
  323. {
  324. switch(RandStart)
  325. {
  326. case 0:
  327. {
  328. VehicleStarted[VID] = 1;
  329. TogglePlayerControllable(playerid,1);
  330. SendClientMessage(playerid,YELLOW,"* Vehicle successfully Started!");
  331. }
  332. case 1:
  333. {
  334. SendClientMessage(playerid,WHITE,"* Starting Vehicle Failed!");
  335. }
  336. }
  337. }
  338. }
  339. return 1;
  340. }
  341.  
  342. public IsAtGasStation(playerid)
  343. {
  344. if(IsPlayerConnected(playerid))
  345. {
  346. if(PlayerToPoint(playerid,1595.5406, 2198.0520, 10.3863,10))
  347. {
  348. return 1;
  349. }
  350. else if(PlayerToPoint(playerid,2202.0649, 2472.6697, 10.5677,10))
  351. {
  352. return 1;
  353. }
  354. else if(PlayerToPoint(playerid,2115.1929, 919.9908, 10.5266,10))
  355. {
  356. return 1;
  357. }
  358. else if(PlayerToPoint(playerid,2640.7209, 1105.9565, 10.5274,10))
  359. {
  360. return 1;
  361. }
  362. else if(PlayerToPoint(playerid,608.5971, 1699.6238, 6.9922,10))
  363. {
  364. return 1;
  365. }
  366. else if(PlayerToPoint(playerid,618.4878, 1684.5792, 6.9922,10))
  367. {
  368. return 1;
  369. }
  370. else if(PlayerToPoint(playerid,2146.3467, 2748.2893, 10.5245,10))
  371. {
  372. return 1;
  373. }
  374. else if(PlayerToPoint(playerid,-1679.4595, 412.5129, 6.9973,10))
  375. {
  376. return 1;
  377. }
  378. else if(PlayerToPoint(playerid,-1327.5607, 2677.4316, 49.8093,10))
  379. {
  380. return 1;
  381. }
  382. else if(PlayerToPoint(playerid,-1470.0050, 1863.2375, 32.3521,10))
  383. {
  384. return 1;
  385. }
  386. else if(PlayerToPoint(playerid,-2409.2200, 976.2798, 45.2969,10))
  387. {
  388. return 1;
  389. }
  390. else if(PlayerToPoint(playerid,-2244.1396, -2560.5833, 31.9219,10))
  391. {
  392. return 1;
  393. }
  394. else if(PlayerToPoint(playerid,-1606.0544, -2714.3083, 48.5335,10))
  395. {
  396. return 1;
  397. }
  398. else if(PlayerToPoint(playerid,1937.4293, -1773.1865, 13.3828,10))
  399. {
  400. return 1;
  401. }
  402. else if(PlayerToPoint(playerid,-91.3854, -1169.9175, 2.4213,10))
  403. {
  404. return 1;
  405. }
  406. else if(PlayerToPoint(playerid,1383.4221, 462.5385, 20.1506,10))
  407. {
  408. return 1;
  409. }
  410. else if(PlayerToPoint(playerid,660.4590, -565.0394, 16.3359,10))
  411. {
  412. return 1;
  413. }
  414. else if(PlayerToPoint(playerid,1381.7206, 459.1907, 20.3452,10))
  415. {
  416. return 1;
  417. }
  418. else if(PlayerToPoint(playerid,-1605.7156, -2714.4573, 48.5335,10))
  419. {
  420. return 1;
  421. }
  422. }
  423. return 0;
  424. }
  425.  
  426. PlayerToPoint(playerid,Float:x,Float:y,Float:z,radius) //Not my script
  427. {
  428. if(GetPlayerDistanceToPointEx(playerid,x,y,z) < radius)
  429. {
  430. return 1;
  431. }
  432. return 0;
  433. }
  434.  
  435. GetPlayerDistanceToPointEx(playerid,Float:x,Float:y,Float:z)
  436. {
  437. new Float:x1,Float:y1,Float:z1;
  438. new Float:tmpdis;
  439. GetPlayerPos(playerid,x1,y1,z1);
  440. tmpdis = floatsqroot(floatpower(floatabs(floatsub(x,x1)),2)+floatpower(floatabs(floatsub(y,y1)),2)+floatpower(floatabs(floatsub(z,z1)),2));
  441. return floatround(tmpdis);
  442. }
Advertisement
Add Comment
Please, Sign In to add comment