Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include a_samp
- #include sscanf2
- #include a_mysql
- #define c_main 0x99CCCCAA
- #define c_yell 0xFFFF00AA
- #define c_grad 0xCCCCCCAA
- #define TimeRashoda 1*1000 //60000 - 1 минута
- #define Vminus 1 //Отнимаемый бензин (при трате)
- #define max_stations 10 //Максимальное к-во заправок
- #define max_fuel 150
- #define mysql_host "localhost"
- #define mysql_db "samp"
- #define mysql_user "root"
- #define mysql_pass ""
- #define table "FuelStations"
- #define npub%0(%1) forward%0(%1); public%0(%1)
- enum Zapravki { ID, Float: posX, Float: posY, Float: posZ, Price, };
- new ZaprInfo[max_stations][Zapravki];
- new Benzin[MAX_VEHICLES],
- CheckBenzin[MAX_VEHICLES],
- l, a, d, b, _b, o,
- Text: ShowDatchik,
- CheckTimer, FuelTimer,
- CheckZapravka,
- bool: engine[MAX_VEHICLES],
- Text3D:textje,
- TOTAL_AZS,
- mysql_query[80], buf[512], cH;
- public OnFilterScriptInit()
- {
- print("Скрипт бензина от Wolf1227 загружен. Cheat-Master.RU");
- cH = mysql_connect(mysql_host, mysql_user, mysql_db, mysql_pass);
- switch(mysql_ping())
- {
- case 1: printf("< MySQL > Подключение к базе %s успешно выполнено", mysql_db);
- case -1: printf("< MySQL > Не удалось подключиться к базе %s", mysql_db);
- }
- mysql_debug(1);
- for(new i; i < MAX_VEHICLES; i++) Benzin[i] = 150, CheckBenzin[i] = 1;
- ShowDatchik = TextDrawCreate(26.966911, 323.527099, "F 0L");
- TextDrawLetterSize(ShowDatchik, 0.225999, 1.177000);
- TextDrawTextSize(ShowDatchik, 100.233413, 85.078506);
- TextDrawAlignment(ShowDatchik, 2);
- TextDrawColor(ShowDatchik, -5963521);
- TextDrawSetShadow(ShowDatchik, 0);
- TextDrawSetOutline(ShowDatchik, 1);
- TextDrawBackgroundColor(ShowDatchik, 51);
- TextDrawFont(ShowDatchik, 2);
- TextDrawSetProportional(ShowDatchik, 1);
- FuelTimer = SetTimer("Fuel", 60000, 1);
- SetTimer("Bugreport", 180000, 1);
- loadStations();
- return 1;
- }
- public OnFilterScriptExit()
- {
- TextDrawDestroy(ShowDatchik); print("Скрипт бензина от Wolf1227 выгружен. Cheat-Master.ru");
- KillTimer(FuelTimer);
- mysql_close(cH);
- Delete3DTextLabel(textje);
- return 1;
- }
- public OnVehicleDeath(vehicleid,killerid)
- {
- KillTimer(CheckTimer);
- engine[vehicleid] = false;
- }
- public OnVehicleSpawn(vehicleid)
- {
- Benzin[vehicleid] = max_fuel;
- CheckBenzin[vehicleid] = 1;
- engine[vehicleid] = false;
- }
- public OnPlayerExitVehicle(playerid, vehicleid)
- {
- TextDrawHideForPlayer(playerid, ShowDatchik);
- KillTimer(CheckTimer);
- }
- public OnPlayerStateChange(playerid, newstate, oldstate)
- {
- if(newstate == PLAYER_STATE_DRIVER)
- {
- new vehid = GetPlayerVehicleID(playerid);
- if(engine[vehid] == false)
- {
- if(IsABike(vehid) || IsAPlane(vehid) || IsABoat(vehid))
- SetVehicleParamsEx(vehid, true, false, false, false, false, false, false), engine[vehid] = true;
- else SendClientMessage(playerid, c_grad, "• Чтобы завести двигатель, нажмите \"2\".");
- }
- new ShowBenz[64];
- format(ShowBenz,64,"F %iL", Benzin[vehid]);
- TextDrawSetString(ShowDatchik,ShowBenz);
- TextDrawShowForPlayer(playerid,ShowDatchik);
- if(CheckBenzin[vehid] == 0)
- {
- SendClientMessage(playerid, c_main, "* В этой машине нету бензина");
- SetVehicleParamsEx(vehid, 0, l, a, d, b, _b, o);
- return true;
- }
- }
- if(newstate != PLAYER_STATE_DRIVER)
- {
- TextDrawHideForPlayer(playerid,ShowDatchik);
- KillTimer(CheckTimer);
- }
- return true;
- }
- npub RashodBenzina(playerid)
- {
- new vehid = GetPlayerVehicleID(playerid);
- if(Benzin[vehid] <= 0)
- {
- SendClientMessage(playerid, c_main, "* Бензин кончился, машина заглохла");
- SetVehicleParamsEx(vehid, 0, l, a, d, b, _b, o);
- CheckBenzin[vehid] = 0;
- KillTimer(CheckTimer);
- return true;
- }
- Benzin[vehid] -= Vminus;
- new ShowBenz[64];
- format(ShowBenz,64,"F %iL",Benzin[vehid]);
- TextDrawSetString(ShowDatchik,ShowBenz);
- return true;
- }
- npub ZapravkaBenzina(playerid)
- {
- new cID = GetPlayerVehicleID(playerid);
- if(Benzin[cID] == max_fuel)
- {
- new strng[64];
- KillTimer(CheckZapravka);
- if(engine[cID] == true) CheckTimer = SetTimer("RashodBenzina", TimeRashoda, 1);
- format(strng, 64, "* Общее к-во литров: %i L | Сумма: %i$", GetPVarInt(playerid, "Liters"), GetPVarInt(playerid, "MinusMoney"));
- SendClientMessage(playerid, c_main, strng);
- SendClientMessage(playerid, c_yell, "* Автомобиль полностью заправлен");
- TogglePlayerControllable(playerid,1);
- CheckBenzin[cID] = 1;
- SetPVarInt(playerid, "MinusMoney", 0), SetPVarInt(playerid, "Liters", 0), SetPVarInt(playerid, "PriceFuel", 0);
- return true;
- }
- Benzin[cID]++;
- SetPVarInt(playerid, "Liters", GetPVarInt(playerid, "Liters")+1);
- for(new s; s < TOTAL_AZS; s++)
- {
- GivePlayerMoney(playerid, -GetPVarInt(playerid, "PriceFuel"));
- SetPVarInt(playerid, "MinusMoney", GetPVarInt(playerid, "PriceFuel") * GetPVarInt(playerid, "Liters"));
- }
- new ShowBenz[64];
- format(ShowBenz,64,"F %iL",Benzin[cID]);
- TextDrawSetString(ShowDatchik,ShowBenz);
- return true;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- new params[128];
- sscanf(cmdtext, "s[30]s[128]", cmdtext, params);
- if(!strcmp(cmdtext, "/addazs", true))
- {
- if(sscanf(params, "d", params[0])) return SendClientMessage(playerid, c_grad, "Используйте: /addazs [цена за 1л бензина]");
- new Float:pos[3];
- GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
- 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]);
- mysql_function_query(cH, mysql_query, false, "", "");
- loadStations();
- return true;
- }
- if(!strcmp(cmdtext, "/fill", true))
- {
- if(GetPlayerState(playerid) != 2) return SendClientMessage(playerid, c_main, "* Данная команда доступна только водителям");
- if(IsABoat(GetPlayerVehicleID(playerid)) || IsAPlane(GetPlayerVehicleID(playerid)) || IsABike(GetPlayerVehicleID(playerid)) || GetVehicleModel(GetPlayerVehicleID(playerid)) == 462)
- return SendClientMessage(playerid, c_main, "* Это нельзя заправить");
- for(new s; s < TOTAL_AZS; s++)
- {
- if(IsPlayerInRangeOfPoint(playerid, 15.0, ZaprInfo[s][posX], ZaprInfo[s][posY], ZaprInfo[s][posZ]))
- {
- TogglePlayerControllable(playerid,0);
- KillTimer(CheckTimer);
- CheckZapravka = SetTimer("ZapravkaBenzina", 100, 1);
- SetPVarInt(playerid, "PriceFuel", ZaprInfo[s][Price]);
- return true;
- }
- }
- return SendClientMessage(playerid, c_main, "* Вы не на заправке");
- }
- return false;
- }
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- if(newkeys == KEY_SUBMISSION)
- {
- new vID = GetPlayerVehicleID(playerid);
- if(IsAPlane(vID) || IsABoat(vID) || IsABike(vID)) return 1;
- if(Benzin[vID] == 0) return SendClientMessage(playerid, c_main, "* В этом авто нет бензина");
- switch(engine[vID])
- {
- case false:
- {
- SetVehicleParamsEx(vID, true, l, a, d, b, _b, o);
- engine[vID] = true;
- CheckTimer = SetTimer("RashodBenzina", TimeRashoda, 1);
- }
- case true:
- {
- SetVehicleParamsEx(vID, false, l, a, d, b, _b, o);
- engine[vID] = false;
- KillTimer(CheckTimer);
- }
- }
- }
- return true;
- }
- IsABoat(carid)
- {
- new Boats[] = {472, 473, 493, 495, 484, 430, 454, 453, 452, 446};
- for(new i = 0; i < sizeof(Boats); i++) if(GetVehicleModel(carid) == Boats[i]) return 1;
- return 0;
- }
- IsAPlane(carid)
- {
- new AirVeh[] = {592, 577, 511, 512, 593, 520, 553, 476, 519, 460, 513, 548, 425, 417, 487, 488, 497, 563, 447, 469};
- for(new i = 0; i < sizeof(AirVeh); i++) if(GetVehicleModel(carid) == AirVeh[i]) return 1;
- return 0;
- }
- IsABike(carid)
- {
- if(GetVehicleModel(carid) == 509 || GetVehicleModel(carid) == 481 || GetVehicleModel(carid) == 510) return 1;
- return 0;
- }
- npub Fuel() { for(new car = 0; car != MAX_VEHICLES; car++) if(engine[car] == true) Benzin[car]--; }
- stock loadStations()
- {
- mysql_function_query(cH, "SELECT * FROM `"table"`", true, "OnLoadStationsCallback", "");
- return 1;
- }
- npub OnLoadStationsCallback()
- {
- new time = GetTickCount(), r, f, i;
- cache_get_data(r, f);
- for(i = 0; i < r; i++)
- {
- cache_get_field_content(i, "ID", buf), ZaprInfo[i][ID] = strval(buf);
- cache_get_field_content(i, "posX", buf), ZaprInfo[i][posX] = floatstr(buf);
- cache_get_field_content(i, "posY", buf), ZaprInfo[i][posY] = floatstr(buf);
- cache_get_field_content(i, "posZ", buf), ZaprInfo[i][posZ] = floatstr(buf);
- cache_get_field_content(i, "Price", buf), ZaprInfo[i][Price] = strval(buf);
- new text[100];
- format(text, 100, "{99CCCC}Цена за 1 литр бензина: {FFCC33}%i$", ZaprInfo[i][Price]);
- textje = Create3DTextLabel(text, 0xFFFFFFFF, ZaprInfo[i][posX], ZaprInfo[i][posY], ZaprInfo[i][posZ], 20.0, 0, 0);
- TOTAL_AZS++;
- }
- printf("* [ АЗС ] Было загружено %i АЗС за %i (ms)", TOTAL_AZS, GetTickCount() - time);
- return 1;
- }
- stock saveStations(idst)
- {
- if(idst == -1) for(idst = 0; idst < TOTAL_AZS; idst++) saveStations(idst);
- else
- {
- format(buf, sizeof(buf), "UPDATE `"table"` SET `posX` = '%f', `posY` = '%f', `posZ` = '%f', `Price` = '%d' WHERE `ID` = '%d'",
- ZaprInfo[idst][posX],
- ZaprInfo[idst][posY],
- ZaprInfo[idst][posZ],
- ZaprInfo[idst][Price],
- idst);
- mysql_function_query(cH, buf, false, "", "");
- }
- return 1;
- }
- public OnQueryError(errorid,error[],callback[],query[],connectionHandle) return printf("EID: %i | Error: %s | Query: %s", errorid, error, query);
- 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