Fuel bug.
#1

When I enter a car and start to drive, my fuel will bug to 123781947192 instead of a normal amount between 0 and 100. What's wrong in the code?

Код:
public Fillup()
{
	//foreach(Player, i)
    for(new i; i<MAX_PLAYERS; i++)
   	{
	   	if(IsPlayerConnected(i))
	   	{
		    new VID;
		    new FillUp;
		    new string[128];
		    VID = GetPlayerVehicleID(i);
		    FillUp = 100 - Gas[VID];
			if(Refueling[i] == 1)
		    {
				if(PlayerInfo[i][pCash] >= FillUp+4)
				{
					Gas[VID] += FillUp;
					FillUp = 50;
				    format(string,sizeof(string),"* You filled your Vehicle up for: $%d.",FillUp);
				    SendClientMessage(i,COLOR_LIGHTBLUE,string);
				    PlayerInfo[i][pCash] = PlayerInfo[i][pCash]-FillUp;
					GivePlayerMoney(i, - FillUp);
					Refueling[i] = 0;
				}
			   	else
			   	{
			   	    SendClientMessage(i,COLOR_GREY,"   You can't afford that !");
			   	}
		 	}
		}
	}
	return 1;
}
Reply
#2

Samp only supports 10 digit long numbers, if exceeded u will get that number u get.

9999999999 = the max

Chech your script for numbers larger then 10 digits and lowe or remove them
Reply
#3

Nothing is above that. Highest nuber was 100, I changed that to 99, but it still didn't work..
Reply
#4

I found out what makes it bug, but I don't know how to solve it.

Код:
Fuel[carid] -= 0.07;
When there is a value above 1.0 it works fine, but the fueltank is empty in like 30seconds, when I put in a value like 0.***, no matter how much numbers behind the 0. , it just bugs to a random number.. How can I fix that?
Reply
#5

Quote:
Originally Posted by whando
Посмотреть сообщение
I found out what makes it bug, but I don't know how to solve it.

Код:
Fuel[carid] -= 0.07;
When there is a value above 1.0 it works fine, but the fueltank is empty in like 30seconds, when I put in a value like 0.***, no matter how much numbers behind the 0. , it just bugs to a random number.. How can I fix that?
Are you showing us all the code? isnt there a stock you are using or something?
Reply
#6

Well I got this. Nothing else

Код:
public Speedometer()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
	{
	    new State = GetPlayerState(i);
		if(State == PLAYER_STATE_DRIVER && ShowSpeed[i] == 1 && IsPlayerInAnyVehicle(i))
	    {
     		#define MULTIPLY_SPEED  3
     		new carid = GetPlayerVehicleID(i);
			new VehicleModel = GetVehicleModel(GetPlayerVehicleID(i));
			new playerid;

			new Float:x, Float:y, Float:z, Float:health, string[256]; TextDrawDestroy(black); TextDrawDestroy(Speedom[i]);
			GetPlayerPos(i, x, y, z); GetVehicleHealth(GetPlayerVehicleID(i), health);
			new Float:Dis = floatsqroot(floatpower(floatabs(floatsub(OldCoordsX[i],x)),2) + floatpower(floatabs(floatsub(OldCoordsY[i],y)),2));
            if(Fuel[carid] <= 0){ RemovePlayerFromVehicle(i); SendClientMessage(i, COLOR_LIGHTRED, "The gas tank is empty in this vehicle !"); }
			if(VehicleModel==509||VehicleModel==481||VehicleModel==510) { SetVehicleHealth(GetPlayerVehicleID(i), 1000); Fuel[carid] = 100; }
			if(VehicleModel==520||VehicleModel==476||VehicleModel==593||VehicleModel==553||VehicleModel==513||VehicleModel==512||VehicleModel==577||VehicleModel==592||VehicleModel==511||VehicleModel==539||VehicleModel==464||VehicleModel==519) { Fuel[carid] = 100; }
			new speed = (floatround(Dis)*MULTIPLY_SPEED);
			new vid = GetPlayerVehicleID(playerid);

            new Sspeed[15];


	     	if( speed == 0) {
 	 			format(Sspeed,sizeof(Sspeed),"~w~%dKM/H",(floatround(Dis)*MULTIPLY_SPEED));
		    } else if( speed >= 1 && speed <= 60 ){
      			format(Sspeed,sizeof(Sspeed),"~w~%dKM/H",(floatround(Dis)*MULTIPLY_SPEED));
	        	Fuel[carid] -= 0.01;
		    } else if( speed >= 61 && speed <= 120 ){
	    		format(Sspeed,sizeof(Sspeed),"~w~%dKM/H",(floatround(Dis)*MULTIPLY_SPEED));
	    		Fuel[carid] -= 0.02;
		    } else if( speed >= 120 && speed <= 500 ){
  				format(Sspeed,sizeof(Sspeed),"~w~%dKM/H",(floatround(Dis)*MULTIPLY_SPEED));
      			Fuel[carid] -= 0.05;
		    }




			format(string,sizeof(string),"~n~~Y~Speed:~w~%s~n~~Y~Fuel:~w~%d~n~" ,Sspeed,Fuel[vid]);

			black = TextDrawCreate(494.000000,379.000000,"_");
			TextDrawTextSize(black,600.000000,0.000000);
			TextDrawAlignment(black,0);
			TextDrawFont(black,2);
			TextDrawLetterSize(black,1.700000,6.250000);
			TextDrawSetOutline(black,1);
			TextDrawSetProportional(black,1);
			TextDrawSetShadow(black,1);

			Speedom[i] = TextDrawCreate(495.000000,380.000000,string);
        	TextDrawTextSize(Speedom[i],600.000000,0.000000);
			TextDrawAlignment(Speedom[i],0);
			TextDrawFont(Speedom[i],2);
			TextDrawLetterSize(Speedom[i],0.299999,1.000000);
			TextDrawSetOutline(Speedom[i],1);
			TextDrawSetProportional(Speedom[i],1);
			TextDrawSetShadow(Speedom[i],1);

			TextDrawShowForPlayer(i, black);
			TextDrawShowForPlayer(i, Speedom[i]);
			OldCoordsX[i] = x; OldCoordsY[i] = y;
		} else { TextDrawHideForPlayer(i, black); TextDrawHideForPlayer(i, Speedom[i]); }
	}
	return true;
}
Reply
#7

Anyone?
Reply
#8

I'm sorry I cant find anything wrong with your code... perhaps someone else can help you out! good luck
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)