Simplest way around this?
#1

Quote:
Originally Posted by update
Player 1 buys vehicle A.
Vehicle A is given SAMP ID 1.
I save vehicle A and it is given MySQL ID 1.

So far so good. Stats save and load fine.

Player 2 spawns a temporary vehicle (Vehicle B) with a /veh command.
Vehicle B is given SAMP ID 2.
Because the vehicle is temporary and will disappear on a restart, no mysql ID is assigned.



Player 3 buys vehicle C.
Vehicle C is given SAMP ID 3.
I save vehicle C, but it is only given MySQL ID 2.

Now there's trouble. When trying to load vehicle C, the script loads the stats for MySQL ID 3 (which is non existent).
I'm working on my vehicle system, and I think I'm really over thinking an issue I'm stuck on. When a vehicle is bought, I insert a column to the MySQL table with the ID as an auto incrementing value. I save all vehicle stats by that ID, but that stops working when a vehicle is spawned by a source that isn't the dealership.

For example:
  • I buy a vehicle, it is assigned to ID 1.
    Vehicle 1 saves with MySQL ID 1.

  • Another vehicle is spawned with a /veh command. It is assigned (by samp) vehicle ID 2.

  • Another player buys a vehicle, with samp id 3, but when it saves that vehicle is only ID 2 in the MySQL table.
How should I work around this?
Reply
#2

I don't get what you mean.

The SAMP vehicle ids are server sided and are subject to change at any time.
Reply
#3

That's my problem. Once the SAMP vehicle IDs mix up, all the wrong stats are distributed.
Reply
#4

Well instead of saving the vehicle ID, save the vehicle model, position, color, tuning etc. whatever you are looking to save, and save that to the table instead. Then once you relaunch your gamemode/filterscript, just create the vehicles that exist, with the model, colors etc. that are saved in the table.
Reply
#5

The easiest way to go around that problem would be to not store the vehicles in their own database - but store the vehicles in the user accounts database, rendering the actual server-sided vehicleid somewhat useless and easily avoidable. I'm going to go ahead and guess that this is really isn't what you wanted in the first place, but it is an alternative that should work with no major problems.
Reply
#6

Quote:
Originally Posted by shitbird
View Post
The easiest way to go around that problem would be to not store the vehicles in their own database - but store the vehicles in the user accounts database, rendering the actual server-sided vehicleid somewhat useless and easily avoidable. I'm going to go ahead and guess that this is really isn't what you wanted in the first place, but it is an alternative that should work with no major problems.
I could see that working quite easily, except with the player being able to own up to five vehicles, that would be a hell of a lot of extra things to save for just a player. Mods, color, position.. times 5. This does seem like the simplest solution though.

Quote:
Originally Posted by BenzoAMG
View Post
Well instead of saving the vehicle ID, save the vehicle model, position, color, tuning etc. whatever you are looking to save, and save that to the table instead. Then once you relaunch your gamemode/filterscript, just create the vehicles that exist, with the model, colors etc. that are saved in the table.
I'm not saving the SAMP vehicle ID, but a server side ID assigned by the MySQL auto increment. Which actually leads me to think maybe my problem is in my loading method. My stock:
pawn Code:
stock LoadVehicle(houseid)
{
    new query[800],result[32];
    format(query,sizeof(query),"SELECT * FROM vehicles WHERE VehicleID = '%i'",houseid);
    mysql_query(query);
    mysql_store_result();
    if(mysql_num_rows() != 0) {
        while(mysql_fetch_row_format(query,"|")) {
            mysql_fetch_field_row(result, "VehicleID"); VehicleInfo[houseid][vVehID] = strval(result);
            mysql_fetch_field_row(result, "VehicleOwner"); VehicleInfo[houseid][vVehOwner] = result;
            mysql_fetch_field_row(result, "VehicleColor1"); VehicleInfo[houseid][vVehCol1] = strval(result);
            mysql_fetch_field_row(result, "VehicleColor2"); VehicleInfo[houseid][vVehCol2] = strval(result);
            mysql_fetch_field_row(result, "VehicleParkX"); VehicleInfo[houseid][vVehParkX] = floatstr(result);
            mysql_fetch_field_row(result, "VehicleParkY"); VehicleInfo[houseid][vVehParkY] = floatstr(result);
            mysql_fetch_field_row(result, "VehicleParkZ"); VehicleInfo[houseid][vVehParkZ] = floatstr(result);
            mysql_fetch_field_row(result, "VehicleParkA"); VehicleInfo[houseid][vVehParkA] = floatstr(result);
            mysql_fetch_field_row(result, "VehicleLockStatus"); VehicleInfo[houseid][vVehLockStatus] = strval(result);
            mysql_fetch_field_row(result, "VehicleModelID"); VehicleInfo[houseid][vVehModelID] = strval(result);
            //mysql_fetch_field_row(result, "VehicleSAMPID"); VehicleInfo[houseid][vVehSAMPlID] = strval(result);
        }
        CreateVehicle(VehicleInfo[houseid][vVehModelID],VehicleInfo[houseid][vVehParkX],VehicleInfo[houseid][vVehParkY],VehicleInfo[houseid][vVehParkZ],VehicleInfo[houseid][vVehParkA],VehicleInfo[houseid][vVehCol1],VehicleInfo[houseid][vVehCol2],99999999999999);
        vcount++;
    }
    mysql_free_result();
    return 1;
}
And my OnVehicleSpawn as of now:
pawn Code:
public OnVehicleSpawn(vehicleid)
{
    SetVehiclePos(vehicleid,VehicleInfo[vehicleid][vVehParkX],VehicleInfo[vehicleid][vVehParkY],VehicleInfo[vehicleid][vVehParkZ]);
    SetVehicleZAngle(vehicleid,VehicleInfo[vehicleid][vVehParkA]);
    return 1;
}
if I changed that ^ to this ->
pawn Code:
public OnVehicleSpawn(vehicleid)
{
    new vid = VehicleInfo[vehicleid][vVehID];
    SetVehiclePos(vid,VehicleInfo[vid][vVehParkX],VehicleInfo[vid][vVehParkY],VehicleInfo[vid][vVehParkZ]);
    SetVehicleZAngle(vid,VehicleInfo[vid][vVehParkA]);
    return 1;
}
Do you think that could change anything? (can't test it for a few hours) If I'm correct that should fetch the MySQL ID of the spawning vehicle first, and not set the position based on the SAMP vehicle ID like it's currently doing.

Any input?
Reply
#7

Quote:
Originally Posted by ******
View Post
I would just create an array "MAX_VEHICLES" big that stores the MySQL ID for every vehicle, then you can use that to quickly convert between the two.
Could you possibly expand on that idea a bit more? I understand what you're suggesting, but not sure on how to implement it. I thought I had everything figured out in my last post but it wouldn't seem so, so I guess I should try this solution.
Reply
#8

Use mysql_insert_id() to get the most recently inserted auto increment id after inserting the row.

pawn Code:
new g_vehSQLids[MAX_VEHICLES];

mysql_query(...);

g_vehSQLids[vehicleid] = mysql_insert_id();
Your original post has very awkward wording.
Reply
#9

Player 1 buys vehicle A.
Vehicle A is given SAMP ID 1.
I save vehicle A and it is given MySQL ID 1.

So far so good. Stats save and load fine.

Player 2 spawns a temporary vehicle (Vehicle B) with a /veh command.
Vehicle B is given SAMP ID 2.
Because the vehicle is temporary and will disappear on a restart, no mysql ID is assigned.



Player 3 buys vehicle C.
Vehicle C is given SAMP ID 3.
I save vehicle C, but it is only given MySQL ID 2.

Now there's trouble. When trying to load vehicle C, the script loads the stats for MySQL ID 3 (which is non existent).
Reply
#10

Quote:
Originally Posted by zDevon
View Post
Player 1 buys vehicle A.
Vehicle A is given SAMP ID 1.
I save vehicle A and it is given MySQL ID 1.

So far so good. Stats save and load fine.

Player 2 spawns a temporary vehicle (Vehicle B) with a /veh command.
Vehicle B is given SAMP ID 2.
Because the vehicle is temporary and will disappear on a restart, no mysql ID is assigned.



Player 3 buys vehicle C.
Vehicle C is given SAMP ID 3.
I save vehicle C, but it is only given MySQL ID 2.

Now there's trouble. When trying to load vehicle C, the script loads the stats for MySQL ID 3 (which is non existent).
Then don't load the stats for ID 3?

Post all the code, and table structures associated with your system. Maybe it's just me, but your posts make you seem very confused on how to implement MySQL in your mode.

The SAMP vehicle ids shouldn't even be associated with loading/saving from your database. They're completely dynamic and shouldn't be used to index rows in a table. They should just be stored into temporary server memory in case you need to change the vehicle in any way via script.

According to your post, MySQL is doing exactly what it should be doing.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)