23.02.2014, 01:07
Mine Was Based Off That One And It Keep Staying At petrol 100 then it would go To 96 then back to 100 and double the textdraw try my fix just change the offset of the textdraw to suit your needs
PHP код:
forward FuelConsumption();
forward RefillFuel(playerid);
new RefillingFuel[MAX_PLAYERS];
new Text:FuelTxt[MAX_PLAYERS];
new Fuel[MAX_VEHICLES];
new FuelRefillTimer;
new FuelTimer;
main()
{
for(new i=0;i<MAX_PLAYERS;i++)
{
//--[Fuel]
FuelTxt[i] = TextDrawCreate(430,420,"Fuel:%i%");
TextDrawBackgroundColor(FuelTxt[i],0x00000033);
TextDrawFont(FuelTxt[i],3);
TextDrawLetterSize(FuelTxt[i],0.399999,1.700000);
TextDrawColor(FuelTxt[i],0xFFFFFFFF);
TextDrawSetShadow(FuelTxt[i],3);
}
}
public FuelConsumption()
{
for(new i=0;i<MAX_PLAYERS;i++)
{
new vehicleid = GetPlayerVehicleID(i);
new engine,lights,alarm,doors,bonnet,boot,objective;
GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
if(GetPlayerVehicleSeat(i) == 0)
{
Fuel[vehicleid]--;
if(Fuel[vehicleid]<= 0)
{
Fuel[vehicleid] = 0;
SetVehicleParamsEx(vehicleid,0,lights,alarm,doors,bonnet,boot,objective);
VehicleInfo[vehicleid][Engine] = 0;
GameTextForPlayer(i,"~w~You Are Out Of ~r~Fuel~w~!",5000,4);
}
}
new string[125];
format(string,sizeof string,"Fuel:%i%",Fuel[vehicleid]);
TextDrawSetString(FuelTxt[i],string);
}
return 1;
}
public RefillFuel(playerid)
{
new vehicleid = GetPlayerVehicleID(playerid);
if(IsPlayerConnected(playerid))
{
if(RefillingFuel[playerid] == 1)
{
if(Fuel[vehicleid] < 100)
{
Fuel[vehicleid] = 100;
RefillingFuel[playerid] = 0;
KillTimer(FuelRefillTimer);
TogglePlayerControllable(playerid, 0);
}
}
new string[128];
format(string,sizeof string,"Fuel:%i%",Fuel[vehicleid]);
TextDrawSetString(FuelTxt[playerid],string);
KillTimer(FuelRefillTimer);
TogglePlayerControllable(playerid, 1);
SendClientMessage(playerid,-1,COLOR_YELLOW"<<Vehicle Info>>"COLOR_WHITE" To Turn On Ignition Press Key ~k~~TOGGLE_SUBMISSIONS~ ");
GameTextForPlayer(playerid,"~w~You Can Now Turn On Ignition ~n~ To Turn On Ignition Press Key ~k~~TOGGLE_SUBMISSIONS~!",3000,4);
}
return 1;
}
public OnGameModeInit()
{
for(new i=0;i<MAX_VEHICLES;i++)
{
Fuel[i] = 100;
}
return 1;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
new vehicleid = GetPlayerVehicleID(playerid);
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
if(PRESSED(KEY_SUBMISSION))
{
new engine,lights,alarm,doors,bonnet,boot,objective;
GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
if(VehicleInfo[vehicleid][Engine] != 1)
{
if(Fuel[vehicleid] > 0)
{
SetVehicleParamsEx(vehicleid,1,lights,alarm,doors,bonnet,boot,objective);
VehicleInfo[vehicleid][Engine] = 1;
GameTextForPlayer(playerid,"~w~Ignition: ~g~On", 200,3);
SendClientMessage(playerid,-1,COLOR_YELLOW"<<Vehicle Info>>"COLOR_WHITE" Ignition State:"COLOR_GREEN" On");
SendClientMessage(playerid,-1,COLOR_YELLOW"<<Vehicle Info>>"COLOR_WHITE" To Turn Off Ignition Press Key ~k~~TOGGLE_SUBMISSIONS~ ");
SendClientMessage(playerid,-1,COLOR_YELLOW"<<Vehicle Info>>"COLOR_WHITE" To Turn On/Off Lights Press Key ~k~~PED_FIREWEAPON~ ");
FuelTimer = SetTimer("FuelConsumption",20000,true);
}
if(Fuel[vehicleid]<= 0)
{
SetVehicleParamsEx(vehicleid,0,lights,alarm,doors,bonnet,boot,objective);
VehicleInfo[vehicleid][Engine] = 0;
GameTextForPlayer(playerid,"~w~You Are Out Of ~r~Fuel!", 200,3);
SendClientMessage(playerid,-1,COLOR_YELLOW"<<Vehicle Info>>"COLOR_WHITE" Fuel:"COLOR_RED" Empty");
KillTimer(FuelTimer);
}
}
}
}
return 1;
}