Jump to content
  • 0

Porblema citire/scriere km


MAXYMUSS

Question

Problema intalnita (descriere):Km se salveaza in mysql , ii citeste , dar cand dau restart la server ia km de la 0 ( chiar daca sunt salvati de exemplu 2-3km tot incepe de la 0)

Ar  trebuie sa fac ceva de citire a km din baza de date ? daca da cum ? ..  Multumesc !
Ero(area / rile) / warning-(ul / urile): -
Liniile de cod / sursa / script-ul(obligatoriu):

public CheckGas()
{
	for(new i=1; i<= MAX_VEHICLES; i++)
	{
		if(i != INVALID_VEHICLE_ID)
		{
			GetVehicleParamsEx(i,engine,lights,alarm,doors,bonnet,boot,objective);
			if(engine == VEHICLE_PARAMS_ON && alarmon == 0)
			{
			    if(IsAPlane(i) == 0 && IsABoat(i) == 0 && IsABmx(i) == 0 && Gas > 0  && i != 307 && i != 308 && i != 171 &&i != 172 && i != 173 && i != 174 && i != 161 && i != 162 && i != 163)
				{
					Gas--;
					foreach(Player, o)
					{
					  new Float:Viteza = GetVehicleSpeed_P(o);
					  if(Viteza > 5 && GetPlayerState(o) == PLAYER_STATE_DRIVER && GetPlayerVehicleID(o) == i)
					  {
					    CarData[i-PreVehicle][cKM]++;
				        new query[MAX_STRING];
				        format(query, sizeof(query), "UPDATE cars SET KM='%d' WHERE id=%d", CarData[i-PreVehicle][cKM], i-PreVehicle);
				        mysql_query(query);
					  }
					}
				}
			}
		}
	}

Imagini / Video (optional): -
Ati incercat sa rezolvati singur?: -

Edited by MAXYMUSS
Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 0

Pai km astia definestei ca un float. Si acolo la update adaugi:

new query[MAX_STRING];
format(query, sizeof(query), "UPDATE `cars` SET `KM`='%0.2f' WHERE `id`='%d'", CarData[i-PreVehicle][cKM], i-PreVehicle);
mysql_query(query);

Mergi la

new CarData

si acolo deasuprea la enum adaugi inloc de cKM

Float:cKM

Peste tot unde setezi ca variabila asta sa fie 0 inloc de 0 pui 0.0 exemplu:

CarData[i-PreVehicle][cKM] = 0.0; // deoarece e float

Mergi la :

sscanf(Query, "p<|>e<iiffffffffiis[64]s[64]iiiiis[255]iiiiiiiiiiiiiii>",CarData[idx]);

si inlocuieste "i" cu "f" .

 

La textdraw inloc de "%d" inlocuieste cu "%.2f".

La functia CheckGas inlocuieste:

CarData[i-PreVehicle][cKM]++;

cu:

CarData[i-PreVehicle][cKM] += (Carspeed(i)*0.27)/700;

si functia pentru Carspeed:

stock Carspeed(playerid,mode = 1)
{
    new Float:Velocity [3];
    GetVehicleVelocity ( GetPlayerVehicleID ( playerid ) , Velocity [ 0 ] , Velocity [ 1 ] , Velocity [ 2 ] ) ;
    return IsPlayerInAnyVehicle ( playerid ) ? floatround ( ( ( floatsqroot ( ( ( Velocity [ 0 ] * Velocity [ 0 ] ) + ( Velocity [ 1 ] * Velocity [ 1 ] ) + ( Velocity [ 2 ] * Velocity [ 2 ] ) ) ) * ( !mode ? 105.0 : 170.0 ) ) ) * 1 ) : 0;
}
Edited by andy47
  • Upvote 1
Link to comment
Share on other sites

  • 0
public LoadCar()
{
    new Query[255];
    mysql_query("SELECT * FROM cars"); // Querys the "Query" Variable.
    mysql_store_result(); // Stores the result from Query
    personalcars = mysql_num_rows();
    new masini=0;
    for(new idx = 1; idx <= personalcars; idx++)
    {
        format(Query, sizeof(Query), "SELECT * FROM cars WHERE id = '%d'", idx);
        mysql_query(Query); // Querys the "Query" Variable.
        mysql_store_result(); // Stores the result from Query
        if(mysql_num_rows()) // Checks if theres anyrow.
        if(mysql_fetch_row_format(Query,"|")) // Splits the row
        {
            sscanf(Query, "p<|>e<iiffffffffis[182]s[182]iiiiis[255]iiiiiiiiiiiiiiiiiiiiii>",CarData[idx]);
            masini++;
        }

        //printf("id %d car model %d, cLocationx %f, cNum %s, cSaAngle %f, cComponent13 %d",idx, CarData[idx][cModel],CarData[idx][cLocationx],CarData[idx][cNum],CarData[idx][cSaAngle], CarData[idx][cComponent01]);
    }
    printf("* Masini personale citite: %d", masini);
    return 1;
}

acesta este loadcar

si de aici ia datele :

	for(new i = 1; i<=personalcars+PreVehicle; i++)
	{
	    if(CarData[cModel] >= 400 && CarData[cModel] <= 611)
	    {
	        new model = CarData[cModel];
	        new Float:xx1 = CarData[cLocationx];
	        new Float:yy1 = CarData[cLocationy];
	        new Float:zz1 = CarData[cLocationz];
	        new Float:aa1 = CarData[cAngle];
	        new color1 = CarData[cColorOne];
	        new color2 = CarData[cColorTwo];
	        //new color3 = CarData[cPaintjob];
	        new carid = AddStaticVehicleEx(model,xx1,yy1,zz1,aa1,color1,color2,60000);
	        if(CarData[cComponent00] != 0)
	        {
	            AddVehicleComponent(carid,CarData[cComponent00]);
	        }
	        if(CarData[cComponent01] != 0)
	        {
	            AddVehicleComponent(carid,CarData[cComponent01]);
	        }
	        if(CarData[cComponent02] != 0)
	        {
	            AddVehicleComponent(carid,CarData[cComponent02]);
	        }
	        if(CarData[cComponent03] != 0)
	        {
	            AddVehicleComponent(carid,CarData[cComponent03]);
	        }
	        if(CarData[cComponent04] != 0)
	        {
	            AddVehicleComponent(carid,CarData[cComponent04]);
	        }
	        if(CarData[cComponent05] != 0)
	        {
	            AddVehicleComponent(carid,CarData[cComponent05]);
	        }
	        if(CarData[cComponent06] != 0)
	        {
	            AddVehicleComponent(carid,CarData[cComponent06]);
	        }
	        if(CarData[cComponent07] != 0)
	        {
	            AddVehicleComponent(carid,CarData[cComponent07]);
	        }
	        if(CarData[cComponent08] != 0)
	        {
	            AddVehicleComponent(carid,CarData[cComponent08]);
	        }
	        if(CarData[cComponent09] != 0)
	        {
	            AddVehicleComponent(carid,CarData[cComponent09]);
	        }
	        if(CarData[cComponent10] != 0)
	        {
	            AddVehicleComponent(carid,CarData[cComponent10]);
	        }
            if(CarData[cComponent11] != 0)
	        {
	            AddVehicleComponent(carid,CarData[cComponent11]);
	        }
	        if(CarData[cComponent12] != 0)
	        {
	            AddVehicleComponent(carid,CarData[cComponent12]);
	        }
	        if(CarData[cComponent13] != 0)
	        {
	            AddVehicleComponent(carid,CarData[cComponent13]);
	        }
	        if(CarData[cPaintjob] != 4)
		    {
		    	ChangeVehiclePaintjob(carid, CarData[cPaintjob]);
	    	}
	    }
	}
	for(new i = 1; i<999;i++)
	{
	    if(CarData[cModel] >= 400 && CarData[cModel] <= 611)
	    {
	        format(string, sizeof(string), "%s",CarData[cNum]);
	        SetVehicleNumberPlate(i+PreVehicle, string);
	        if(CarData[cLockk] == 1)
	        {
	        	VehLocked[i+PreVehicle] = 1;
			}
			alarmon = 0;
	    }
	}
Edited by MAXYMUSS
Link to comment
Share on other sites

  • 0

nu,la fel face , incepe iar km de la 0 (un id la ultimele i zici ? sau unde ? )

 

nu ar trebui sa pun si aici ceva legat de km ? ( nu stiu ce )

for(new i = 1; i<=personalcars+PreVehicle; i++)
	{
	    if(CarData[cModel] >= 400 && CarData[cModel] <= 611)
	    {
	        new model = CarData[cModel];
	        new Float:xx1 = CarData[cLocationx];
	        new Float:yy1 = CarData[cLocationy];
	        new Float:zz1 = CarData[cLocationz];
	        new Float:aa1 = CarData[cAngle];
	        new color1 = CarData[cColorOne];
	        new color2 = CarData[cColorTwo];
	        //new color3 = CarData[cPaintjob];
	        new carid = AddStaticVehicleEx(model,xx1,yy1,zz1,aa1,color1,color2,60000);
	        if(CarData[cComponent00] != 0)
	        {
	            AddVehicleComponent(carid,CarData[cComponent00]);
	        }
	        if(CarData[cComponent01] != 0)
	        {
	            AddVehicleComponent(carid,CarData[cComponent01]);
	        }
	        if(CarData[cComponent02] != 0)
	        {
	            AddVehicleComponent(carid,CarData[cComponent02]);
	        }
	        if(CarData[cComponent03] != 0)
	        {
	            AddVehicleComponent(carid,CarData[cComponent03]);
	        }
	        if(CarData[cComponent04] != 0)
	        {
	            AddVehicleComponent(carid,CarData[cComponent04]);
	        }
	        if(CarData[cComponent05] != 0)
	        {
	            AddVehicleComponent(carid,CarData[cComponent05]);
	        }
	        if(CarData[cComponent06] != 0)
	        {
	            AddVehicleComponent(carid,CarData[cComponent06]);
	        }
	        if(CarData[cComponent07] != 0)
	        {
	            AddVehicleComponent(carid,CarData[cComponent07]);
	        }
	        if(CarData[cComponent08] != 0)
	        {
	            AddVehicleComponent(carid,CarData[cComponent08]);
	        }
	        if(CarData[cComponent09] != 0)
	        {
	            AddVehicleComponent(carid,CarData[cComponent09]);
	        }
	        if(CarData[cComponent10] != 0)
	        {
	            AddVehicleComponent(carid,CarData[cComponent10]);
	        }
            if(CarData[cComponent11] != 0)
	        {
	            AddVehicleComponent(carid,CarData[cComponent11]);
	        }
	        if(CarData[cComponent12] != 0)
	        {
	            AddVehicleComponent(carid,CarData[cComponent12]);
	        }
	        if(CarData[cComponent13] != 0)
	        {
	            AddVehicleComponent(carid,CarData[cComponent13]);
	        }
	        if(CarData[cPaintjob] != 4)
		    {
		    	ChangeVehiclePaintjob(carid, CarData[cPaintjob]);
	    	}
	    }
	}
	for(new i = 1; i<999;i++)
	{
	    if(CarData[cModel] >= 400 && CarData[cModel] <= 611)
	    {
	        format(string, sizeof(string), "%s",CarData[cNum]);
	        SetVehicleNumberPlate(i+PreVehicle, string);
	        if(CarData[cLockk] == 1)
	        {
	        	VehLocked[i+PreVehicle] = 1;
			}
			alarmon = 0;
	    }
	}
Edited by MAXYMUSS
Link to comment
Share on other sites

  • 0
sscanf(Query, "p<|>e<iiffffffffiis[64]s[64]iiiiis[255]iiiiiiiiiiiiiii>",CarData[idx]);

tot la fel face, ultimul i in f , la acela te referi nu ? ala ar veni sa fi ckm in cardata, multumesc de ajutor !

Edited by MAXYMUSS
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more details you can also review our Terms of Use and Privacy Policy.