SA-MP Forums Archive
MySQL Player Vehicles. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: MySQL Player Vehicles. (/showthread.php?tid=257131)



MySQL Player Vehicles. - Feli97 - 24.05.2011

Hi all, i am doing a script which load player vehicles when he/she logs in.
But I've a problem, it doesn't work... This is the script for loading vehicles at server start.
Код:
stock initiatePVehicleSpawns() {
	new sql[164],row[255],result[1024],bool: success = true;
	format(sql, sizeof(sql), "SELECT COUNT(*) FROM playervehicles");
	mysql_query(sql);
	mysql_store_result();
	mysql_fetch_row(row);
	totalcars = strvalEx(row);
	mysql_free_result();
    for (new i=0; i<=totalcars; i++)
	{
	                format(sql, sizeof(sql), "SELECT * FROM playervehicles WHERE ID = %d", i);
    				mysql_query(sql);

				    mysql_get_field("vOwner", pVehicleInfo[i][vOwner]);

					mysql_get_field("vModel", result);
					pVehicleInfo[i][vModel] = strval(result);

					mysql_get_field("vX", result);
					pVehicleInfo[i][vVehiclePosition][0] = floatstr(result);

					mysql_get_field("vY", result);
					pVehicleInfo[i][vVehiclePosition][1] = floatstr(result);

					mysql_get_field("vZ", result);
					pVehicleInfo[i][vVehiclePosition][2] = floatstr(result);

					mysql_get_field("vA", result);
					pVehicleInfo[i][vVehicleRotation] = floatstr(result);

					mysql_get_field("vColor1", result);
					pVehicleInfo[i][vColor][0] = strval(result);

					mysql_get_field("vColor2", result);
					pVehicleInfo[i][vColor][1] = strval(result);

					mysql_get_field("vPaintjob", result);
					pVehicleInfo[i][vPaintjob] = strval(result);

					vPuzz[i] = 1;

					systemVariables[vehicleCounts][0]++;
				}
    if(success) printf("[script] %d vehicles loaded.", systemVariables[vehicleCounts][0]);
	mysql_free_result();
	}
And this is the code for loading player vehicles when he logs.
Код:
forward LoadPlayerVehicles(playerid);
public LoadPlayerVehicles(playerid){
GetPlayerName(playerid, pname, sizeof (pname));
new sql[256],row[253];
format(sql, sizeof(sql), "SELECT COUNT(*) FROM playervehicles");
mysql_query(sql);
mysql_store_result();
mysql_fetch_row(row);
totalcars = strvalEx(row);
mysql_free_result();
for (new i=0; i<=totalcars; i++)
	{
 	if(!strcmp(pVehicleInfo[i][vOwner],pname)) print("I recognised a player vehicle"); //If it prints there will be recognised a file with a player vehicle
 	}
	}
Pls.. Help me!

The problem is that the code print all vehicles and didn't recognise the player vehicle ones...


Re: MySQL Player Vehicles. - Feli97 - 24.05.2011

Can anyone respond?


Re: MySQL Player Vehicles. - Feli97 - 24.05.2011

Anyone there HELP MEE IT'S URGENT!!!


Re: MySQL Player Vehicles. - dannyk0ed - 24.05.2011

No-One barely knows MSQ


Re: MySQL Player Vehicles. - Feli97 - 24.05.2011

You can post too a way for script the load-player vehicles, it isn't so urgent to fix this script, it's urgent to make one which loads player vehicles


Re: MySQL Player Vehicles. - Feli97 - 24.05.2011

HELP


Re: MySQL Player Vehicles. - Feli97 - 24.05.2011

I'm gonna pay who will fix this script.


Re: MySQL Player Vehicles. - GamingTurf - 24.05.2011

1st Script:
pawn Код:
format(sql, sizeof(sql), "SELECT * FROM playervehicles WHERE ID = %d", i);
It's selecting from the playervehicle's database, where the "ID" is the playersid (Which is RANDOM). - I don't see how that works, it should be:
pawn Код:
// Get the player's name & store in int 'name'.
format(sql, sizeof(sql), SELECT * FROM playervehicles WHERE owner='%s', name);
Don't know if that is right ..

2nd Script:

pawn Код:
format(sql, sizeof(sql), "SELECT COUNT(*) FROM playervehicles");
Shouldnt you use:
pawn Код:
//Get player's name & store as 'name'
format(sql, sizeof(sql), "SELECT * FROM playervehicles WHERE owner = '%s'", name");
I'm not sure if i'm right or wrong as i dont even understand your script .. or what you want it to do.


Re: MySQL Player Vehicles. - Feli97 - 24.05.2011

I've done this 2nd version but it doesn't work too..
Код:
 stock initiatePVehicleSpawns(playerid) {
	new sql[164],result[1024],bool: success = true, vlodded, line[1024];
	GetPlayerName(playerid, pname, sizeof (pname));
 	format(sql, sizeof(sql), "SELECT * FROM playervehicles WHERE vOwner = '%s'", pname);
 	mysql_query(sql);
    mysql_store_result(RegistrationSystemConnection);
    vlodded = mysql_num_rows(RegistrationSystemConnection);
    printf("%d",vlodded);
    for(new i=0; i<mysql_num_rows(RegistrationSystemConnection); i++)
    {
	               	mysql_fetch_row(line);
	               	
  	 				mysql_get_field("vOwner", pVehicleInfo[i][vOwner]);

					mysql_get_field("vModel", result);
					pVehicleInfo[i][vModel] = strval(result);

					mysql_get_field("vX", result);
					pVehicleInfo[i][vVehiclePosition][0] = floatstr(result);

					mysql_get_field("vY", result);
					pVehicleInfo[i][vVehiclePosition][1] = floatstr(result);

					mysql_get_field("vZ", result);
					pVehicleInfo[i][vVehiclePosition][2] = floatstr(result);

					mysql_get_field("vA", result);
					pVehicleInfo[i][vVehicleRotation] = floatstr(result);

					mysql_get_field("vColor1", result);
					pVehicleInfo[i][vColor][0] = strval(result);

					mysql_get_field("vColor2", result);
					pVehicleInfo[i][vColor][1] = strval(result);

					mysql_get_field("vPaintjob", result);
					pVehicleInfo[i][vPaintjob] = strval(result);
					printf("Trovato veicolo %d, Owner %s",i ,pVehicleInfo[i][vOwner]);
					vPuzz[i] = 1;

					systemVariables[vehicleCounts][0]++;
				}
    if(success) printf("[script] %d vehicles loaded.", systemVariables[vehicleCounts][0]);
	mysql_free_result();
	}



Re: MySQL Player Vehicles. - GamingTurf - 24.05.2011

Quote:
Originally Posted by Feli97
Посмотреть сообщение
I've done this 2nd version but it doesn't work too..
Код:
 stock initiatePVehicleSpawns(playerid) {
	new sql[164],result[1024],bool: success = true, vlodded, line[1024];
	GetPlayerName(playerid, pname, sizeof (pname));
 	format(sql, sizeof(sql), "SELECT * FROM playervehicles WHERE vOwner = '%s'", pname);
 	mysql_query(sql);
    mysql_store_result(RegistrationSystemConnection);
    vlodded = mysql_num_rows(RegistrationSystemConnection);
    printf("%d",vlodded);
    for(new i=0; i<mysql_num_rows(RegistrationSystemConnection); i++)
    {
	               	mysql_fetch_row(line);
	               	
  	 				mysql_get_field("vOwner", pVehicleInfo[i][vOwner]);

					mysql_get_field("vModel", result);
					pVehicleInfo[i][vModel] = strval(result);

					mysql_get_field("vX", result);
					pVehicleInfo[i][vVehiclePosition][0] = floatstr(result);

					mysql_get_field("vY", result);
					pVehicleInfo[i][vVehiclePosition][1] = floatstr(result);

					mysql_get_field("vZ", result);
					pVehicleInfo[i][vVehiclePosition][2] = floatstr(result);

					mysql_get_field("vA", result);
					pVehicleInfo[i][vVehicleRotation] = floatstr(result);

					mysql_get_field("vColor1", result);
					pVehicleInfo[i][vColor][0] = strval(result);

					mysql_get_field("vColor2", result);
					pVehicleInfo[i][vColor][1] = strval(result);

					mysql_get_field("vPaintjob", result);
					pVehicleInfo[i][vPaintjob] = strval(result);
					printf("Trovato veicolo %d, Owner %s",i ,pVehicleInfo[i][vOwner]);
					vPuzz[i] = 1;

					systemVariables[vehicleCounts][0]++;
				}
    if(success) printf("[script] %d vehicles loaded.", systemVariables[vehicleCounts][0]);
	mysql_free_result();
	}
Can you post a picture of your MySQL database structure ?