This sets the ticket ID to 498 on MySQL when it should be 1.
#1

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 = 1; x < GetVehiclePoolSize()+1; x++)
    {
        if(!isnull(VehPlate[x]) && !strcmp(plate, VehPlate[x], true))
        {
            id = x;
            printf("%d vehid", id);
            printf("%d model",VehModel[id]);
            break;
        }
    }
    if(amount <  1 || amount > 1000)return SendClientMessage(playerid, COLOUR_GREY, "Amount must be between $1 and $1,000.");
    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];
    printf("%d vehid", id);
    printf("%d model",VehModel[id]);
    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;
}
Title says all. When I login to the MYSQL it says the ticket is 498 despite there being no other tickets? I reset the auto increment too.

MAX_TICKETS = 500.

pawn Код:
forward PTicket(playerid, id, amount, reason[]);
public PTicket(playerid, id, amount, reason[])
{
    printf("%d model",VehModel[id]);
    new string[128];
    new tid = cache_insert_id();
    printf("%d - ticket id", cache_insert_id());
    if(tid > MAX_TICKETS)return SendClientMessage(playerid, COLOUR_GREY, "Ticket not created; maximum ticket reached, contact admin.");
    PTID[tid] = tid;
    PTVehSQLID[tid] = VehicleSQLID[id];
    PTByID[tid] = PlayerSQLID[playerid];
    PTDate[tid] = gettime();
    strcpy(PTReason[tid], reason, 24);
    PTAmount[tid] = amount;
    printf("%d ID", id);
    printf("COLOR %d", VehColour1[id]);
    new name = VehModel[id] - 400;
    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[name], AddCommas(amount));
    SendClientMessage(playerid, COLOUR_ORANGE, string);
    format(string, sizeof(string), "* %s places a parking ticket on the %s *", GetNameEx(playerid), VehicleNames[name]);
    ProxDetector(30.0, playerid, string, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE);
    return 1;
}
Reply
#2

Disabling and enabling auto increment doesn't remove its value. See: http://forum.sa-mp.com/showpost.php?...71&postcount=2
Reply
#3

Thanks
Reply
#4

The id isn't supposed to be of any intrinsic value. Its value does not matter. It is just there to identify the row and it shouldn't be used as an array index, ever. The idea behind using a database is that you can store a theoretically infinite amount of data. Frankly I don't understand why you store these tickets in memory while you can grab them from the database as and when they're needed.
Reply
#5

I wasn't sure at the time how to do that. How would you suggest is the best way to then load them all into a dialog system?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)