SA-MP Forums Archive
Saving all server vehicles MYSQL - 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: Saving all server vehicles MYSQL (/showthread.php?tid=209063)



Saving all server vehicles MYSQL - NewbBeginner - 09.01.2011

Код:
public OnGameModeExit()
{
    for(new ServerVehicles; ServerVehicles < MAX_VEHICLES; ServerVehicles++)
    {
	new	Float:PosnX;
	new	Float:PosY;
	new	Float:PosZ;
	new	Float:aAngle;
	new aModel;
	
	aModel = GetVehicleModel(GetPlayerVehicleID(ServerVehicles));

	GetVehiclePos(ServerVehicles, PositsioonX, PositsioonY, PositsioonZ);
	GetVehicleZAngle(GetPlayerVehicleID(ServerVehicles), aAngle);
	
    format(Query, sizeof(Query), "UPDATE `cars` SET `PosX` = '%f', `PosY` = '%f', `PosZ` = '%f', `AutoAngle` = '%f'  WHERE `CarID` = '%d'",
	PosX,
	PosY,
	PosnZ,
	aAngle,
	aAngle,
	aModel);
	mysql_query(Query);
 	}
	mysql_close();
	return 1;
}
I have this code, and if I do GMX, then it is on it's old page, like I saved it into database.
Please help.


Re: Saving all server vehicles MYSQL - NewbBeginner - 11.01.2011

I figured something out, I have now this code, but it doesn't update.
Код:
stock savecars()
{
	for(new id; id < cars; id++)
    {
        new Float:pposX, Float:pposY, Float:pposZ,Float:AutoAngle;
        GetVehiclePos(id, pposX, pposY, pposZ);
        GetVehicleZAngle(id, AutoAngle);
		format(Query, sizeof(Query), "UPDATE `cars` SET `PosX` = '%f', `PosY` = '%f', `PosZ` = '%f', `AutoAngle` = '%f' WHERE `carid` = '%d'",
		pposX,
		pposY,
		pposZ,
		AutoAngle,
		id);
		mysql_query(Query);
		}
}



Re: Saving all server vehicles MYSQL - JaTochNietDan - 11.01.2011

It's a strange way of using MySQL, and it's probably not going to work, there's simply far too many queries you'll need to execute in order to save all of that information. The server would probably crash before it gets anywhere near updating all of those rows.

You should re-think your way of saving all of the vehicles, possibly by a file system, because this is madness


Re: Saving all server vehicles MYSQL - Sergei - 11.01.2011

1. Save vehicles before closing server.
2. Use threads.
3. Don't write in noob SQL language (e.g. puting '' for every possible values, etc).


Re: Saving all server vehicles MYSQL - Scenario - 11.01.2011

Quote:
Originally Posted by Sergei
Посмотреть сообщение
3. Don't write in noob SQL language (e.g. puting '' for every possible values, etc).
What do you mean "putting " for every possible value"? Do you mean adding `'s around each variable place holder? (%s, %d, %f)


Re: Saving all server vehicles MYSQL - Sergei - 11.01.2011

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
What do you mean "putting " for every possible value"? Do you mean adding `'s around each variable place holder? (%s, %d, %f)
' is not " and not `. ' is to be put around string values. I find it stupid when people ask basic questions about SQL and they have hundreas of ` and ' symbols in their query. I call that noob SQL language.


Re: Saving all server vehicles MYSQL - _rAped - 11.01.2011

Quote:
Originally Posted by Sergei
Посмотреть сообщение
' is not " and not `. ' is to be put around string values. I find it stupid when people ask basic questions about SQL and they have hundreas of ` and ' symbols in their query. I call that noob SQL language.
I call that a noob statement.


Re: Saving all server vehicles MYSQL - DVDK - 11.01.2011

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
It's a strange way of using MySQL, and it's probably not going to work, there's simply far too many queries you'll need to execute in order to save all of that information. The server would probably crash before it gets anywhere near updating all of those rows.

You should re-think your way of saving all of the vehicles, possibly by a file system, because this is madness
Nothing wrong with that, i had a house system with about 100 houses in a loop, and in every loop it had about 3 to 5 querys.


Re: Saving all server vehicles MYSQL - NewbBeginner - 11.01.2011

Quote:
Originally Posted by DVDK
Посмотреть сообщение
Nothing wrong with that, i had a house system with about 100 houses in a loop, and in every loop it had about 3 to 5 querys.
But I have something wrong with my code ? It just doesn't save.


Re: Saving all server vehicles MYSQL - Sergei - 11.01.2011

Quote:
Originally Posted by _rAped
Посмотреть сообщение
I call that a noob statement.
Quote:

In need of attention.

Explains it all.