Advertisement
Guest User

Tank system

a guest
May 3rd, 2010
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.39 KB | None | 0 0
  1. /*
  2. *
  3. * Fuel System by RyDeR
  4. * DracoBlue for DCMD
  5. * Someone for the Gas Station Coördinates
  6. *
  7. */
  8. #include <a_samp>
  9.  
  10. #define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1 // Credits go to DracoBlue
  11.  
  12. #define COLOR_GREY 0xAFAFAFAA
  13. #define COLOR_GREEN 0x33FF33AA
  14. #define COLOR_YELLOW 0xFFFF00AA
  15. #define COLOR_WHITE 0xFFFFFFAA
  16. #define COLOR_BRIGHTRED 0xE60000FF
  17. #define COLOR_BLUE 0x0000FFAA
  18. #define COLOR_PURPLE 0x9900FFAA
  19. #define COLOR_BROWN 0x993300AA
  20. #define COLOR_ORANGE 0xFF9933AA
  21. #define COLOR_CYAN 0x99FFFFAA
  22. #define COLOR_TAN 0xFFFFCCAA
  23. #define COLOR_PINK 0xFF66FFAA
  24. #define COLOR_KHAKI 0x999900AA
  25. #define COLOR_LIME 0x99FF00AA
  26. #define COLOR_BLACK 0x000000AA
  27. #define COLOR_TURQ 0x00A3C0AA
  28. #define COLOR_LIGHTBLUE 0x33CCFFAA
  29. #define COLOR_DARKRED 0xAA993333
  30. #define COLOR_VIOLET 0x9955DEEE
  31. #define COLOR_RED 0xFB0000FF
  32.  
  33. #define DIVBY 1.300
  34.  
  35. new
  36. Benzin[MAX_VEHICLES],
  37. bool:PortableFuel[MAX_PLAYERS],
  38. FuelTimer;
  39.  
  40. new
  41. Text: Fuel[MAX_PLAYERS],
  42. Text: BlackBox,
  43. Text: Moving[MAX_PLAYERS];
  44.  
  45.  
  46. public OnFilterScriptInit()
  47. {
  48. FuelTimer = SetTimer("SubFuel", 12000, true);
  49. print("----------------------------------");
  50. print(" Fuel System by RyDeR - Loaded - ");
  51. print("----------------------------------");
  52.  
  53. BlackBox = TextDrawCreate(354.000000, 422.000000, "_");
  54. TextDrawBackgroundColor(BlackBox, 255);
  55. TextDrawFont(BlackBox, 1);
  56. TextDrawLetterSize(BlackBox, 0.509999, 1.000000);
  57. TextDrawColor(BlackBox, -1);
  58. TextDrawSetOutline(BlackBox, 0);
  59. TextDrawSetProportional(BlackBox, 1);
  60. TextDrawSetShadow(BlackBox, 1);
  61. TextDrawUseBox(BlackBox, 1);
  62. TextDrawBoxColor(BlackBox, 0xFF80001A);
  63. TextDrawTextSize(BlackBox, 277.000000, 51.000000);
  64.  
  65. new
  66. i;
  67.  
  68. while (i != GetMaxPlayers())
  69. {
  70. Fuel[i] = TextDrawCreate(258.000000, 421.000000, " ");
  71. TextDrawBackgroundColor(Fuel[i], 255);
  72. TextDrawFont(Fuel[i], 1);
  73. TextDrawLetterSize(Fuel[i], 0.250000, 1.100000);
  74. TextDrawColor(Fuel[i], -1);
  75. TextDrawSetOutline(Fuel[i], 0);
  76. TextDrawSetProportional(Fuel[i], 1);
  77. TextDrawSetShadow(Fuel[i], 1);
  78.  
  79. Moving[i] = TextDrawCreate(354.000000, 422.000000, "_");
  80. TextDrawBackgroundColor(Moving[i], 255);
  81. TextDrawFont(Moving[i], 1);
  82. TextDrawLetterSize(Moving[i], 0.509999, 1.000000);
  83. TextDrawColor(Moving[i], -1);
  84. TextDrawSetOutline(Moving[i], 0);
  85. TextDrawSetProportional(Moving[i], 1);
  86. TextDrawSetShadow(Moving[i], 1);
  87. TextDrawUseBox(Moving[i], 1);
  88. TextDrawBoxColor(Moving[i], 0xFF8000C1);
  89. TextDrawTextSize(Moving[i], 277.000000, 51.000000);
  90. ++i;
  91. }
  92.  
  93. new
  94. v;
  95.  
  96. while (v != MAX_VEHICLES)
  97. {
  98. Benzin[v] = random(100);
  99. ++v;
  100. }
  101. return 1;
  102. }
  103.  
  104. public OnFilterScriptExit()
  105. {
  106. new
  107. i,
  108. v;
  109.  
  110. while (i != GetMaxPlayers())
  111. {
  112. TextDrawDestroy(Fuel[i]);
  113. TextDrawDestroy(Moving[i]);
  114. ++i;
  115. }
  116. TextDrawDestroy(BlackBox);
  117. KillTimer(FuelTimer);
  118.  
  119. while (v != MAX_VEHICLES)
  120. {
  121. Benzin[v] = 100;
  122. ++v;
  123. }
  124. return 1;
  125. }
  126.  
  127. forward SubFuel();
  128. public SubFuel()
  129. {
  130. new
  131. i;
  132.  
  133. while (i != GetMaxPlayers())
  134. {
  135. if (IsPlayerInAnyVehicle(i))
  136. {
  137. new string[128];
  138. if(Benzin[GetPlayerVehicleID(i)] <0) Benzin[GetPlayerVehicleID(i)] = 0;
  139. if(IsPlayerInAnyVehicle(i))
  140. {
  141. Benzin[GetPlayerVehicleID(i)]-=1;
  142. format(string, 128, "Fuel: %%%d", Benzin[GetPlayerVehicleID(i)]);
  143. TextDrawSetString(Fuel[i], string), TextDrawShowForPlayer(i, Fuel[i]),
  144. TextDrawShowForPlayer(i, BlackBox),
  145. TextDrawTextSize(Moving[i], (354.0 - (Benzin[GetPlayerVehicleID(i)] / DIVBY)), 0.000000),
  146. TextDrawShowForPlayer(i, Moving[i]);
  147. }
  148. if (Benzin[GetPlayerVehicleID(i)] < 1)
  149. {
  150. Benzin[GetPlayerVehicleID(i)] = 0;
  151. GameTextForPlayer(i, "~n~~n~~n~~n~~n~~n~~n~~w~You don't have fuel in your vehicle.", 4000, 3);
  152. TogglePlayerControllable(i, false);
  153. RemovePlayerFromVehicle(i);
  154. }
  155. }
  156. else
  157. {
  158. TextDrawHideForPlayer(i, Fuel[i]),
  159. TextDrawHideForPlayer(i, BlackBox),
  160. TextDrawHideForPlayer(i, Moving[i]);
  161. GameTextForPlayer(i, " ", 100, 3);
  162. TogglePlayerControllable(i, true);
  163. }
  164. ++i;
  165. }
  166. return 1;
  167. }
  168.  
  169. public OnVehicleSpawn(vehicleid)
  170. {
  171. Benzin[vehicleid] = random(100);
  172. }
  173.  
  174. public OnPlayerConnect(playerid)
  175. {
  176. PortableFuel[playerid] = false;
  177. return 1;
  178. }
  179.  
  180. public OnPlayerDisconnect(playerid, reason)
  181. {
  182. TextDrawHideForPlayer(playerid, Fuel[playerid]);
  183. TextDrawHideForPlayer(playerid, Moving[playerid]);
  184. TextDrawHideForPlayer(playerid, BlackBox);
  185. return 1;
  186. }
  187.  
  188. public OnPlayerDeath(playerid, killerid, reason)
  189. {
  190. TextDrawHideForPlayer(playerid, Fuel[playerid]);
  191. TextDrawHideForPlayer(playerid, Moving[playerid]);
  192. TextDrawHideForPlayer(playerid, BlackBox);
  193. return 1;
  194. }
  195.  
  196. dcmd_fill (playerid, params[])
  197. {
  198. new
  199. miktar,
  200. string[128],
  201. string2[128],
  202. string3[128],
  203. string4[128],
  204. Fiyat,
  205. Sum;
  206.  
  207. if (!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED, ">> You are not in any vehicle to refill!");
  208. if (!IsAtGasStation(playerid)) return SendClientMessage(playerid, COLOR_RED, ">> You are not in a gas station!");
  209. if (!strlen(params)) return SendClientMessage(playerid, COLOR_RED, ">> /fill [amount in 0 - 100 l]");
  210. miktar = strval(params);
  211. if (miktar < 1 || miktar > 100) return SendClientMessage(playerid, COLOR_RED, ">> Wrong amount in liters! (0-100l)");
  212. if (Benzin[GetPlayerVehicleID(playerid)] >= 100) return SendClientMessage(playerid, COLOR_RED, ">> You can't refill. Your car is full!");
  213. Fiyat = (miktar * 2);
  214. format(string2, 128, ">> You don't have money enough! You need $%d.", Fiyat);
  215. if (GetPlayerMoney(playerid) < Fiyat) return SendClientMessage(playerid, COLOR_RED, string2);
  216. GivePlayerMoney(playerid, -Fiyat);
  217. format(string, 128, ">> You have filled your vehicle for %d liters. Cost: $%d.", miktar, Fiyat);
  218. SendClientMessage(playerid, COLOR_LIME, string);
  219. Benzin[GetPlayerVehicleID(playerid)] += miktar;
  220. if (Benzin[GetPlayerVehicleID(playerid)] > 100) Sum = miktar*2-Benzin[GetPlayerVehicleID(playerid)]+100, GivePlayerMoney(playerid, Sum), format(string4, 128, ">> You have choose a too large amount of liters that your car can't accept. Here's your change($%d).", Sum), SendClientMessage(playerid, COLOR_ORANGE, string4), Benzin[GetPlayerVehicleID(playerid)] = 100;
  221. format(string3, 128, "Fuel: %%%d", Benzin[GetPlayerVehicleID(playerid)]);
  222. TextDrawSetString(Fuel[playerid], string3),
  223. TextDrawShowForPlayer(playerid, Fuel[playerid]),
  224. TextDrawTextSize(Moving[playerid], (354.0 - (Benzin[GetPlayerVehicleID(playerid)] / DIVBY)), 0.000000),
  225. TextDrawShowForPlayer(playerid, Moving[playerid]);
  226. return 1;
  227. }
  228.  
  229. dcmd_buyfuel (playerid, params[])
  230. {
  231. #pragma unused params
  232. if (!IsAtGasStation(playerid)) return SendClientMessage(playerid, COLOR_RED, ">> You are not in a gas station!");
  233. if (PortableFuel[playerid] == true) return SendClientMessage(playerid, COLOR_RED, ">> You can't have more than one tank.");
  234. SendClientMessage(playerid, COLOR_LIME, ">> You have bought a little fuel tank. You can use it when your fuel is low. (/usefuel)");
  235. PortableFuel[playerid] = true;
  236. return 1;
  237. }
  238.  
  239. dcmd_usefuel (playerid, params[])
  240. {
  241. new
  242. string[128];
  243.  
  244. #pragma unused params
  245. if (!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED, ">> You are not in any vehicle!");
  246. if (PortableFuel[playerid] == false) return SendClientMessage(playerid, COLOR_RED, ">> You don't have a fuel tank with you. Buy one by writing /buyfuel.");
  247. if (Benzin[GetPlayerVehicleID(playerid)] >= 40) return SendClientMessage(playerid, COLOR_RED, ">> You have fuel enough.");
  248. SendClientMessage(playerid, COLOR_LIME, ">> You used your fuel tank. (Fuel +25)");
  249. Benzin[GetPlayerVehicleID(playerid)] += 25;
  250. PortableFuel[playerid] = false;
  251. format(string, 128, "Fuel: %%%d", Benzin[GetPlayerVehicleID(playerid)]);
  252. TextDrawSetString(Fuel[playerid], string),
  253. TextDrawShowForPlayer(playerid, Fuel[playerid]),
  254. TextDrawTextSize(Moving[playerid], (354.0 - (Benzin[GetPlayerVehicleID(playerid)] / DIVBY)), 0.000000),
  255. TextDrawShowForPlayer(playerid, Moving[playerid]);
  256. return 1;
  257. }
  258.  
  259. public OnPlayerCommandText(playerid, cmdtext[])
  260. {
  261. dcmd (fill, 4, cmdtext);
  262. dcmd (buyfuel, 7, cmdtext);
  263. dcmd (usefuel, 7, cmdtext);
  264. return 0;
  265. }
  266.  
  267. public OnPlayerStateChange(playerid, newstate, oldstate)
  268. {
  269. new
  270. string[128],
  271. string2[128];
  272.  
  273.  
  274. if(newstate == PLAYER_STATE_DRIVER)
  275. {
  276. format(string, 128, "Fuel: %%%d", Benzin[GetPlayerVehicleID(playerid)]);
  277. TextDrawSetString(Fuel[playerid], string),
  278. TextDrawShowForPlayer(playerid, Fuel[playerid]),
  279. TextDrawShowForPlayer(playerid, BlackBox),
  280. TextDrawTextSize(Moving[playerid], (354.0 - (Benzin[GetPlayerVehicleID(playerid)] / DIVBY)), 0.000000),
  281. TextDrawShowForPlayer(playerid, Moving[playerid]);
  282. if (Benzin[GetPlayerVehicleID(playerid)] < 1)
  283. {
  284. Benzin[GetPlayerVehicleID(playerid)] = 1;
  285. format(string2, 128, "Fuel: %%%d", Benzin[GetPlayerVehicleID(playerid)]);
  286. TextDrawSetString(Fuel[playerid], string2),
  287. TextDrawShowForPlayer(playerid, Fuel[playerid]),
  288. TextDrawTextSize(Moving[playerid], (354.0 - (Benzin[GetPlayerVehicleID(playerid)] / DIVBY)), 0.000000),
  289. TextDrawShowForPlayer(playerid, Moving[playerid]);
  290. }
  291. if(Benzin[GetPlayerVehicleID(playerid)] < 1)
  292. {
  293. Benzin[GetPlayerVehicleID(playerid)] = 0;
  294. GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~n~~n~~w~You don't have fuel in your vehicle.", 4000, 3);
  295. RemovePlayerFromVehicle(playerid);
  296. }
  297. }
  298. else if (newstate == PLAYER_STATE_ONFOOT)
  299. {
  300. TextDrawHideForPlayer(playerid, Fuel[playerid]),
  301. TextDrawHideForPlayer(playerid, BlackBox),
  302. TextDrawHideForPlayer(playerid, Moving[playerid]);
  303. TogglePlayerControllable(playerid, true);
  304. }
  305. return 1;
  306. }
  307.  
  308. stock IsAtGasStation(playerid)
  309. {
  310. if(IsPlayerConnected(playerid))
  311. {
  312. if(IsPlayerInRangeOfPoint(playerid, 6.0,1004.0070,-939.3102,42.1797) || IsPlayerInRangeOfPoint(playerid, 6.0,1944.3260,-1772.9254,13.3906))
  313. {
  314. return 1;
  315. }
  316. else if(IsPlayerInRangeOfPoint(playerid, 6.0,-90.5515,-1169.4578,2.4079) || IsPlayerInRangeOfPoint(playerid, 6.0,-1609.7958,-2718.2048,48.5391))
  317. {
  318. return 1;
  319. }
  320. else if(IsPlayerInRangeOfPoint(playerid, 6.0,-2029.4968,156.4366,28.9498) || IsPlayerInRangeOfPoint(playerid, 8.0,-2408.7590,976.0934,45.4175))
  321. {
  322. return 1;
  323. }
  324. else if(IsPlayerInRangeOfPoint(playerid, 5.0, -2243.9629,-2560.6477,31.8841) || IsPlayerInRangeOfPoint(playerid, 8.0,-1676.6323,414.0262,6.9484))
  325. {
  326. return 1;
  327. }
  328. else if(IsPlayerInRangeOfPoint(playerid, 6.0,2202.2349,2474.3494,10.5258) || IsPlayerInRangeOfPoint(playerid, 10.0, 614.9333,1689.7418,6.6968))
  329. {
  330. return 1;
  331. }
  332. else if(IsPlayerInRangeOfPoint(playerid, 8.0,-1328.8250,2677.2173,49.7665) || IsPlayerInRangeOfPoint(playerid, 6.0,70.3882,1218.6783,18.5165))
  333. {
  334. return 1;
  335. }
  336. else if(IsPlayerInRangeOfPoint(playerid, 8.0,2113.7390,920.1079,10.5255) || IsPlayerInRangeOfPoint(playerid, 6.0,-1327.7218,2678.8723,50.0625))
  337. {
  338. return 1;
  339. }
  340. else if(IsPlayerInRangeOfPoint(playerid, 12.0,1596.2595,2199.3120,10.8203))
  341. {
  342. return 1;
  343. }
  344. }
  345. return 0;
  346. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement