Loading personal cars
#1

Код:
public LoadPersonalVehicles()
{
    new arrCoords[41][64],sql[512],row[512];
	format(sql, sizeof(sql), "SELECT COUNT(id) FROM cars");
	mysql_query(sql);
	SQLLog(sql);
	mysql_store_result();
	mysql_fetch_row(row);
	new asd = AddStaticVehicleEx(411, 0, 0, 0, 0, 0, 0, -1); //For the next idID
	DestroyVehicle(asd);
	new masinipers = AmountOfVehicles()+2;
	if(masinipers>0)
	{
		for (new idx=1; idx<=masinipers; idx++)
		{
		    format(sql, sizeof(sql), "SELECT * FROM cars WHERE id=%d", idx);
		    mysql_query(sql);
			SQLLog(sql);
		    mysql_store_result();
		    if (mysql_num_rows() > 0)
			{
		        mysql_fetch_row(row);
				split(row, arrCoords, '|');
				CarData[asd][cId] = strval(arrCoords[0]);
				CarData[asd][cModel] = strval(arrCoords[1]);
				CarData[asd][cLocationx] = floatstr(arrCoords[2]);
				CarData[asd][cLocationy] = floatstr(arrCoords[3]);
				CarData[asd][cLocationz] = floatstr(arrCoords[4]);
				CarData[asd][cAngle]     = floatstr(arrCoords[5]);
				CarData[asd][cSaLocationx] = strval(arrCoords[6]);
				CarData[asd][cSaLocationy] = strval(arrCoords[7]);
				CarData[asd][cSaLocationz] = strval(arrCoords[8]);
				CarData[asd][cSaAngle] = strval(arrCoords[9]);
				CarData[asd][cColorOne] = strval(arrCoords[10]);
				CarData[asd][cColorTwo] = strval(arrCoords[11]);
				CarData[asd][cOwner] = strval(arrCoords[12]);
				CarData[asd][cDescription] = strval(arrCoords[13]);
				CarData[asd][cValue] = strval(arrCoords[14]);
				CarData[asd][cLicense] = strval(arrCoords[15]);
				CarData[asd][cOwned] = strval(arrCoords[16]);
				CarData[asd][cLockk] = strval(arrCoords[17]);
				CarData[asd][cNum] = strval(arrCoords[18]);
				CarData[asd][cComponent00] = strval(arrCoords[19]);
				CarData[asd][cComponent01] = strval(arrCoords[20]);
				CarData[asd][cComponent02] = strval(arrCoords[21]);
				CarData[asd][cComponent03] = strval(arrCoords[22]);
				CarData[asd][cComponent04] = strval(arrCoords[23]);
				CarData[asd][cComponent05] = strval(arrCoords[24]);
				CarData[asd][cComponent06] = strval(arrCoords[25]);
				CarData[asd][cComponent07] = strval(arrCoords[26]);
				CarData[asd][cComponent08] = strval(arrCoords[27]);
				CarData[asd][cComponent09] = strval(arrCoords[28]);
				CarData[asd][cComponent10] = strval(arrCoords[29]);
				CarData[asd][cComponent11] = strval(arrCoords[30]);
				CarData[asd][cComponent12] = strval(arrCoords[31]);
				CarData[asd][cComponent13] = strval(arrCoords[32]);
				CarData[asd][cKM] = strval(arrCoords[33]);
				CarData[asd][cPaintJob] = strval(arrCoords[34]);
				new car = AddStaticVehicleEx(CarData[asd][cModel], CarData[asd][cLocationx], CarData[asd][cLocationy], CarData[asd][cLocationz], CarData[asd][cAngle], CarData[asd][cColorOne], CarData[asd][cColorTwo], -1);
				SetVehicleToRespawn(car);
				asd++;
				totalcars++;
				//printf("%d - %d - %d", bc, car, VehicleInfo[bc][vModel]);
			}
 		}
		//printf("%d dupa for", totalhouses);
	}
	mysql_free_result();
	printf("%d Vehicles Loaded", totalcars);
	return 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<iiffffffffiis[64]s[64]iiiiis[255]iiiiiiiiiiiiiii>",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 citite: %d", masini);
	return 1;
}*/
I tried in two ways, but nothing. I cant load my personal vehicles and dont know why. Some1 can help me? I'll rep+
Reply
#2

what is you mysql version?
Reply
#3

Did you put LoadCar(); or LoadPersonalVehicles() on 'Public Ongamemodeinit' ?
Reply
#4

Quote:
Originally Posted by simo0000
Посмотреть сообщение
what is you mysql version?
Where can i see that? D:

Quote:
Originally Posted by Nin9r
Посмотреть сообщение
Did you put LoadCar(); or LoadPersonalVehicles() on 'Public Ongamemodeinit' ?
Yes.
Reply
#5

Some1? :-/
Reply
#6

Quote:
Originally Posted by simo0000
Посмотреть сообщение
what is you mysql version?
Mysql plugin R5.
Reply
#7

Код:
	printf("-Masini citite: %d", masini);
What does this line print?
Reply
#8

Quote:
Originally Posted by maramizo
Посмотреть сообщение
Код:
	printf("-Masini citite: %d", masini);
What does this line print?
How many cars are loaded.

I worked something out and changed from sql[512],row[512] to sql[1024],row[1024] and now my vehicles are loading but still not spawning. I changed that addstaticvehicleex to createvehicle.
Reply
#9

Well, a tip that always helps:
When debugging, always use printf to show you the SQL command lines you are sending to ensure it's being sent properly, then check if the variables themselves are working, afterwards, if the variables are working then it's obviously something wrong with your usage of spawning them.

Also, AddStaticVehicleEx only works under OnGameModeInit.
Reply
#10

Well, didnt used Addstaticvehicleex, i replaced it with Createvehicle. Still dont get it, why my cars dont spawn. They are loaded from database but they dont spawn.

Код:
public LoadPersonalVehicles()
{
    new arrCoords[41][64],sql[1024],row[1024];
	format(sql, sizeof(sql), "SELECT COUNT(id) FROM cars");
	mysql_query(sql);
	SQLLog(sql);
	mysql_store_result();
	mysql_fetch_row(row);
	totalcars = strval(row);
	if(totalcars>0)
	{
		for (new idx=1; idx<=totalcars; idx++)
		{
		    format(sql, sizeof(sql), "SELECT * FROM cars WHERE id=%d", idx);
		    mysql_query(sql);
			SQLLog(sql);
		    mysql_store_result();
		    if (mysql_num_rows() > 0)
			{
		        mysql_fetch_row(row);
				split(row, arrCoords, '|');
				CarData[idx][cId] = strval(arrCoords[0]);
				CarData[idx][cModel] = strval(arrCoords[1]);
				CarData[idx][cLocationx] = floatstr(arrCoords[2]);
				CarData[idx][cLocationy] = floatstr(arrCoords[3]);
				CarData[idx][cLocationz] = floatstr(arrCoords[4]);
				CarData[idx][cAngle]     = floatstr(arrCoords[5]);
				CarData[idx][cSaLocationx] = strval(arrCoords[6]);
				CarData[idx][cSaLocationy] = strval(arrCoords[7]);
				CarData[idx][cSaLocationz] = strval(arrCoords[8]);
				CarData[idx][cSaAngle] = strval(arrCoords[9]);
				CarData[idx][cColorOne] = strval(arrCoords[10]);
				CarData[idx][cColorTwo] = strval(arrCoords[11]);
				CarData[idx][cOwner] = strval(arrCoords[12]);
				CarData[idx][cDescription] = strval(arrCoords[13]);
				CarData[idx][cValue] = strval(arrCoords[14]);
				CarData[idx][cLicense] = strval(arrCoords[15]);
				CarData[idx][cOwned] = strval(arrCoords[16]);
				CarData[idx][cLockk] = strval(arrCoords[17]);
				CarData[idx][cNum] = strval(arrCoords[18]);
				CarData[idx][cComponent00] = strval(arrCoords[19]);
				CarData[idx][cComponent01] = strval(arrCoords[20]);
				CarData[idx][cComponent02] = strval(arrCoords[21]);
				CarData[idx][cComponent03] = strval(arrCoords[22]);
				CarData[idx][cComponent04] = strval(arrCoords[23]);
				CarData[idx][cComponent05] = strval(arrCoords[24]);
				CarData[idx][cComponent06] = strval(arrCoords[25]);
				CarData[idx][cComponent07] = strval(arrCoords[26]);
				CarData[idx][cComponent08] = strval(arrCoords[27]);
				CarData[idx][cComponent09] = strval(arrCoords[28]);
				CarData[idx][cComponent10] = strval(arrCoords[29]);
				CarData[idx][cComponent11] = strval(arrCoords[30]);
				CarData[idx][cComponent12] = strval(arrCoords[31]);
				CarData[idx][cComponent13] = strval(arrCoords[32]);
				CarData[idx][cKM] = strval(arrCoords[33]);
				CarData[idx][cPaintJob] = strval(arrCoords[34]);
				new car = CreateVehicle(CarData[idx][cModel], CarData[idx][cLocationx], CarData[idx][cLocationy], CarData[idx][cLocationz], CarData[idx][cAngle], CarData[idx][cColorOne], CarData[idx][cColorTwo], -1);
				SetVehicleToRespawn(car);
				totalcars++;
				//printf("%d - %d - %d", bc, car, VehicleInfo[bc][vModel]);
			}
 		}
		//printf("%d dupa for", totalhouses);
	}
	mysql_free_result();
	printf("%d Vehicles Loaded", totalcars);
	return 0;

}
Here is the last code. And yes, i have loadpersonalvehicles in ongamemodeinit.

And, from server log:

[16:53:53] 92 Houses Loaded
[16:53:53] 0 Bizz Loaded
[16:53:53] 11 SBusinesses Loaded
[16:53:53] Stuff loaded
[16:53:53] 1 IRC Channels Loaded
[16:53:53] 34 factiuni incarcate
[16:53:53] Leaders loaded
[16:53:53] Families loaded
[16:53:53] 2 Vehicles Loaded
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)