Conflict/Problem with ID's from MySQL, assigning them locally.
#1

The issue I'm having is that when I use my parking ticket command when I use it on ID 13, on the database ID 13 is the last ID of vehicles (last vehicle made) and when I try and put a ticket on vehicle 13 it returns the model as 420 (Taxi) as opposed to 579 (Huntley).

As you can see below, I put the variables locally after I create the vehicle. The huntley is the first vehicle in the table on mysql.
VehModel[vehicleid] = VehModel[x];

That shouldn't have any conflicts? I'm a little confused as to why this is happening.
When printing, it is printing correct models for each vehicle.


pawn Код:
cache_get_data(rows, fields);
    for (new y; y != rows; ++y)
    {
            cache_get_row(y, vvid, QueryString);
            x = cache_get_row_int(y, vvid);
            printf("x %d", x);

            cache_get_row(y, vVehModel, QueryString);
            VehModel[x] = strval( QueryString);

            cache_get_row(y, vVehColour1, QueryString);
            VehColour1[x] = strval( QueryString);

            cache_get_row(y, vVehColour2, QueryString);
            VehColour2[x] = strval( QueryString);

            cache_get_row(y,vVehSpawnX, QueryString);
            VehSpawnX[x] = floatstr( QueryString);

            cache_get_row(y,vVehSpawnY, QueryString);
            VehSpawnY[x] = floatstr( QueryString);

            cache_get_row(y,vVehSpawnZ, QueryString);
            VehSpawnZ[x] = floatstr( QueryString);
           
            cache_get_row(y,vVehSpawnAngle, QueryString);
            VehSpawnAngle[x] = floatstr( QueryString);
           
            cache_get_row(y,vVehSiren, QueryString);
            VehSiren[x] = strval(QueryString);
           
            vehicleid = CreateVehicle(VehModel[x], VehSpawnX[x], VehSpawnY[x],VehSpawnZ[x], VehSpawnAngle[x], VehColour1[x], VehColour2[x], -1, VehSiren[x]);
            VehicleSQLID[vehicleid] = x;
            printf("VehSQLID %d", x);
           
            VehModel[vehicleid] = VehModel[x];
            printf("Veh Model: %d VehModel %d VehSQLModel %d", GetVehicleModel(vehicleid), VehModel[vehicleid], VehModel[x]);
            printf("%s VehModel %s",VehicleNames[GetVehicleModel(vehicleid) - 400], VehicleNames[VehModel[vehicleid] - 400]);
            VehColour1[vehicleid] = VehColour1[x];
            VehColour2[vehicleid] = VehColour2[x];
            VehSpawnX[vehicleid] = VehSpawnX[x];
            VehSpawnY[vehicleid] = VehSpawnY[x];
            VehSpawnZ[vehicleid] = VehSpawnZ[x];
            VehSpawnAngle[vehicleid] = VehSpawnAngle[x];
            VehSiren[vehicleid] = VehSiren[x];
Parking Ticket Command
pawn Код:
CMD:pticket(playerid, params[])
{
    if(LoggedIn[playerid] == 0) return SendClientMessage(playerid, COLOUR_GREY, "You must be logged in to use this command.");
    new plate[12],amount, reason[64], id;
    if(Faction[playerid] != 1) return SendClientMessage(playerid, COLOUR_GREY, "You are not a member of the police.");
    if(sscanf(params, "s[12]ds[64]",plate, amount,reason)) return SendClientMessage(playerid, COLOUR_GREY, "Usage: /pticket [license plate] [amount] [reason]");
    for(new x = 0; x < MAX_VEHICLES; x++)
    {
        if(!isnull(VehPlate[x]) && !strcmp(plate, VehPlate[x], true))
        {
            id = x;
            printf("%d vehid", id);
            break;
        }
    }
    if(VehicleSQLID[id] < 1)return SendClientMessage(playerid, COLOUR_GREY, "You cannot place a ticket on this vehicle. (Admin Spawned/Static).");
    if(VehicleFaction[id] == 1)return SendClientMessage(playerid, COLOUR_GREY, "This is a government vehicle, you cannot give it a parking ticket.");
    new query[256];
    format(query, sizeof(query), "INSERT INTO `ptickets` (VehID, Amount, PlacedBy, Date, Reason) VALUES (%d, %d, %d, %d, '%s')", VehicleSQLID[id], amount, PlayerSQLID[playerid], gettime(), reason);
    mysql_tquery(dbHandle, query, "PTicket", "iiis", playerid, id, amount, reason);
    return 1;
}
pawn Код:
forward PTicket(playerid, id, amount, reason[]);
public PTicket(playerid, id, amount, reason[])
{
    new string[128];
    new tid = cache_insert_id();
    PTVehSQLID[tid] = VehicleSQLID[id];
    PTByID[tid] = PlayerSQLID[playerid];
    PTDate[tid] = gettime();
    strcpy(PTReason[tid], reason, 24);
    PTAmount[tid] = amount;
    printf("%d ID", id);
    SendClientMessage(playerid, COLOUR_BLUE, "__________Parking Ticket Information__________");
    format(string, sizeof(string), "Vehicle: "COL_GREY"%s "COL_WHITE"| License Plate: "COL_GREY"%s", VehicleNames[VehModel[id]-400], VehPlate[id]);
    SendClientMessage(playerid, COLOUR_WHITE, string);
    format(string, sizeof(string), "Amount: "COL_RED"$%s "COL_WHITE"| Reason: "COL_GREY"%s", AddCommas(amount), reason);
    SendClientMessage(playerid, COLOUR_WHITE, string);
    format(string, sizeof(string), "You have placed a parking ticket on the %s for the amount of $%s. The owner will be notified.", VehicleNames[VehModel[id] - 400], AddCommas(amount));
    SendClientMessage(playerid, COLOUR_ORANGE, string);
    printf("Veh Model: %d VehModel %d", GetVehicleModel(id), VehModel[id]);
    printf("%s VehModel %s",VehicleNames[GetVehicleModel(id) - 400], VehicleNames[VehModel[id] - 400]);
    format(string, sizeof(string), "* %s places a parking ticket on the %s *", GetNameEx(playerid), VehicleNames[VehModel[id]-400]);
    ProxDetector(30.0, playerid, string, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE);
    return 1;
}
The results of the printf in the PTicket public are incorrect and display as 420 (Taxi Model) - which again is the last ID of the table. (13)
Reply
#2

Here is a question, why do you use that way to load your info ?
PHP код:
        cache_get_field_content(0"String"PlayerI[playerid][mystring], mysql50);
        
PlayerI[playerid][myint] = cache_get_field_content_int(0"Int");
        
PlayerI[playerid][myfloat] = cache_get_field_content_float(0"Float"); 
there, all of your data can be pulled the way you want, omitting the need for strval and stuff (well that is if you use blueG's plugin, I'm not sure if you do tho.)

While it might not be that obvious, your loading method overrides your old data in some way, my suggestion is make local variables for params needed in createveh, create your vehicle first then load the data on the created vehicle ID.
Reply
#3

Thanks for the reply,

I've intended to change the method of loading vehicles but I just haven't yet.

How does the variables overwrite?

Also how can I create the vehicle before I load the variables as it has no data ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)