Advertisement
Guest User

Don Corello

a guest
Aug 17th, 2009
2,331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.32 KB | None | 0 0
  1. /*
  2. .::Simple Fuel Script::.
  3. +
  4. .::Engine Starting::.
  5. ---------------------
  6. .::Coded by Don_Corello::.
  7. .::2008::.
  8. .::NY-Gaming.com::.
  9.  
  10. Version V1:
  11. Command /exit when you dont have a fuel.
  12. If you have full vehicle, you cant refill it...
  13. Thanks to Andre9977 for Gas Stations positions!!
  14. */
  15.  
  16. #include <a_samp>
  17.  
  18. #define SCM SendClientMessage
  19.  
  20. new Menu:Gas;
  21.  
  22. new FuelTimer;
  23. new RefillTimer;
  24.  
  25. new Vgas[MAX_VEHICLES];
  26. new VehicleStarted[MAX_VEHICLES];
  27.  
  28. new Tankuje[MAX_PLAYERS];
  29.  
  30. forward FuelUpdate();
  31. forward ReFill(playerid);
  32. forward Starting(playerid);
  33. forward IsAtGasStation(playerid);
  34.  
  35. public OnFilterScriptInit()
  36. {
  37. print("-------------------------------------");
  38. print("------Simple-Fuel-System-BETA--------");
  39. print("------------NY-Gaming.com------------");
  40.  
  41. FuelTimer = SetTimer("FuelUpdate",7000,1);
  42.  
  43. new RandGas;
  44. RandGas = random(250);
  45. new Car;
  46. for(Car=0;Car<MAX_VEHICLES;Car++)
  47. {
  48. Vgas[Car] = RandGas;
  49. }
  50.  
  51. Gas = CreateMenu("~g~G~w~as ~g~S~w~tation:",1,50,220,200,200);
  52. AddMenuItem(Gas,0,"Petrol");
  53. AddMenuItem(Gas,0,"Unleaded");
  54. AddMenuItem(Gas,0,"Diesel");
  55. AddMenuItem(Gas,0,"Exit");
  56. return 1;
  57. }
  58.  
  59. public OnFilterScriptExit()
  60. {
  61. DestroyMenu(Gas);
  62. KillTimer(FuelTimer);
  63. return 1;
  64. }
  65.  
  66. public OnPlayerCommandText(playerid, cmdtext[])
  67. {
  68. if(strcmp("/refuel", cmdtext, true, 10) == 0)
  69. {
  70. if(IsAtGasStation(playerid))
  71. {
  72. if(IsPlayerInAnyVehicle(playerid))
  73. {
  74. new VID = GetPlayerVehicleID(playerid);
  75. if(Vgas[VID] < 100)
  76. {
  77. ShowMenuForPlayer(Gas,playerid);
  78. }else{
  79. SCM(playerid,0xFFFF00AA,".:: [ERROR]: Already full Fuel! ::.");
  80. }
  81. }else{
  82. SCM(playerid,0xFFFF00AA,".:: [ERROR]: You are not in a Vehicle! ::.");
  83. }
  84. }else{
  85. SCM(playerid,0xFFFF00AA,".:: [ERROR]: You are not at a Gas Station! ::.");
  86. }
  87. return 1;
  88. }
  89. if(strcmp("/exit", cmdtext, true, 10) == 0)
  90. {
  91. if(IsPlayerConnected(playerid))
  92. {
  93. if(IsPlayerInAnyVehicle(playerid))
  94. {
  95. RemovePlayerFromVehicle(playerid);
  96. TogglePlayerControllable(playerid, 1);
  97. SCM(playerid,0xFFFF00AA,".:: [VEHICLE]: You Leave the Vehicle! ::.");
  98. }else{
  99. SCM(playerid,0xFFFF00AA,".:: [ERROR]: You are not in a Vehicle! ::.");
  100. }
  101. }
  102. return 1;
  103. }
  104. return 0;
  105. }
  106.  
  107. public OnPlayerStateChange(playerid, newstate, oldstate)
  108. {
  109. new CarID = GetPlayerVehicleID(playerid);
  110.  
  111. if(newstate == PLAYER_STATE_DRIVER)
  112. {
  113. if(VehicleStarted[CarID] == 0)
  114. {
  115. TogglePlayerControllable(playerid,0);
  116. SCM(playerid,0xFFFF00AA,".:: [VEHICLE]: Engine Not Started, Please Press SHIFT! ::.");
  117. }else{
  118. SCM(playerid,0xFFFF00AA,".:: [VEHICLE]: Engine Already Started! ::.");
  119. }
  120. if(Vgas[CarID] < 1)
  121. {
  122. SCM(playerid,0xFFFF00AA,".:: [VEHICLE]: No Fuel! ::.");
  123. }
  124. }
  125. return 1;
  126. }
  127.  
  128. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  129. {
  130. if(newkeys == KEY_JUMP)
  131. {
  132. if(IsPlayerInAnyVehicle(playerid))
  133. {
  134. if(IsPlayerConnected(playerid))
  135. {
  136. new Vehicle = GetPlayerVehicleID(playerid);
  137. if(VehicleStarted[Vehicle] == 0)
  138. {
  139. SCM(playerid,0xFFFF00AA,"* Starting vehicle...");
  140. GameTextForPlayer(playerid,"~n~~n~~n~~n~~n~~n~~n~~g~Starting vehicle...",3000,3);
  141. SetTimerEx("Starting",3500,0,"i",playerid);
  142. }
  143. }
  144. }
  145. }
  146. }
  147.  
  148. public OnPlayerSelectedMenuRow(playerid, row)
  149. {
  150. new Menu:Current = GetPlayerMenu(playerid);
  151. if(Current == Gas)
  152. {
  153. switch(row)
  154. {
  155. case 0:
  156. {
  157. GameTextForPlayer(playerid,"~b~Petrol ~n~ ~w~Refueling vehicle ~n~~g~Please wait..",4000,3);
  158. RefillTimer = SetTimerEx("ReFill",2000,1,"i",playerid);
  159. Tankuje[playerid] = 1;
  160. TogglePlayerControllable(playerid,0);
  161. }
  162. case 1:
  163. {
  164. GameTextForPlayer(playerid,"~b~Unleaded 98 ~n~ ~w~Refueling vehicle ~n~~g~Please wait..",4000,3);
  165. RefillTimer = SetTimerEx("ReFill",2000,1,"i",playerid);
  166. Tankuje[playerid] = 1;
  167. TogglePlayerControllable(playerid,0);
  168. }
  169. case 2:
  170. {
  171. GameTextForPlayer(playerid,"~b~Super Diesel ~n~ ~w~Refueling vehicle ~n~~g~Please wait..",4000,3);
  172. RefillTimer = SetTimerEx("ReFill",2000,1,"i",playerid);
  173. Tankuje[playerid] = 1;
  174. TogglePlayerControllable(playerid,0);
  175. }
  176. case 3:
  177. {
  178. GameTextForPlayer(playerid,"~y~Have a nice day!",4000,3);
  179. HideMenuForPlayer(Gas,playerid);
  180. }
  181. }
  182. }
  183. return 1;
  184. }
  185.  
  186. public FuelUpdate()
  187. {
  188. new string[256];
  189. for(new i=0;i<MAX_PLAYERS;i++)
  190. {
  191. if(IsPlayerInAnyVehicle(i))
  192. {
  193. if(IsPlayerConnected(i))
  194. {
  195. new PCar = GetPlayerVehicleID(i);
  196. if(Tankuje[i] == 0 && VehicleStarted[PCar] == 1)
  197. {
  198. if(Vgas[PCar] >= 1)
  199. {
  200. Vgas[PCar] -= 1;
  201. format(string, sizeof(string),"~n~~n~~n~~n~~n~~n~~n~~n~~n~~b~FUEL: ~w~%d%",Vgas[PCar]);
  202. GameTextForPlayer(i,string,7500,3);
  203. }else{
  204. TogglePlayerControllable(i,0);
  205. GameTextForPlayer(i,"~n~~n~~n~~n~~b~No FUEL!",2500,3);
  206. SCM(i,0xFFFF00AA,".:: [VEHICLE]: No FUEL, Please Type '/exit'! ::.");
  207. }
  208. }
  209. }
  210. }
  211. }
  212. }
  213.  
  214. public ReFill(playerid)
  215. {
  216. new PCar = GetPlayerVehicleID(playerid);
  217. new string[256];
  218. if(IsPlayerConnected(playerid))
  219. {
  220. if(IsPlayerInAnyVehicle(playerid))
  221. {
  222. if(Vgas[PCar] < 100)
  223. {
  224. if(GetPlayerMoney(playerid) >= 200)
  225. {
  226. Vgas[PCar] += 5;
  227. format(string, sizeof(string),"~n~~n~~n~~y~FUEL: ~w~%d%",Vgas[PCar]);
  228. GameTextForPlayer(playerid,string,2000,3);
  229. GivePlayerMoney(playerid,-200);
  230. }else{
  231. SCM(playerid,0xFFFF00AA,".:: [ERROR]: You dont have Enough cash! ($200) ::.");
  232. TogglePlayerControllable(playerid,1);
  233. Tankuje[playerid] = 0;
  234. KillTimer(RefillTimer);
  235. }
  236. }else{
  237. SCM(playerid,0xFFFF00AA,"* Car successfully refilled!");
  238. Vgas[PCar] = 100;
  239. Tankuje[playerid] = 0;
  240. KillTimer(RefillTimer);
  241. TogglePlayerControllable(playerid,1);
  242. }
  243. }else{
  244. SCM(playerid,0xFFFF00AA,"* Refueling vehicle canceled!");
  245. }
  246. }
  247. }
  248.  
  249. public Starting(playerid)
  250. {
  251. new Vehicle = GetPlayerVehicleID(playerid);
  252. new RandomStart;
  253.  
  254. if(IsPlayerConnected(playerid))
  255. {
  256. if(IsPlayerInAnyVehicle(playerid))
  257. {
  258. RandomStart = random(4);
  259. switch(RandomStart)
  260. {
  261. case 0,1:
  262. {
  263. VehicleStarted[Vehicle] = 1;
  264. TogglePlayerControllable(playerid,1);
  265. SendClientMessage(playerid,0xFFFF00AA,"* Vehicle started!");
  266. }
  267. case 2,3:
  268. {
  269. SendClientMessage(playerid,0xFFFF00AA,"* Starting vehicle failed!");
  270. }
  271. }
  272. }
  273. }
  274. }
  275.  
  276. public IsAtGasStation(playerid)
  277. {
  278. if(IsPlayerConnected(playerid))
  279. {
  280. if(PlayerToPoint(playerid,1595.5406, 2198.0520, 10.3863,10))
  281. {
  282. return 1;
  283. }
  284. if(PlayerToPoint(playerid,2202.0649, 2472.6697, 10.5677,10))
  285. {
  286. return 1;
  287. }
  288. if(PlayerToPoint(playerid,2115.1929, 919.9908, 10.5266,10))
  289. {
  290. return 1;
  291. }
  292. if(PlayerToPoint(playerid,2640.7209, 1105.9565, 10.5274,10))
  293. {
  294. return 1;
  295. }
  296. if(PlayerToPoint(playerid,608.5971, 1699.6238, 6.9922,10))
  297. {
  298. return 1;
  299. }
  300. if(PlayerToPoint(playerid,618.4878, 1684.5792, 6.9922,10))
  301. {
  302. return 1;
  303. }
  304. if(PlayerToPoint(playerid,2146.3467, 2748.2893, 10.5245,10))
  305. {
  306. return 1;
  307. }
  308. if(PlayerToPoint(playerid,-1679.4595, 412.5129, 6.9973,10))
  309. {
  310. return 1;
  311. }
  312. if(PlayerToPoint(playerid,-1327.5607, 2677.4316, 49.8093,10))
  313. {
  314. return 1;
  315. }
  316. if(PlayerToPoint(playerid,-1470.0050, 1863.2375, 32.3521,10))
  317. {
  318. return 1;
  319. }
  320. if(PlayerToPoint(playerid,-2409.2200, 976.2798, 45.2969,10))
  321. {
  322. return 1;
  323. }
  324. if(PlayerToPoint(playerid,-2244.1396, -2560.5833, 31.9219,10))
  325. {
  326. return 1;
  327. }
  328. if(PlayerToPoint(playerid,-1606.0544, -2714.3083, 48.5335,10))
  329. {
  330. return 1;
  331. }
  332. if(PlayerToPoint(playerid,1937.4293, -1773.1865, 13.3828,10))
  333. {
  334. return 1;
  335. }
  336. if(PlayerToPoint(playerid,-91.3854, -1169.9175, 2.4213,10))
  337. {
  338. return 1;
  339. }
  340. if(PlayerToPoint(playerid,1383.4221, 462.5385, 20.1506,10))
  341. {
  342. return 1;
  343. }
  344. if(PlayerToPoint(playerid,660.4590, -565.0394, 16.3359,10))
  345. {
  346. return 1;
  347. }
  348. if(PlayerToPoint(playerid,1381.7206, 459.1907, 20.3452,10))
  349. {
  350. return 1;
  351. }
  352. if(PlayerToPoint(playerid,-1605.7156, -2714.4573, 48.5335,10))
  353. {
  354. return 1;
  355. }
  356.  
  357. }
  358. return 0;
  359. }
  360.  
  361. PlayerToPoint(playerid,Float:x,Float:y,Float:z,radius) // Not my script :)
  362. {
  363. if(GetPlayerDistanceToPointEx(playerid,x,y,z) < radius)
  364. {
  365. return 1;
  366. }
  367. return 0;
  368. }
  369.  
  370. GetPlayerDistanceToPointEx(playerid,Float:x,Float:y,Float:z)
  371. {
  372. new Float:x1,Float:y1,Float:z1;
  373. new Float:tmpdis;
  374. GetPlayerPos(playerid,x1,y1,z1);
  375. tmpdis = floatsqroot(floatpower(floatabs(floatsub(x,x1)),2)+floatpower(floatabs(floatsub(y,y1)),2)+floatpower(floatabs(floatsub(z,z1)),2));
  376. return floatround(tmpdis);
  377. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement