22.01.2015, 20:59
Also, when you want to set the ID yourself, remove the auto-increment from your ID column, but keep the primary key setting.
Then you can control how the ID is stored, and you can use the same ID in both your array as in MySQL.
When loading data from MySQL, You can use the ID as the index of your array. Read the ID first, then use that ID to store the rest of your data in the proper array-index upon reading it from the database.
When saving, do the same: use the index of your array as ID in your table.
Your database will have the same data with the same ID as in your script this way.
You'll need to add the ID to your INSERT query to add a new row to the database, as MySQL won't auto-increase it anymore.
I'm doing the same thing when creating gas-stations, police-stations, speedcams, houses, businesses, mission-locations, mission-data, mission vehicles (which are spawned near every spawnlocation), ...
All that data is stored inside arrays and is constantly used by the script from the moment you start the server until you shut it down (static data that has a preset limit, such as a limit for the max amount of houses, speedcams and such).
Only keep the auto-increment setting for data that isn't loaded fully upon OnGameModeInit such as logs and playerdata, as your server loads playerdata when they connect, they don't need to load data about all players when the server is started.
And logs aren't loaded at all, only during an admin-command perhaps to review the logs in-game.
Player-data and logs are dynamic data, they keep getting larger and larger without a preset limit, and they aren't stored inside arrays for the entire runtime duration of your server.
Then you can control how the ID is stored, and you can use the same ID in both your array as in MySQL.
When loading data from MySQL, You can use the ID as the index of your array. Read the ID first, then use that ID to store the rest of your data in the proper array-index upon reading it from the database.
When saving, do the same: use the index of your array as ID in your table.
Your database will have the same data with the same ID as in your script this way.
You'll need to add the ID to your INSERT query to add a new row to the database, as MySQL won't auto-increase it anymore.
I'm doing the same thing when creating gas-stations, police-stations, speedcams, houses, businesses, mission-locations, mission-data, mission vehicles (which are spawned near every spawnlocation), ...
All that data is stored inside arrays and is constantly used by the script from the moment you start the server until you shut it down (static data that has a preset limit, such as a limit for the max amount of houses, speedcams and such).
Only keep the auto-increment setting for data that isn't loaded fully upon OnGameModeInit such as logs and playerdata, as your server loads playerdata when they connect, they don't need to load data about all players when the server is started.
And logs aren't loaded at all, only during an admin-command perhaps to review the logs in-game.
Player-data and logs are dynamic data, they keep getting larger and larger without a preset limit, and they aren't stored inside arrays for the entire runtime duration of your server.