12.02.2011, 15:55
I have a problem that occurs when i try to make buyable car. I use some systems from this website. First i have simple vehicles (not ownership).
Another system is Ownership vehicles:
And the problem with those two systems is that vID dublicates for VehicleOwnerShip system. If i comment simple vehicle loading and leave just ownership system it works fine. But if i use them both, when i create vehicle i get same (ID:1). Anyone who can suggest a better id generating or something like that?
pawn Код:
stock AddVehiclesFromFile()
{
new
Str[67],
dModel,
Float:VX,
Float:VY,
Float:VZ,
Float:VA,
vTotal;
mysql_query("SELECT * FROM `vehicles`");
mysql_store_result();
if(mysql_num_rows() > 0)
{
while(mysql_fetch_row(Str))
{
sscanf(Str, "p<|>iffff", dModel, VX, VY, VZ, VA);
AddStaticVehicleEx(dModel, VX, VY, VZ, VA, -1, -1, (30 * 60));
vTotal++;
}
}
mysql_free_result();
printf("** %i\t<->\tVehicles Loaded From\t<->\tMySQL\t\t **", vTotal);
return 1;
}
pawn Код:
stock AddVehicleToFile(Float:VX, Float:VY, Float:VZ, Float:VA, dModel)
{
new
Query[200];
format(Query, sizeof(Query), "INSERT INTO `vehicles` (VehicleModel, VehicleX, VehicleY, VehicleZ, VehicleAngle) VALUES(%d, %f, %f, %f, %f)",
dModel, VX, VY, VZ, VA);
mysql_query(Query);
mysql_free_result();
return 1;
}
pawn Код:
CMD:vcreate(playerid, params[])
{
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "You must be admin to use this command!");
new
Float:Pos[4],
ivModel,
ivPrice,
ivColors[2],
Query[256],
iMsg[128];
if(sscanf(params, "iiii", ivModel, ivPrice, ivColors[0], ivColors[1])) return SendClientMessage(playerid, -1, ""#CRED"Usage: "#CORANGE"/VCreate < Vehicle Model > < Price > < Color 1 > < Color 2 >");
GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
GetPlayerFacingAngle(playerid, Pos[3]);
new
vID = GetNewVehID();
vInfo[vID][vModel] = ivModel;
vInfo[vID][vColor1] = ivColors[0];
vInfo[vID][vColor2] = ivColors[1];
vInfo[vID][vPrice] = ivPrice;
vInfo[vID][vPosX] = Pos[0];
vInfo[vID][vPosY] = Pos[1];
vInfo[vID][vPosZ] = Pos[2];
vInfo[vID][vPosA] = Pos[3];
strmid(vInfo[vID][vOwner], "Unbought", 0, 20, 20);
format(Query, sizeof(Query), "INSERT INTO `privateveh` (`vID`, `vModel`, `vColor1`, `vColor2`, `vPrice`, `vOwner`, `vPosX`, `vPosY`, `vPosZ`, `vPosA`) VALUES (%d, %d, %d, %d, %d, 'Unbought', %f, %f, %f, %f)",
vID,
ivModel,
ivColors[0],
ivColors[1],
ivPrice,
Pos[0],
Pos[1],
Pos[2],
Pos[3]);
mysql_query(Query);
new
cCar = CreateVehicle(ivModel, Pos[0], Pos[1], Pos[2], Pos[3], ivColors[0], ivColors[1], 500000);
ivCreated[cCar] = vID;
SavePrivVeh(vID);
format(iMsg, sizeof(iMsg), ""#CYELLOW"Vehicle: "#CBLUE"%i (VID: %i) "#CYELLOW"has been created. Price: "#CBLUE"$%i", ivModel, vID, ivPrice);
SendClientMessage(playerid, -1, iMsg);
return 1;
}
pawn Код:
stock LoadPVehicles()
{
new
Query[512],
vModel2,
vC[2],
vPrice2,
vOwner2[MAX_PLAYER_NAME],
Float:Pos[4],
vID;
mysql_query("SELECT * FROM `privateveh` WHERE `vID` < "#MAX_BUYABLE_VEH);
mysql_store_result();
if(mysql_num_rows() > 0)
{
while(mysql_fetch_row(Query))
{
print("\n====================\n");
sscanf(Query, "p<|>iiiiis[24]ffff", vID, vModel2, vC[0], vC[1], vPrice2, vOwner2, Pos[0], Pos[1], Pos[2], Pos[3]);
vInfo[vID][vModel] = vModel2;
printf("%i", vModel2);
vInfo[vID][vColor1] = vC[0];
printf("%i", vC[0]);
vInfo[vID][vColor2] = vC[1];
printf("%i", vC[1]);
vInfo[vID][vPrice] = vPrice2;
printf("%i", vPrice2);
strmid(vInfo[vID][vOwner], vOwner2, 0, 128, 128);
printf("%s", vOwner2);
vInfo[vID][vPosX] = Pos[0];
printf("%f", Pos[0]);
vInfo[vID][vPosY] = Pos[1];
printf("%f", Pos[1]);
vInfo[vID][vPosZ] = Pos[2];
printf("%f", Pos[2]);
vInfo[vID][vPosA] = Pos[3];
printf("%f", Pos[3]);
print("\n====================\n");
if(vInfo[vID][vModel] != 0)
{
new
vCarID = CreateVehicle(vModel2, Pos[0], Pos[1], Pos[2], Pos[3], vC[0], vC[1], 500000);
ivCreated[vCarID] = vID;
}
}
}
mysql_free_result();
return printf("%i vehicles loaded!", vID);
}
pawn Код:
stock GetNewVehID()
{
for(new i = 1; i < MAX_BUYABLE_VEH; i++)
{
if(!vInfo[ivCreated[i]][vPrice]) return i;
}
return 2000;
}