SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 31/05/2020, 08:01 AM   #1
Mike861
Huge Clucker
 
Join Date: Feb 2018
Posts: 233
Reputation: 16
Question mysql vehicle loading issue

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.
Mike861 is offline   Reply With Quote
Old 31/05/2020, 09:08 AM   #2
Adamoneoone
Huge Clucker
 
Join Date: Sep 2014
Posts: 488
Reputation: 37
Default Re: mysql vehicle loading issue

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.
__________________
If you want to have your own custom script, or even want to have one of our already released scripts, join our SCRIPTING SERVICES DISCORD, or send me a private message!
Adamoneoone is offline   Reply With Quote
Old 31/05/2020, 09:16 AM   #3
Mike861
Huge Clucker
 
Join Date: Feb 2018
Posts: 233
Reputation: 16
Default Re: mysql vehicle loading issue

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
Mike861 is offline   Reply With Quote
Old 31/05/2020, 09:26 AM   #4
Adamoneoone
Huge Clucker
 
Join Date: Sep 2014
Posts: 488
Reputation: 37
Default Re: mysql vehicle loading issue

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...
__________________
If you want to have your own custom script, or even want to have one of our already released scripts, join our SCRIPTING SERVICES DISCORD, or send me a private message!
Adamoneoone is offline   Reply With Quote
Old 31/05/2020, 09:28 AM   #5
Mike861
Huge Clucker
 
Join Date: Feb 2018
Posts: 233
Reputation: 16
Default Re: mysql vehicle loading issue

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.
Mike861 is offline   Reply With Quote
Old 31/05/2020, 09:30 AM   #6
Adamoneoone
Huge Clucker
 
Join Date: Sep 2014
Posts: 488
Reputation: 37
Default Re: mysql vehicle loading issue

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
__________________
If you want to have your own custom script, or even want to have one of our already released scripts, join our SCRIPTING SERVICES DISCORD, or send me a private message!
Adamoneoone is offline   Reply With Quote
Old 31/05/2020, 09:38 AM   #7
Mike861
Huge Clucker
 
Join Date: Feb 2018
Posts: 233
Reputation: 16
Default Re: mysql vehicle loading issue

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.
Mike861 is offline   Reply With Quote
Old 31/05/2020, 09:41 AM   #8
Adamoneoone
Huge Clucker
 
Join Date: Sep 2014
Posts: 488
Reputation: 37
Default Re: mysql vehicle loading issue

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.
__________________
If you want to have your own custom script, or even want to have one of our already released scripts, join our SCRIPTING SERVICES DISCORD, or send me a private message!
Adamoneoone is offline   Reply With Quote
Old 31/05/2020, 09:45 AM   #9
Mike861
Huge Clucker
 
Join Date: Feb 2018
Posts: 233
Reputation: 16
Default Re: mysql vehicle loading issue

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?
Mike861 is offline   Reply With Quote
Old 31/05/2020, 10:49 AM   #10
Adamoneoone
Huge Clucker
 
Join Date: Sep 2014
Posts: 488
Reputation: 37
Default Re: mysql vehicle loading issue

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.
__________________
If you want to have your own custom script, or even want to have one of our already released scripts, join our SCRIPTING SERVICES DISCORD, or send me a private message!
Adamoneoone is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mysql Loading issue JessThompson Scripting Help 9 05/03/2017 01:42 AM
[HELP] MySQL Loading Issue BornHuman Scripting Help 3 15/05/2016 07:56 AM
Vehicle System Loading issue Zonoya Scripting Help 0 08/03/2015 10:36 AM
MySQL (R7 Loading Issue) zT KiNgKoNg Scripting Help 0 30/08/2014 02:25 PM
Mysql Vehicle Loading Issue Rokzlive Scripting Help 1 23/12/2011 09:53 AM


All times are GMT. The time now is 12:15 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.