Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //********************* [ Credits ] ******************************************//
- /*
- Car Fuel Script by Cameltoe
- Version 1.3
- I do not demand to keep the credits but it is appreciated.
- */
- //******************** [ Includes ] ******************************************//
- #include <a_samp>
- #include <zcmd>
- //******************** [ Forwards ] ******************************************//
- forward FuelDown(playerid);
- //******************** [ Defines ] ******************************************//
- // Vehicles
- #undef MAX_VEHICLES
- #define MAX_VEHICLES 2000
- // Fuel
- #define REFUEL_COST 2500
- #define MAX_FUEL 100
- #define FUEL_DECREASE 1
- // Colors
- #define COLOR_RED 0xFF000000
- #define COLOR_YELLOW 0xFFFF0000
- #define COLOR_BLUE 0x0000FF00
- #define COLOR_GREEN 0x00FF0000
- #define COLOR_WHITE 0xFFFFFFFF
- //******************** [ Enums ] *********************************************//
- enum Car
- {
- Float:Fuel,
- }
- //******************** [ Symbols ] *******************************************//
- new Carinfo[MAX_VEHICLES][Car];
- new Text:FuelText[MAX_PLAYERS];
- new FuelTimer[MAX_PLAYERS];
- //******************** [ Callbakcs ] *****************************************//
- public OnFilterScriptInit()
- {
- printf("_____________________________________");
- printf("| |");
- printf("| Fuel FS v1.1 |");
- printf("| By |");
- printf("| Cameltoe |");
- printf("|___________________________________|");
- for(new vehicleid; vehicleid < MAX_VEHICLES; vehicleid++)
- {
- Carinfo[vehicleid][Fuel] = MAX_FUEL;
- }
- return 1;
- }
- /*main()
- {
- printf("_____________________________________");
- printf("| |");
- printf("| Fuel FS v1.1 |");
- printf("| By |");
- printf("| Cameltoe |");
- printf("|___________________________________|");
- for(new vehicleid; vehicleid < MAX_VEHICLES; vehicleid++)
- {
- Carinfo[vehicleid][Fuel] = MAX_FUEL;
- }
- return 1;
- }*/
- public OnPlayerConnect(playerid)
- {
- FuelText[playerid] = TextDrawCreate(450.0, 405.0," ");
- TextDrawHideForPlayer(playerid,FuelText[playerid]);
- TextDrawAlignment(FuelText[playerid],0);
- TextDrawSetProportional(FuelText[playerid],1);
- TextDrawSetShadow(FuelText[playerid], 1);
- TextDrawSetOutline(FuelText[playerid], 2);
- TextDrawLetterSize(FuelText[playerid],0.60,2.0);
- TextDrawFont(FuelText[playerid], 3);
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- TextDrawDestroy(FuelText[playerid]);
- return 1;
- }
- public OnPlayerStateChange(playerid,newstate,oldstate)
- {
- new string[128];
- if(newstate == PLAYER_STATE_DRIVER)
- {
- if(floatround(Carinfo[GetPlayerVehicleID(playerid)][Fuel]) <= 0)
- {
- format(string,sizeof(string),"~g~ Fuel: ~w~ 0");
- SendClientMessage(playerid, COLOR_WHITE, "This vehicle has ran out of fuel");
- KillTimer(FuelTimer[playerid]);
- ToggleVehicleEngine(GetPlayerVehicleID(playerid), true);
- TextDrawSetString(FuelText[playerid], string);
- }
- else
- {
- FuelTimer[playerid] = SetTimerEx("FuelDown", 10000, true, "i", playerid); // Fueldown timer
- TextDrawShowForPlayer(playerid, FuelText[playerid]);
- }
- }
- else
- {
- TextDrawHideForPlayer(playerid,FuelText[playerid]);
- TextDrawSetString(FuelText[playerid], " ");
- }
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- return 0;
- }
- //******************** [ Functions ] ********************************************//
- public FuelDown(playerid)
- {
- new string[128];
- new vehicleid = GetPlayerVehicleID(playerid);
- if(IsPlayerInAnyVehicle(playerid))
- {
- if(floatround(Carinfo[vehicleid][Fuel]) <= 0 || Carinfo[vehicleid][Fuel] - GetPlayerSpeed(playerid) * FUEL_DECREASE / 100 < 0)
- {
- format(string,sizeof(string),"~g~ Fuel: ~w~ 0");
- SendClientMessage(playerid, COLOR_RED, "This vehicle has ran out of fuel");
- KillTimer(FuelTimer[playerid]);
- ToggleVehicleEngine(vehicleid, false);
- TextDrawSetString(FuelText[playerid], string);
- }
- else
- {
- Carinfo[vehicleid][Fuel] = Carinfo[vehicleid][Fuel] - GetPlayerSpeed(playerid) * FUEL_DECREASE / 100;
- format(string,sizeof(string),"~g~ Fuel: ~w~ %d", floatround(Carinfo[vehicleid][Fuel]));
- TextDrawSetString(FuelText[playerid], string);
- }
- }
- else
- {
- format(string,sizeof(string),"~g~ Fuel: ~w~ ");
- KillTimer(FuelTimer[playerid]);
- }
- }
- //******************** [ Stocks ] ********************************************//
- stock ToggleVehicleEngine(vehicleid, bool: Mode)
- {
- new engine,lights,alarm,doors,bonnet,boot,objective;
- GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
- if(Mode == false) SetVehicleParamsEx(vehicleid, VEHICLE_PARAMS_OFF, lights, alarm, doors, bonnet, boot, objective);
- else SetVehicleParamsEx(vehicleid, VEHICLE_PARAMS_ON, lights, alarm, doors, bonnet, boot, objective);
- }
- stock GetPlayerSpeed(playerid)
- {
- new Float:ST[4];
- if(IsPlayerInAnyVehicle(playerid)) GetVehicleVelocity(GetPlayerVehicleID(playerid),ST[0],ST[1],ST[2]); else GetPlayerVelocity(playerid,ST[0],ST[1],ST[2]);
- ST[3] = floatsqroot(floatpower(floatabs(ST[0]), 2.0) + floatpower(floatabs(ST[1]), 2.0) + floatpower(floatabs(ST[2]), 2.0)) * 180;
- return floatround(ST[3]);
- }
- //******************** [ Commands ] ******************************************//
- command(car, playerid, params[])
- {
- new Float:Pos[4]; GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]); GetPlayerFacingAngle(playerid, Pos[3]);
- new vehicleid = CreateVehicle(411, Pos[0], Pos[1], Pos[2], Pos[3], 0, 0, 60*10000);
- PutPlayerInVehicle(playerid, vehicleid, 0);
- return 1;
- }
- command(money, playerid, params[])
- {
- GivePlayerMoney(playerid, 500);
- return 1;
- }
- command(refuel, playerid, params[])
- {
- if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_YELLOW, "You to be inside an vehicle to refuel it.");
- if(GetPlayerMoney(playerid) < REFUEL_COST) return SendClientMessage(playerid, COLOR_YELLOW, "You do not have enough money to refuel your vehicle.");
- Carinfo[GetPlayerVehicleID(playerid)][Fuel] = MAX_FUEL;
- KillTimer(FuelTimer[playerid]);
- ToggleVehicleEngine(GetPlayerVehicleID(playerid), true);
- FuelTimer[playerid] = SetTimerEx("FuelDown", 10000, true, "i", playerid); // Fueldown timer
- GivePlayerMoney(playerid, -REFUEL_COST);
- SendClientMessage(playerid, COLOR_YELLOW, "You refueled your vehicle.");
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement