Advertisement
Wolf1227

Cheat-Master.ru Заправка FS

Oct 15th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.11 KB | None | 0 0
  1. #include a_samp
  2. #include sscanf2
  3. #include a_mysql
  4. #define c_main 0x99CCCCAA
  5. #define c_yell 0xFFFF00AA
  6. #define c_grad 0xCCCCCCAA
  7. #define TimeRashoda 1*1000 //60000 - 1 минута
  8. #define Vminus 1 //Отнимаемый бензин (при трате)
  9. #define max_stations 10 //Максимальное к-во заправок
  10. #define max_fuel 150
  11. #define mysql_host "localhost"
  12. #define mysql_db "samp"
  13. #define mysql_user "root"
  14. #define mysql_pass ""
  15. #define table "FuelStations"
  16. #define npub%0(%1) forward%0(%1); public%0(%1)
  17. enum Zapravki { ID, Float: posX, Float: posY, Float: posZ, Price, };
  18. new ZaprInfo[max_stations][Zapravki];
  19. new Benzin[MAX_VEHICLES],
  20. CheckBenzin[MAX_VEHICLES],
  21. l, a, d, b, _b, o,
  22. Text: ShowDatchik,
  23. CheckTimer, FuelTimer,
  24. CheckZapravka,
  25. bool: engine[MAX_VEHICLES],
  26. Text3D:textje,
  27. TOTAL_AZS,
  28. mysql_query[80], buf[512], cH;
  29. public OnFilterScriptInit()
  30. {
  31. print("Скрипт бензина от Wolf1227 загружен. Cheat-Master.RU");
  32. cH = mysql_connect(mysql_host, mysql_user, mysql_db, mysql_pass);
  33. switch(mysql_ping())
  34. {
  35. case 1: printf("< MySQL > Подключение к базе %s успешно выполнено", mysql_db);
  36. case -1: printf("< MySQL > Не удалось подключиться к базе %s", mysql_db);
  37. }
  38. mysql_debug(1);
  39. for(new i; i < MAX_VEHICLES; i++) Benzin[i] = 150, CheckBenzin[i] = 1;
  40. ShowDatchik = TextDrawCreate(26.966911, 323.527099, "F 0L");
  41. TextDrawLetterSize(ShowDatchik, 0.225999, 1.177000);
  42. TextDrawTextSize(ShowDatchik, 100.233413, 85.078506);
  43. TextDrawAlignment(ShowDatchik, 2);
  44. TextDrawColor(ShowDatchik, -5963521);
  45. TextDrawSetShadow(ShowDatchik, 0);
  46. TextDrawSetOutline(ShowDatchik, 1);
  47. TextDrawBackgroundColor(ShowDatchik, 51);
  48. TextDrawFont(ShowDatchik, 2);
  49. TextDrawSetProportional(ShowDatchik, 1);
  50. FuelTimer = SetTimer("Fuel", 60000, 1);
  51. SetTimer("Bugreport", 180000, 1);
  52. loadStations();
  53. return 1;
  54. }
  55. public OnFilterScriptExit()
  56. {
  57. TextDrawDestroy(ShowDatchik); print("Скрипт бензина от Wolf1227 выгружен. Cheat-Master.ru");
  58. KillTimer(FuelTimer);
  59. mysql_close(cH);
  60. Delete3DTextLabel(textje);
  61. return 1;
  62. }
  63. public OnVehicleDeath(vehicleid,killerid)
  64. {
  65. KillTimer(CheckTimer);
  66. engine[vehicleid] = false;
  67. }
  68. public OnVehicleSpawn(vehicleid)
  69. {
  70. Benzin[vehicleid] = max_fuel;
  71. CheckBenzin[vehicleid] = 1;
  72. engine[vehicleid] = false;
  73. }
  74. public OnPlayerExitVehicle(playerid, vehicleid)
  75. {
  76. TextDrawHideForPlayer(playerid, ShowDatchik);
  77. KillTimer(CheckTimer);
  78. }
  79. public OnPlayerStateChange(playerid, newstate, oldstate)
  80. {
  81. if(newstate == PLAYER_STATE_DRIVER)
  82. {
  83. new vehid = GetPlayerVehicleID(playerid);
  84. if(engine[vehid] == false)
  85. {
  86. if(IsABike(vehid) || IsAPlane(vehid) || IsABoat(vehid))
  87. SetVehicleParamsEx(vehid, true, false, false, false, false, false, false), engine[vehid] = true;
  88. else SendClientMessage(playerid, c_grad, "• Чтобы завести двигатель, нажмите \"2\".");
  89. }
  90. new ShowBenz[64];
  91. format(ShowBenz,64,"F %iL", Benzin[vehid]);
  92. TextDrawSetString(ShowDatchik,ShowBenz);
  93. TextDrawShowForPlayer(playerid,ShowDatchik);
  94.  
  95. if(CheckBenzin[vehid] == 0)
  96. {
  97. SendClientMessage(playerid, c_main, "* В этой машине нету бензина");
  98. SetVehicleParamsEx(vehid, 0, l, a, d, b, _b, o);
  99. return true;
  100. }
  101. }
  102. if(newstate != PLAYER_STATE_DRIVER)
  103. {
  104. TextDrawHideForPlayer(playerid,ShowDatchik);
  105. KillTimer(CheckTimer);
  106. }
  107. return true;
  108. }
  109. npub RashodBenzina(playerid)
  110. {
  111. new vehid = GetPlayerVehicleID(playerid);
  112. if(Benzin[vehid] <= 0)
  113. {
  114. SendClientMessage(playerid, c_main, "* Бензин кончился, машина заглохла");
  115. SetVehicleParamsEx(vehid, 0, l, a, d, b, _b, o);
  116. CheckBenzin[vehid] = 0;
  117. KillTimer(CheckTimer);
  118. return true;
  119. }
  120. Benzin[vehid] -= Vminus;
  121. new ShowBenz[64];
  122. format(ShowBenz,64,"F %iL",Benzin[vehid]);
  123. TextDrawSetString(ShowDatchik,ShowBenz);
  124. return true;
  125. }
  126. npub ZapravkaBenzina(playerid)
  127. {
  128. new cID = GetPlayerVehicleID(playerid);
  129. if(Benzin[cID] == max_fuel)
  130. {
  131. new strng[64];
  132. KillTimer(CheckZapravka);
  133. if(engine[cID] == true) CheckTimer = SetTimer("RashodBenzina", TimeRashoda, 1);
  134. format(strng, 64, "* Общее к-во литров: %i L | Сумма: %i$", GetPVarInt(playerid, "Liters"), GetPVarInt(playerid, "MinusMoney"));
  135. SendClientMessage(playerid, c_main, strng);
  136. SendClientMessage(playerid, c_yell, "* Автомобиль полностью заправлен");
  137. TogglePlayerControllable(playerid,1);
  138. CheckBenzin[cID] = 1;
  139. SetPVarInt(playerid, "MinusMoney", 0), SetPVarInt(playerid, "Liters", 0), SetPVarInt(playerid, "PriceFuel", 0);
  140. return true;
  141. }
  142. Benzin[cID]++;
  143. SetPVarInt(playerid, "Liters", GetPVarInt(playerid, "Liters")+1);
  144. for(new s; s < TOTAL_AZS; s++)
  145. {
  146. GivePlayerMoney(playerid, -GetPVarInt(playerid, "PriceFuel"));
  147. SetPVarInt(playerid, "MinusMoney", GetPVarInt(playerid, "PriceFuel") * GetPVarInt(playerid, "Liters"));
  148. }
  149. new ShowBenz[64];
  150. format(ShowBenz,64,"F %iL",Benzin[cID]);
  151. TextDrawSetString(ShowDatchik,ShowBenz);
  152. return true;
  153. }
  154. public OnPlayerCommandText(playerid, cmdtext[])
  155. {
  156. new params[128];
  157. sscanf(cmdtext, "s[30]s[128]", cmdtext, params);
  158. if(!strcmp(cmdtext, "/addazs", true))
  159. {
  160. if(sscanf(params, "d", params[0])) return SendClientMessage(playerid, c_grad, "Используйте: /addazs [цена за 1л бензина]");
  161. new Float:pos[3];
  162. GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
  163. mysql_format(cH, mysql_query, "INSERT INTO `"table"` (`posX`, `posY`, `posZ`, `Price`) VALUES('%f', '%f', '%f', '%d')", pos[0], pos[1], pos[2], params[0]);
  164. mysql_function_query(cH, mysql_query, false, "", "");
  165. loadStations();
  166. return true;
  167. }
  168. if(!strcmp(cmdtext, "/fill", true))
  169. {
  170. if(GetPlayerState(playerid) != 2) return SendClientMessage(playerid, c_main, "* Данная команда доступна только водителям");
  171. if(IsABoat(GetPlayerVehicleID(playerid)) || IsAPlane(GetPlayerVehicleID(playerid)) || IsABike(GetPlayerVehicleID(playerid)) || GetVehicleModel(GetPlayerVehicleID(playerid)) == 462)
  172. return SendClientMessage(playerid, c_main, "* Это нельзя заправить");
  173. for(new s; s < TOTAL_AZS; s++)
  174. {
  175. if(IsPlayerInRangeOfPoint(playerid, 15.0, ZaprInfo[s][posX], ZaprInfo[s][posY], ZaprInfo[s][posZ]))
  176. {
  177. TogglePlayerControllable(playerid,0);
  178. KillTimer(CheckTimer);
  179. CheckZapravka = SetTimer("ZapravkaBenzina", 100, 1);
  180. SetPVarInt(playerid, "PriceFuel", ZaprInfo[s][Price]);
  181. return true;
  182. }
  183. }
  184. return SendClientMessage(playerid, c_main, "* Вы не на заправке");
  185. }
  186. return false;
  187. }
  188. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  189. {
  190. if(newkeys == KEY_SUBMISSION)
  191. {
  192. new vID = GetPlayerVehicleID(playerid);
  193. if(IsAPlane(vID) || IsABoat(vID) || IsABike(vID)) return 1;
  194. if(Benzin[vID] == 0) return SendClientMessage(playerid, c_main, "* В этом авто нет бензина");
  195. switch(engine[vID])
  196. {
  197. case false:
  198. {
  199. SetVehicleParamsEx(vID, true, l, a, d, b, _b, o);
  200. engine[vID] = true;
  201. CheckTimer = SetTimer("RashodBenzina", TimeRashoda, 1);
  202. }
  203. case true:
  204. {
  205. SetVehicleParamsEx(vID, false, l, a, d, b, _b, o);
  206. engine[vID] = false;
  207. KillTimer(CheckTimer);
  208. }
  209. }
  210. }
  211. return true;
  212. }
  213. IsABoat(carid)
  214. {
  215. new Boats[] = {472, 473, 493, 495, 484, 430, 454, 453, 452, 446};
  216. for(new i = 0; i < sizeof(Boats); i++) if(GetVehicleModel(carid) == Boats[i]) return 1;
  217. return 0;
  218. }
  219. IsAPlane(carid)
  220. {
  221. new AirVeh[] = {592, 577, 511, 512, 593, 520, 553, 476, 519, 460, 513, 548, 425, 417, 487, 488, 497, 563, 447, 469};
  222. for(new i = 0; i < sizeof(AirVeh); i++) if(GetVehicleModel(carid) == AirVeh[i]) return 1;
  223. return 0;
  224. }
  225. IsABike(carid)
  226. {
  227. if(GetVehicleModel(carid) == 509 || GetVehicleModel(carid) == 481 || GetVehicleModel(carid) == 510) return 1;
  228. return 0;
  229. }
  230. npub Fuel() { for(new car = 0; car != MAX_VEHICLES; car++) if(engine[car] == true) Benzin[car]--; }
  231. stock loadStations()
  232. {
  233. mysql_function_query(cH, "SELECT * FROM `"table"`", true, "OnLoadStationsCallback", "");
  234. return 1;
  235. }
  236. npub OnLoadStationsCallback()
  237. {
  238. new time = GetTickCount(), r, f, i;
  239. cache_get_data(r, f);
  240. for(i = 0; i < r; i++)
  241. {
  242. cache_get_field_content(i, "ID", buf), ZaprInfo[i][ID] = strval(buf);
  243. cache_get_field_content(i, "posX", buf), ZaprInfo[i][posX] = floatstr(buf);
  244. cache_get_field_content(i, "posY", buf), ZaprInfo[i][posY] = floatstr(buf);
  245. cache_get_field_content(i, "posZ", buf), ZaprInfo[i][posZ] = floatstr(buf);
  246. cache_get_field_content(i, "Price", buf), ZaprInfo[i][Price] = strval(buf);
  247. new text[100];
  248. format(text, 100, "{99CCCC}Цена за 1 литр бензина: {FFCC33}%i$", ZaprInfo[i][Price]);
  249. textje = Create3DTextLabel(text, 0xFFFFFFFF, ZaprInfo[i][posX], ZaprInfo[i][posY], ZaprInfo[i][posZ], 20.0, 0, 0);
  250. TOTAL_AZS++;
  251. }
  252. printf("* [ АЗС ] Было загружено %i АЗС за %i (ms)", TOTAL_AZS, GetTickCount() - time);
  253. return 1;
  254. }
  255. stock saveStations(idst)
  256. {
  257. if(idst == -1) for(idst = 0; idst < TOTAL_AZS; idst++) saveStations(idst);
  258. else
  259. {
  260. format(buf, sizeof(buf), "UPDATE `"table"` SET `posX` = '%f', `posY` = '%f', `posZ` = '%f', `Price` = '%d' WHERE `ID` = '%d'",
  261. ZaprInfo[idst][posX],
  262. ZaprInfo[idst][posY],
  263. ZaprInfo[idst][posZ],
  264. ZaprInfo[idst][Price],
  265. idst);
  266. mysql_function_query(cH, buf, false, "", "");
  267. }
  268. return 1;
  269. }
  270. public OnQueryError(errorid,error[],callback[],query[],connectionHandle) return printf("EID: %i | Error: %s | Query: %s", errorid, error, query);
  271. npub Bugreport() { SendClientMessageToAll(0xFFCC66FF, "[ Mini Benzin Script ] Нашли баг, недоработку? Пишите разработчику скрипта по контактам ниже:"), SendClientMessageToAll(0xFFCC66FF, "[ Mini Benzin Script ] Skype: medoro-wolf ; Cheat-Master.Ru user #3603 (( Wolf1227 ))"); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement