29.06.2016, 14:45
Hey everyone. I am having this issue regarding to the speedometer's fuel thing. Basically, when I am in vehicle and turned the engine off, the fuel is still lowering and sometimes when I drive, the fuel textdraw does not update, it is like freezed. It updates only when I exit and enter the car again and then it shows it's real value, but then suddenly it goes back to 100. Can you help me please to fix it?
Here is some code:
OnGameModeInIt
+ I was using https://sampforum.blast.hk/showthread.php?tid=169284 to create a fuel system for a speedo.
Here is some code:
OnGameModeInIt
PHP код:
SetTimer("Speedometer", 100, true);
for(new i=0;i<MAX_VEHICLES;i++)
{
fuel[i] = 100;
}
SetTimer("timer_fuel_lower",20000,true);
PHP код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if (newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
{
new vid = GetPlayerVehicleID(playerid);
new string[125];format(string,sizeof string,"Fuel: ~y~%i~w~ L",fuel[vid]);
TextDrawSetString(td_fuel[playerid],string);
TextDrawShowForPlayer(playerid,Textdraw2[playerid]);
TextDrawShowForPlayer(playerid,Textdraw1[playerid]);
TextDrawShowForPlayer(playerid,speedbox[playerid]);
TextDrawShowForPlayer(playerid,HEALTH[playerid]);
TextDrawShowForPlayer(playerid,td_fuel[playerid]);
} else {
TextDrawHideForPlayer(playerid,td_fuel[playerid]);
TextDrawHideForPlayer(playerid,Textdraw2[playerid]);
TextDrawHideForPlayer(playerid,Textdraw1[playerid]);
TextDrawHideForPlayer(playerid,HEALTH[playerid]);
TextDrawHideForPlayer(playerid,speedbox[playerid]);
}
PHP код:
public timer_fuel_lower()
{
for(new i=0;i<MAX_PLAYERS;i++) {
new vid = GetPlayerVehicleID(i);
if (GetPlayerVehicleSeat(i) == 0) {
fuel[vid] = fuel[vid] -1;
if (fuel[vid]<1)
{
fuel[vid] = 0;
SetVehicleParamsEx(vid,0,0,0,0,1,1,0); //change this to watever you like
GameTextForPlayer(i,"~r~You are out of ~w~fuel~r~!",5000,4); //show text
}
}
new string[125];format(string,sizeof string,"Fuel: ~y~%i~w~ L",fuel[vid]);
TextDrawSetString(td_fuel[i],string);
}
return 1;
}