Help | Fuel System Bug
#1

I'm trying to make a simple fuel system to role play gamemode while doing it perfectly right it does wired stuff in-game to the fuel itself, here's what it does:
This is very wierd! I would give the full code so you can try please help me with it

Код:
//---- Fuel System ----//
new NoFuel[MAX_PLAYERS];
new Refueling[MAX_PLAYERS];
new Gas[MAX_VEHICLES];
new gGas[MAX_PLAYERS];
new Text:Textdraw40[MAX_PLAYERS];
new checkgastimer;
new stoppedvehtimer;
forward CheckGas();
forward Fillup();
forward StoppedVehicle();

#define GasMax 100
#define RunOutTime 40000
#define RefuelWait 5000
Under enum pInfo
Код:
pFuel,
Under OnPlayerConnect(playerid)
Код:
NoFuel[playerid] = 0;
gGas[playerid] = 1;
PlayerInfo[playerid][pFuel] = 0;
Under OnPlayerRegister(playerid, password[]) & OnPlayerSave(playerid)
Код:
format(var, 32, "Fuel=%d\n",PlayerInfo[playerid][pFuel]);fwrite(hFile, var);
Under OnPlayerLogin
Код:
if( strcmp( key , "Fuel" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pFuel] = strvalEx( val ); }
Texdraw Under OnPlayerConnect(playerid)
Код:
Textdraw40[playerid] = TextDrawCreate(498.000000, 140.000000, " "); // fuel
TextDrawBackgroundColor(Textdraw40[playerid], 255);
TextDrawFont(Textdraw40[playerid], 1);
TextDrawLetterSize(Textdraw40[playerid], 0.389999, 1.299999);
TextDrawColor(Textdraw40[playerid], 0xFFFFFFFF);
TextDrawSetOutline(Textdraw40[playerid], 1);
TextDrawSetProportional(Textdraw40[playerid], 1);
Under OnPlayerStateChange(playerid, newstate, oldstate)
Код:
if(newstate == PLAYER_STATE_DRIVER)
{
	TextDrawShowForPlayer(playerid, Textdraw40[playerid]);
}
Under OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
Код:
if(NoFuel[playerid] == 1)
{
	TogglePlayerControllable(playerid, 1);
	SafeRemovePlayerFromVehicle(playerid);
	NoFuel[playerid] = 0;
	return 1;
}
Under OtherTimer()
Код:
if(gGas[i] == 1)
{
	new vehicle = GetPlayerVehicleID(i);
	if(IsAPlane(vehicle) || IsABoat(vehicle) || IsABycicle(vehicle) || IsAHelicopter(vehicle))
	{
		format(string, sizeof(string), "~w~Fuel: ~g~~h~N/A");
	}
	else if(vehicle >= 1698)
	{
		format(string, sizeof(string), "~w~Fuel: ~p~Unknown");
	}
	else
	{
		if(Gas[vehicle] > 10)
		{
			format(string, sizeof(string), "~w~Fuel: ~g~~h~%d/~w~100%.",Gas[vehicle]);
		}
		else
		{
			format(string, sizeof(string), "~w~Fuel: ~r~~h~%d/~w~100%.",Gas[vehicle]);
		}
	}
	TextDrawSetString(Textdraw40[i], string);
}
Those Public's are exist along with fuel:
Код:
public CheckGas()
{
	for(new i=0;i<MAX_PLAYERS;i++)
	{
    	if(IsPlayerConnected(i))
       	{
       	    if(GetPlayerState(i) == PLAYER_STATE_DRIVER)
       	    {
	       		new vehicle = GetPlayerVehicleID(i);
	        	if(Gas[vehicle] >= 1)
		   		{
		   		    if(Gas[vehicle] <= 10)
				    {
			   			PlayerPlaySound(i, 1085, 0.0, 0.0, 0.0);
			   			if(gGas[i] == 0)
					   	{
			   				GameTextForPlayer(i,"~w~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~Fuel is low",5000,3);
						}
				    }
					if(IsAPlane(vehicle) || IsABycicle(vehicle) || IsABoat(vehicle) || engineOn[vehicle] == 0 || vehicle >= 1579 || IsAHelicopter(vehicle)) { Gas[vehicle]++; }
	              	Gas[vehicle]--;
		   		}
	   			else
	           	{
	              	NoFuel[i] = 1;
	              	TogglePlayerControllable(i, 0);
		        	GameTextForPlayer(i,"~w~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~No fuel in Vehicle",1500,3);
				}
			}
    	}
	}
	return 1;
}

public Fillup()
{
	for(new i=0; i<MAX_PLAYERS; i++)
   	{
	   	if(IsPlayerConnected(i))
	   	{
		    new VID;
		    new FillUp;
		    new string[128];
		    VID = GetPlayerVehicleID(i);
		    FillUp = GasMax - Gas[VID];
			if(Refueling[i] == 1)
		    {
		        if(IsACopsVehicle(VID) || IsAnAgentVehicle(VID) || IsAnAmbulance(VID) || IsAnFiretruck(VID))
		        {
		            Gas[VID] += FillUp;
		            FillUp = FillUp * BizzInfo[3][bEntranceCost];
		            format(string,sizeof(string),"* Vehicle filled up, for: $%d.",FillUp);
	    			SendClientMessage(i,COLOR_WHITE,string);
	    			GameTextForPlayer(i, "~w~Government has paid for a gas.", 5000, 1);
					BizzInfo[3][bTill] += FillUp;
					ExtortionBiz(3, FillUp);
					Refueling[i] = 0;
					SetVehicleParamsEx(VID,VEHICLE_PARAMS_ON,lights,alarm,doors,bonnet,boot,objective);
					TogglePlayerControllable(i, 1);
		        }
		        else
		        {
					if(GetPlayerMoney(i) >= FillUp+4)
					{
						Gas[VID] += FillUp;
						FillUp = FillUp * BizzInfo[3][bEntranceCost];
				    	format(string,sizeof(string),"* Vehicle filled up, for: $%d.",FillUp);
				    	SendClientMessage(i,COLOR_WHITE,string);
						AC_BS_GivePlayerMoney(i, - FillUp);
						BizzInfo[3][bTill] += FillUp;
						ExtortionBiz(3, FillUp);
						Refueling[i] = 0;
						SetVehicleParamsEx(VID,VEHICLE_PARAMS_ON,lights,alarm,doors,bonnet,boot,objective);
						TogglePlayerControllable(i, 1);
					}
			   		else
			   		{
			   	    	format(string,sizeof(string),"* Not enough Money to refill, it costs $%d to fill your Vehicle.",FillUp);
				    	SendClientMessage(i,COLOR_WHITE,string);
   		                SetVehicleParamsEx(VID,VEHICLE_PARAMS_ON,lights,alarm,doors,bonnet,boot,objective);
				    	TogglePlayerControllable(i, 1);
			   		}
				}
		 	}
		}
	}
	return 1;
}


public StoppedVehicle()
{
new Float:x,Float:y,Float:z;
new Float:distance,value;
//foreach(Player, i)
for(new i; i<MAX_PLAYERS; i++)
{
	if(IsPlayerConnected(i))
	{
		if(IsPlayerInAnyVehicle(i))
		{
			new VID;
			VID = GetPlayerVehicleID(i);
			GetPlayerPos(i, x, y, z);
			distance = floatsqroot(floatpower(floatabs(floatsub(x,SavePlayerPos[i][LastX])),2)+floatpower(floatabs(floatsub(y,SavePlayerPos[i][LastY])),2)+floatpower(floatabs(floatsub(z,SavePlayerPos[i][LastZ])),2));
			value = floatround(distance * 3600);
			if(UpdateSeconds > 1)
			{
				value = floatround(value / UpdateSeconds);
			}
			if(value == 0)
			{
				Gas[VID]++;
			}
			SavePlayerPos[i][LastX] = x;
			SavePlayerPos[i][LastY] = y;
			SavePlayerPos[i][LastZ] = z;
		}
	}
}
return 1;
}
There is a refuel command for player and for admin, the refuel goes through the public's, but the commands isn't the problem, the problem is that the updated Fuel: 100/100 goes crazy while invehicle and i can't figure why, can someone see it and guide me PLEASEE :]
Reply
#2

You can set a variable which when a vehicle spawns it will set the fuel to 100. Something like this:
pawn Код:
new Float: VehicleFuel[MAX_VEHICLES] = 100.0;
And under OnGameModeInit:
pawn Код:
for(new v = 0; v < MAX_VEHICLES; v++)
    {
        VehicleFuel[v] = 100.0;
    }
Just giving example.
Reply
#3

Quote:
Originally Posted by Necip
Посмотреть сообщение
You can set a variable which when a vehicle spawns it will set the fuel to 100. Something like this:
pawn Код:
new Float: VehicleFuel[MAX_VEHICLES] = 100.0;
And under OnGameModeInit:
pawn Код:
for(new v = 0; v < MAX_VEHICLES; v++)
    {
        VehicleFuel[v] = 100.0;
    }
Just giving example.
But its there already:
Код:
#define GasMax 100
And Under OnGameModeInit:
Код:
for(new c=0;c<MAX_VEHICLES;c++)
{
	Gas[c] = GasMax;
}
Isn't this is the same?^
Reply
#4

Do you have engine function? If yes, make it like it checks if the engine params are unset, set the fuel of that vehicle to 100.
Reply
#5

Quote:
Originally Posted by Necip
Посмотреть сообщение
Do you have engine function? If yes, make it like it checks if the engine params are unset, set the fuel of that vehicle to 100.
No I don't have...
Reply
#6

Only if unset.
Reply
#7

Quote:
Originally Posted by Necip
Посмотреть сообщение
Only if unset.
Please I don't understand .. can u just tell me what to do? cause I can't find how fixing this bug (
Reply
#8

I am on my phone. PM me and I will tell you how to do it as soon as I get on my PC.
Reply
#9

Well I tried what you told me on PM and it didn't work so well =\

PLEASE ANYONE... I dont understand why the Fuel Goes from 100 to bilions after i did this:
Under OnGameModeInit
Код:
	for(new v=0;v<MAX_VEHICLES;v++)
	{
		Gas[v] = GasMax;
	}
Код:
#define GasMax 100
Reply
#10

hmmm im having same problem, been stumped for days now
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)