mysql vehicle loading issue
#1

I have created a dynamic vehicle system that allows me to create vehicles around the map just by a command, so far it saves the vehicles into the table but i'm not sure how am i supposed to load it. I haven't been making any dynamic systems so far rather than accounts but i think im learning it so far. Here's the code i've tried:

Code:
LoadVehicles()
{
	 new query[1000], vehiclecolor1, vehiclecolor2, Float:vehiclex, Float:vehicley, Float:vehiclez, Float:vehiclea;
	 mysql_format(mysql_handle, query, sizeof(query), "SELECT * FROM `vehicles` WHERE `vehmodel` = %d, `vehcolor1` = %d, `vehcolor2` = %d, `veh_x` = %f, `veh_y` = %f, `veh_z` = %f, `veh_a` = %f ", vehicledata[vehicleid2][vehmodel], vehicledata[vehicleid2][vehcolor1], vehicledata[vehicleid2][vehcolor2], vehicledata[vehicleid2][veh_x], vehicledata[vehicleid2][veh_y], vehicledata[vehicleid2][veh_z], vehicledata[vehicleid2][veh_a]);
	 mysql_tquery(mysql_handle, query);
	
	

	for(new v = 0; v < sizeof(vehicleid2); v++)
	{
	        vehiclemodel = vehicledata[v][vehmodel];
		vehiclecolor1 = vehicledata[v][vehcolor1];
		vehiclecolor2 = vehicledata[v][vehcolor2];
		vehiclex = vehicledata[v][veh_x];
		vehicley = vehicledata[v][veh_y];
		vehiclez = vehicledata[v][veh_z];
		vehiclea = vehicledata[v][veh_a];
		
	        CreateVehicle(vehiclemodel, vehiclex, vehicley, vehiclez, vehiclea, vehiclecolor1, vehiclecolor2, -1, 0);
	}
	
        return 1;
}
Then i just do LoadVehicles(); under OnGameModeInit.
Reply
#2

The way you wrote it is wrong already.

The way you should do it is:
1. Have the top part under OnGameModeInit:
Code:
public OnGameModeInit()
{
	 new query[1000], vehiclecolor1, vehiclecolor2, Float:vehiclex, Float:vehicley, Float:vehiclez, Float:vehiclea;
	 mysql_format(mysql_handle, query, sizeof(query), "SELECT * FROM `vehicles` WHERE `vehmodel` = %d, `vehcolor1` = %d, `vehcolor2` = %d, `veh_x` = %f, `veh_y` = %f, `veh_z` = %f, `veh_a` = %f ", vehicledata[vehicleid2][vehmodel], vehicledata[vehicleid2][vehcolor1], vehicledata[vehicleid2][vehcolor2], vehicledata[vehicleid2][veh_x], vehicledata[vehicleid2][veh_y], vehicledata[vehicleid2][veh_z], vehicledata[vehicleid2][veh_a]);
	 mysql_tquery(mysql_handle, query);
2. However as you can see, nothing will be called, so we have to turn
Code:
mysql_tquery(mysql_handle, query);
into
Code:
mysql_tquery(mysql_handle, query, "LoadVehicles", "");
3. In order for this change to work, you have to forward and public LoadVehicles:
Code:
forward LoadVehicles();
public LoadVehicles()
{
	for(new v = 0; v < sizeof(vehicleid2); v++)
	{
	        vehiclemodel = vehicledata[v][vehmodel];
		vehiclecolor1 = vehicledata[v][vehcolor1];
		vehiclecolor2 = vehicledata[v][vehcolor2];
		vehiclex = vehicledata[v][veh_x];
		vehicley = vehicledata[v][veh_y];
		vehiclez = vehicledata[v][veh_z];
		vehiclea = vehicledata[v][veh_a];
		
	        CreateVehicle(vehiclemodel, vehiclex, vehicley, vehiclez, vehiclea, vehiclecolor1, vehiclecolor2, -1, 0);
	}
	
        return 1;
}
!! THIS CODE WON'T WORK, you have to apply the changes accordingly, it is just a canvas.
Reply
#3

The variables next to query should be down at the LoadVehicles callback, anyways i've put everything as you said and its not loading the vehicles. Now there's one error in the mysql error log.
Code:
[11:18:22] [plugins/mysql] error #1064 while executing query "SELECT * FROM `vehicles` WHERE `vehmodel` = 0, `vehcolor1` = 0, `vehcolor2` = 0, `veh_x` = 0.000000, `veh_y` = 0.000000, `veh_z` = 0.000000, `veh_a` = 0.000000 ": You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' `vehcolor1` = 0, `vehcolor2` = 0, `veh_x` = 0.000000, `veh_y` = 0.000000, `veh_' at line 1
[11:18:22] [log-core] exception 0XC0000005 (ACCESS_VIOLATION) from Vectored Exception Handler catched; shutting log-core down
Reply
#4

The proper way to write it using SQL is to use "AND" and not using commas.
Code:
SELECT * FROM `vehicles` WHERE `vehmodel` = 0 AND `vehcolor1` = 0 AND...
Reply
#5

Quote:
Originally Posted by Adamoneoone
View Post
The proper way to write it using SQL is to use "AND" and not using commas.
Code:
SELECT * FROM `vehicles` WHERE `vehmodel` = 0 AND `vehcolor1` = 0 AND...
I'm using commas for accounts and it works, but in this case now i don't have the error anymore. But the vehicles are still not loading.
Reply
#6

Show the whole thing you've got. Anyways, if you try to load using this query, you won't see anything for sure, gta sa modelids range from 400 to 600 smth,
Quote:

`vehmodel` = 0

won't load anything
Reply
#7

Quote:
Originally Posted by Adamoneoone
View Post
Show the whole thing you've got. Anyways, if you try to load using this query, you won't see anything for sure, gta sa modelids range from 400 to 600 smth, won't load anything
What else do you want me to show, and of course i know they range from 400 to 611.
Reply
#8

The code you've written. If you copy pasted what I wrote above you won't get anything, as there's no cache_get function at all.
Reply
#9

Quote:
Originally Posted by Adamoneoone
View Post
The code you've written. If you copy pasted what I wrote above you won't get anything, as there's no cache_get function at all.
I don't use cache for this system, but i do use it for login/register. But i assume it would work since there are functions from where i can get values from the vehicles that are saved in the table. I only learned mysql recently, is cache necessary for almost every system that i'll make?
Reply
#10

Quote:

But i assume it would work since there are functions from where i can get values from the vehicles that are saved in the table.

Which ones are you talking about?

Again without any piece of code we can't tell you what's wrong.
If you ever plan on retreiving data from the DB, you'll need to use cache or orm funcs.
Check the wiki for more info.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)