stock GetFreeVehicleSlot()
{
new VSlot;
for(new v = 0; v < MAX_VEHICLES; v ++)
{
VSlot = v;
if(VSlot != Vehicles[v][CarFileID])
{
return VSlot;
}
}
return VSlot;
}
public SaveVehicleCallback(vehicleid, playerid)
{
new
rows,
fields;
cache_get_data(rows, fields);
if(rows == 1)
{
//SendClientMessage(SavingVehiclePlayerID, WARNRED, "This Vehicle already exists");
SendClientMessage(playerid, WARNRED, "This Vehicle already exists");
}
else if(rows == 0)
{
new query[2000];
format(query, sizeof(query), "INSERT INTO `Vehicles` (`CarFileID`, `ModelID`, `VehicleID`,`VOwner`, `VPlate`, `VehicleWorld`, `VehicleInteriorID`) VALUES ");
format(query, sizeof(query), "%s(%d, %d, %d, '%s', '%s', %d, %d)",
query,
GetFreeVehicleSlot(),
Vehicles[vehicleid][ModelID],
vehicleid,
Vehicles[vehicleid][VOwner],
Vehicles[vehicleid][VPlate],
Vehicles[vehicleid][VehicleWorld],
Vehicles[vehicleid][VehicleInteriorID]);
mysql_function_query(g_connectionHandle, query, false, "DefaultCallback", "");
format(query, sizeof(query), "UPDATE `Vehicles` SET `Color1`= %d, `Color2` = %d, `VPosX` = '%f', `VPosY` = '%f', `VPosZ` = '%f', `VPosAngle` = '%f', `FactionCar` = %d WHERE VehicleID = %d",
Vehicles[vehicleid][Color1],
Vehicles[vehicleid][Color2],
Vehicles[vehicleid][VPosX],
Vehicles[vehicleid][VPosY],
Vehicles[vehicleid][VPosZ],
Vehicles[vehicleid][VPosAngle],
Vehicles[vehicleid][FactionCar],
vehicleid);
mysql_function_query(g_connectionHandle, query, false, "DefaultCallback", "");
DestroyVehicle(vehicleid);
SpawnedVehicles--;
new query2[400];
format(query2, sizeof(query2), "SELECT * FROM `Vehicles` WHERE `VehicleID` = %d", vehicleid); // Selects all the information from the table
mysql_function_query(g_connectionHandle, query2, true, "LoadVehiclesCallback", "d", vehicleid);
SendClientMessage(playerid, GREEN, "Vehicle Saved!");
//SendClientMessage(SavingVehiclePlayerID, GREEN, "Vehicle Saved!");
//SavingVehiclePlayerID = -1;
}
else
{
//SendClientMessage(SavingVehiclePlayerID, COLOR_WHITE, "There was a "#COL_EMB_RED"fatal error "#COL_EMB_WHITE"during registration! Please contact a developer.");
SendClientMessage(playerid, COLOR_WHITE, "There was a "#COL_EMB_RED"fatal error "#COL_EMB_WHITE"during registration! Please contact a developer.");
}
return 1;
}
public LoadVehiclesCallback(vehicleid)
{
new
rows,
fields;
cache_get_data(rows, fields);
if(rows == 1)
{
new temp[50];
cache_get_row(0, 0, temp); // #0 = #1 in the DB
Vehicles[vehicleid][CarFileID] = strval(temp);
cache_get_row(0, 2, temp);
Vehicles[vehicleid][ModelID] = strval(temp);
cache_get_row(0, 3, temp);
Vehicles[vehicleid][Color1] = strval(temp);
cache_get_row(0, 4, temp);
Vehicles[vehicleid][Color2] = strval(temp);
cache_get_row(0, 5, temp);
Vehicles[vehicleid][VPosX] = floatstr(temp);
cache_get_row(0, 6, temp);
Vehicles[vehicleid][VPosY] = floatstr(temp);
cache_get_row(0, 7, temp);
Vehicles[vehicleid][VPosZ] = floatstr(temp);
cache_get_row(0, 8, temp);
Vehicles[vehicleid][VPosAngle] = floatstr(temp);
cache_get_row(0, 9, temp);
Vehicles[vehicleid][LockStatus] = strval(temp);
cache_get_row(0, 10, temp);
Vehicles[vehicleid][FactionCar] = strval(temp);
cache_get_row(0, 11, Vehicles[vehicleid][VOwner]);
cache_get_row(0, 12, Vehicles[vehicleid][VPlate]);
cache_get_row(0, 13, temp);
Vehicles[vehicleid][VehicleWorld] = strval(temp);
cache_get_row(0, 14, temp);
Vehicles[vehicleid][VehicleInteriorID] = strval(temp);
cache_get_row(0, 15, temp);
Vehicles[vehicleid][SpeedoColor] = strval(temp);
cache_get_row(0, 16, temp);
Vehicles[vehicleid][Impounded] = strval(temp);
cache_get_row(0, 17, temp);
Vehicles[vehicleid][FlashAble] = strval(temp);
if(Vehicles[vehicleid][Impounded] == 1)
{
if(VehicleJustImpounded[vehicleid] == 1)
{
ImpoundCount++;
if(ImpoundCount >= 48)
{
ImpoundCount = 0;
}
//new rand = random(sizeof(RandomImpoundSpawn));
//Vehicles[vehicleid][VehicleID] = AddStaticVehicleEx(Vehicles[vehicleid][ModelID], RandomImpoundSpawn[rand][0], RandomImpoundSpawn[rand][1], RandomImpoundSpawn[rand][2], RandomImpoundSpawn[rand][3], Vehicles[vehicleid][Color1], Vehicles[vehicleid][Color2], -1);
Vehicles[vehicleid][VehicleID] = AddStaticVehicleEx(Vehicles[vehicleid][ModelID], RandomImpoundSpawn[ImpoundCount][0], RandomImpoundSpawn[ImpoundCount][1], RandomImpoundSpawn[ImpoundCount][2], RandomImpoundSpawn[ImpoundCount][3], Vehicles[vehicleid][Color1], Vehicles[vehicleid][Color2], -1);
SetVehicleVirtualWorld(Vehicles[vehicleid][VehicleID], 0);//set vw
LinkVehicleToInterior(Vehicles[vehicleid][VehicleID], 0);//set int
SetVehicleNumberPlate(Vehicles[vehicleid][VehicleID], Vehicles[vehicleid][VPlate]);
Vehicles[vehicleid][Fuel] = 100;
Vehicles[vehicleid][Battery] = 100;
VehicleJustImpounded[vehicleid] = 0;
}
else
{
new rand = random(sizeof(RandomImpoundSpawn));
Vehicles[vehicleid][VehicleID] = AddStaticVehicleEx(Vehicles[vehicleid][ModelID], RandomImpoundSpawn[rand][0], RandomImpoundSpawn[rand][1], RandomImpoundSpawn[rand][2], RandomImpoundSpawn[rand][3], Vehicles[vehicleid][Color1], Vehicles[vehicleid][Color2], -1);
SetVehicleVirtualWorld(Vehicles[vehicleid][VehicleID], Vehicles[vehicleid][VehicleID]+1);//set vw
LinkVehicleToInterior(Vehicles[vehicleid][VehicleID], Vehicles[vehicleid][VehicleInteriorID]);//set int
SetVehicleNumberPlate(Vehicles[vehicleid][VehicleID], Vehicles[vehicleid][VPlate]);
Vehicles[vehicleid][Fuel] = 100;
Vehicles[vehicleid][Battery] = 100;
}
}
else
{
Vehicles[vehicleid][VehicleID] = AddStaticVehicleEx(Vehicles[vehicleid][ModelID], Vehicles[vehicleid][VPosX], Vehicles[vehicleid][VPosY], Vehicles[vehicleid][VPosZ], Vehicles[vehicleid][VPosAngle], Vehicles[vehicleid][Color1], Vehicles[vehicleid][Color2], -1);
SetVehicleVirtualWorld(Vehicles[vehicleid][VehicleID], Vehicles[vehicleid][VehicleWorld]);//set vw
LinkVehicleToInterior(Vehicles[vehicleid][VehicleID], Vehicles[vehicleid][VehicleInteriorID]);//set int
SetVehicleNumberPlate(Vehicles[vehicleid][VehicleID], Vehicles[vehicleid][VPlate]);
Vehicles[vehicleid][Fuel] = 100;
Vehicles[vehicleid][Battery] = 100;
}
Vehicles[Vehicles[vehicleid][VehicleID]][SavedCar] = 1;
new query[500];
format(query, sizeof(query), "UPDATE `Vehicles` SET `VehicleID` = %d WHERE `CarFileID` = %d", Vehicles[vehicleid][VehicleID], Vehicles[vehicleid][CarFileID]);
mysql_function_query(g_connectionHandle, query, false, "DefaultCallback", "");
printf("[System] Vehicle %d has been succesfully spawned!", vehicleid);
SpawnedVehicles++;
}
return 1;
}
Alright, for your first problem, please restate the issue, the way you explained it is rather confusing to me (at this hour of the day). For your second problem, you could simply add +1 onto your function, could you not? Seeing if it's returning the last saved ID adding one would give you the last used, perhaps?
|
Well, just put "return VSlot + 1;" at the end of the function. It'll return a value for 1 bigger than it normally would, which should fix the issue.
|
Well, just put "return VSlot + 1;" at the end of the function. It'll return a value for 1 bigger than it normally would, which should fix the issue.
|
stock GetFreeVehicleSlot()
{
new VSlot;
for(new v = 0; v < MAX_VEHICLES; v ++)
{
VSlot = v;
if(VSlot != Vehicles[v][CarFileID])
{
return VSlot;
}
}
return VSlot+1;
}
stock GetFreeVehicleSlot()
{
new string[40];
for(new i = 0; i < MAX_VEHICLES; i++)
{
format(string, sizeof(string), "Vehicles/Vehicle_%d.ini", i); //format the file
if(fexist(string)) continue; //If the file exists, go to the next file
return i; //If the file doesn't exist, then we have an available slot, and we return the number/value of 'i'
}
return -1; //return -1 or INVALID_VEHICLE_ID for no available files
}
This is what I had when I used Dini files, is there a way to do the same with Mysql?
pawn Код:
|
stock GetFreeVehicleSlot()
{
new query[200];
for(new v = 0; v < MAX_VEHICLES; v ++)
{
format(query, sizeof(query), "SELECT * FROM `Vehicles` WHERE CarFileID = %d");
mysql_function_query(g_connectionHandle, query, false, "DefaultCallback", "");
mysql_store_result(g_connectionHandle);
if(mysql_num_rows(g_connectionHandle) > 0) continue;
return v;
}
return -1;
}