Posts: 190
Threads: 28
Joined: Jul 2013
Reputation:
0
Alright, in my database I have a field 'id' which is set to auto_increment. If I were to get the data of the field 'id', can I just use GetPlayerVehicleID because it's gonna be same as the id in the table? By the way I am talking about cars table where all the server vehicles are stored.
Posts: 1,733
Threads: 20
Joined: Nov 2010
Reputation:
0
If you only create vehicles during OnGameModeInit and nowhere else in your code, it could work.
But if you're creating vehicles elsewhere and delete a few during the entire session your server is running, your id's WILL be messed up.
You should not store vehicle-id's in a database for saving.
I'm not using a database, just ordinary files to store my mission-vehicles (vehicles already present near spawn-locations).
It only stores the model, coordinates, rotation and colors.
My gamemode holds 400 mission-vehicles for example, with ID's 1 to 400.
Players are also able to buy house-vehicles, which get destroyed when the player leaves the server.
The server is running and all mission vehicles are loaded. So far so good.
Then, player A joins the server and owns 2 vehicles for example.
Upon joining the server, his house-vehicles are loaded and they get ID's 401 to 402.
Then player B joins the server and has 4 house-vehicles. They get ID's 403 to 406.
Now player A buys a new vehicle which gets ID 407.
Both players disconnect and all vehicles of both players are unloaded, so ID's 401 to 407 are available again.
Now player A re-joins the server and his vehicles are loaded, all 3 of them.
Previously they had ID's 401, 402 and 407, right?
Now they will get ID's 401, 402 and 403, because those slots are available.
The ID's are messed up as you can see.
Storing vehicleid's is just NOT-DONE. Only save the data about the vehicles, not their id.
Posts: 305
Threads: 52
Joined: Mar 2012
Reputation:
0
For what I'll do it by MY style. Create 2 Columns, ID and Vehicle Model ID. The ID is the number of vehicles that is set using AUTO_INCREMENT and once the vehicle is created, I'll use mysql_insert_id and GetVehicleModel and insert both to the database.