MYSQL | Vehicle System
#1

Hi,

I've got this strange bug that I can't seem to solve. Ill paste the code

PHP код:
enum VehicleStats
{
    
vID,
    
vModel,
    
Float:vPosition[4],
    
vOwner[24],
    
vColor1,
    
vColor2,
}
new 
Vehicle[MAX_VEHICLES][VehicleStats];
COMMAND:createvehicle(playeridparams[])
{
    new 
vModelTiFloat:posxFloat:posyFloat:poszFloat:posavColor1TvColor2Tquery[228], string[128];
    if(
sscanf(params"ddd"vModelTvColor1TvColor2T)) return SendClientMessage(playeridCOLOR_GREY"[Command] Usage: /createvehicle [ModelID] [Color1] [Color2]");
    
GetPlayerPos(playeridposxposyposz);
    
GetPlayerFacingAngle(playeridposa);
    if(
vModelT 411 || vModelT 611) return SendClientMessage(playeridCOLOR_GREY"Model ID Must not be below 411 and not higher than 611");
     
mysql_insert_id();
    
format(querysizeof(query), "INSERT INTO vehicles (VehicleID, VehicleModel, VehiclePosx, VehiclePosy, VehiclePosz, VehiclePosa, VehicleColor1, VehicleColor2) VALUES('%d', '%d', '%f', '%f', '%f', '%f', '%d', '%d'"ivModelTposxposyposzposavColor1TvColor2T);
    
mysql_query(query);
    
Vehicle[i][vID] = i;
    
Vehicle[i][vModel] = vModelT;
    
Vehicle[i][vPosition][0] = posx;
    
Vehicle[i][vPosition][1] = posy;
    
Vehicle[i][vPosition][2] = posz;
    
Vehicle[i][vPosition][3] = posa;
    
Vehicle[i][vColor1] = vColor1T;
    
Vehicle[i][vColor2] = vColor2T;
    
format(stringsizeof(string), "Vehicle Created! Vehicle ID : %d | Vehicle ModelID : %d | Vehicle Color1And2 : 5 | Vehicle PosX : %f | Vehicle PosY : %f | Vehicle PosZ : %f | Vehicle PosA : %f"ivModelTposxposyposzposa);
    
SendClientMessage(playeridCOLOR_GREYstring);
    return 
1;

I did create a table insise the database. When i type /createvehicle in game it will create it inside the db. But when i use it again it will repeat the same id over and over again and it doesnt create then. What am i doing wrong?

Typed from my iphone dident even bother fixing spelling mistakes haha

Thanks
Reply
#2

Did you enable auto increment?
Reply
#3

enum VehicleStats
{
vID,
vModel,
Float:vPosition[4],
vOwner[24],
vColor1,
vColor2,
}
new Vehicle[MAX_VEHICLES][VehicleStats];

COMMAND:createvehicle(playerid, params[])
{
new vModelT, i, Floatosx, Floatosy, Floatosz, Floatosa, vColor1T, vColor2T, query[228], string[128];
if(sscanf(params, "ddd[128]", vModelT, vColor1T, vColor2T)) return SendClientMessage(playerid, COLOR_GREY, "[Command] Usage: /createvehicle [ModelID] [Color1] [Color2]");
GetPlayerPos(playerid, posx, posy, posz);
GetPlayerFacingAngle(playerid, posa);
if(vModelT < 411 || vModelT > 611) return SendClientMessage(playerid, COLOR_GREY, "Model ID Must not be below 411 and not higher than 611");
i = mysql_insert_id();
format(query, sizeof(query), "INSERT INTO vehicles (VehicleID, VehicleModel, VehiclePosx, VehiclePosy, VehiclePosz, VehiclePosa, VehicleColor1, VehicleColor2) VALUES('%d', '%d', '%f', '%f', '%f', '%f', '%d', '%d'", i, vModelT, posx, posy, posz, posa, vColor1T, vColor2T);
mysql_query(query);
Vehicle[i][vID] = i;
Vehicle[i][vModel] = vModelT;
Vehicle[i][vPosition][0] = posx;
Vehicle[i][vPosition][1] = posy;
Vehicle[i][vPosition][2] = posz;
Vehicle[i][vPosition][3] = posa;
Vehicle[i][vColor1] = vColor1T;
Vehicle[i][vColor2] = vColor2T;
format(string, sizeof(string), "Vehicle Created! Vehicle ID : %d | Vehicle ModelID : %d | Vehicle Color1And2 : 5 | Vehicle PosX : %f | Vehicle PosY : %f | Vehicle PosZ : %f | Vehicle PosA : %f", i, vModelT, posx, posy, posz, posa);
SendClientMessage(playerid, COLOR_GREY, string);
return 1;
}
Reply
#4

Quote:
Originally Posted by Vince
Посмотреть сообщение
Did you enable auto increment?
Yes, I did.

Quote:
Originally Posted by HK
Посмотреть сообщение
enum VehicleStats
{
vID,
vModel,
Float:vPosition[4],
vOwner[24],
vColor1,
vColor2,
}
new Vehicle[MAX_VEHICLES][VehicleStats];

COMMAND:createvehicle(playerid, params[])
{
new vModelT, i, Floatosx, Floatosy, Floatosz, Floatosa, vColor1T, vColor2T, query[228], string[128];
if(sscanf(params, "ddd[128]", vModelT, vColor1T, vColor2T)) return SendClientMessage(playerid, COLOR_GREY, "[Command] Usage: /createvehicle [ModelID] [Color1] [Color2]");
GetPlayerPos(playerid, posx, posy, posz);
GetPlayerFacingAngle(playerid, posa);
if(vModelT < 411 || vModelT > 611) return SendClientMessage(playerid, COLOR_GREY, "Model ID Must not be below 411 and not higher than 611");
i = mysql_insert_id();
format(query, sizeof(query), "INSERT INTO vehicles (VehicleID, VehicleModel, VehiclePosx, VehiclePosy, VehiclePosz, VehiclePosa, VehicleColor1, VehicleColor2) VALUES('%d', '%d', '%f', '%f', '%f', '%f', '%d', '%d'", i, vModelT, posx, posy, posz, posa, vColor1T, vColor2T);
mysql_query(query);
Vehicle[i][vID] = i;
Vehicle[i][vModel] = vModelT;
Vehicle[i][vPosition][0] = posx;
Vehicle[i][vPosition][1] = posy;
Vehicle[i][vPosition][2] = posz;
Vehicle[i][vPosition][3] = posa;
Vehicle[i][vColor1] = vColor1T;
Vehicle[i][vColor2] = vColor2T;
format(string, sizeof(string), "Vehicle Created! Vehicle ID : %d | Vehicle ModelID : %d | Vehicle Color1And2 : 5 | Vehicle PosX : %f | Vehicle PosY : %f | Vehicle PosZ : %f | Vehicle PosA : %f", i, vModelT, posx, posy, posz, posa);
SendClientMessage(playerid, COLOR_GREY, string);
return 1;
}
I'll be trying that out right now! Thank you!
Reply
#5

Just tested it and it doesn't seem to work. Do I have to free the result?
Reply
#6

*Bump Soz *
Reply
#7

In the MySQL table, is VehicleID field set to AUTO_INCREMENT?
Reply
#8

Quote:
Originally Posted by Tayab
Посмотреть сообщение
In the MySQL table, is VehicleID field set to AUTO_INCREMENT?
Yes.
Reply
#9

EDIT: Woops double post
Reply
#10

Bumpy
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)