House and vehicle SQLite load -
Hessu - 26.10.2015
Hi
I got some issues with freeing results that i have struggeled with too long. Hopefully you see the problem.
pawn Код:
// This function will load the house's datafile (used when the server is started to load all houses)
HouseFile_Load(HouseID)
{
print("Load house was called");
// Setup local variables
new Query[64], ParameterValue[50], DB:Database, DBResult:result, DBResult:result2;
new cModel, cPass[24], cPaint, components[14], Float:cx, Float:cy, Float:cz, Float:crot, CIns, Col1, Col2, bool:VehicleClamped, bool:VehicleHasPass, cFuel = -1, cHeal = -1;
Database = db_open("DataHouses.db");
format(Query, sizeof(Query), "SELECT * FROM `Houses` WHERE `HouseID` = '%d'", HouseID);
result = db_query(Database, Query);
// A House witht his ID was found < sort of loop inside database
if(db_num_rows(result))
{
print("House found!");
print("Only loading house");
// Save the player data from database to player enum
db_get_field_assoc(result, "HouseAddress", ParameterValue, 50);
format(AHouseData[HouseID][HouseAddress], 50, ParameterValue); // Store the HouseAddress
db_get_field_assoc(result, "HouseName", ParameterValue, 50);
format(AHouseData[HouseID][HouseName], 50, ParameterValue); // Store the HouseName
db_get_field_assoc(result, "HouseX", ParameterValue, 50);
AHouseData[HouseID][HouseX] = floatstr(ParameterValue); // Store the HouseX
db_get_field_assoc(result, "HouseY", ParameterValue, 50);
AHouseData[HouseID][HouseY] = floatstr(ParameterValue); // Store the HouseY
db_get_field_assoc(result, "HouseZ", ParameterValue, 50);
AHouseData[HouseID][HouseZ] = floatstr(ParameterValue); // Store the HouseZ
db_get_field_assoc(result, "HouseInterior", ParameterValue, 50);
AHouseData[HouseID][HouseInterior] = strval(ParameterValue); // Store the HouseInterior
db_get_field_assoc(result, "HouseMaxSlots", ParameterValue, 50);
AHouseData[HouseID][HouseMaxSlots] = strval(ParameterValue); // Store the HouseMaxSlots
db_get_field_assoc(result, "HouseNewMaxSlots", ParameterValue, 50);
AHouseData[HouseID][HouseNewMaxSlots] = strval(ParameterValue); // Store the HouseNewMaxSlots
db_get_field_assoc(result, "HousePrice", ParameterValue, 50);
AHouseData[HouseID][HousePrice] = strval(ParameterValue); // Store the HousePrice
db_get_field_assoc(result, "Owned", ParameterValue, 50);
if (strcmp(ParameterValue, "1", false) == 0) // If the value "Yes" was read
{
AHouseData[HouseID][Owned] = true; // House is owned
print("House set to owned");
}
else
{
AHouseData[HouseID][Owned] = false; // House is not owned
print("House set to not owned");
}
db_get_field_assoc(result, "HouseOpened", ParameterValue, 50);
if (strcmp(ParameterValue, "1", false) == 0) // If the value "Yes" was read
{
AHouseData[HouseID][HouseOpened] = true; // House is open
}
else
{
AHouseData[HouseID][HouseOpened] = false; // House is closed
}
db_get_field_assoc(result, "PlayerIsTycoon", ParameterValue, 50);
if (strcmp(ParameterValue, "1", false) == 0) // If the value "Yes" was read
{
AHouseData[HouseID][PlayerIsTycoon] = true; // House owner is tycoon
}
else
{
AHouseData[HouseID][PlayerIsTycoon] = false; // House owner is not tycoon
}
db_get_field_assoc(result, "Owner", ParameterValue, 50);
format(AHouseData[HouseID][Owner], 24, ParameterValue);
new string[128];
format(string, sizeof(string), "The house owner of HouseID: %d is : %s", HouseID, AHouseData[HouseID][Owner]);
print(string);
db_get_field_assoc(result, "Insurance", ParameterValue, 50);
AHouseData[HouseID][Insurance] = strval(ParameterValue); // Store the Insurance
}
db_free_result(result);
for (new vehicleid; vehicleid < 50; vehicleid++)
{
format(Query, sizeof(Query), "SELECT * FROM `Vehicle` WHERE `HouseID` = '%d'", HouseID);
result2 = db_query(Database, Query);
if(db_num_rows(result2))
{
AVehicleData[vehicleid][BelongsToHouse] = HouseID;
//Setup local variables
new cPanels = 0, cDoors = 0, cLights = 0, cTires = 0;
// Clear all data to start a new vehicle
cModel = 0;
cPaint = 0;
cFuel = -1;
cFuel = -1;
for (new i; i < 14; i++)
{
components[i] = 0;
}
db_get_field_assoc(result2, "Pass", ParameterValue, 50);
format(cPass, 24, ParameterValue); // Store the password
db_get_field_assoc(result2, "Model", ParameterValue, 50);
cModel = strval(ParameterValue); // Store the VehicleModel
db_get_field_assoc(result2, "Fuel", ParameterValue, 50);
cFuel = strval(ParameterValue); // Store the Fuel
db_get_field_assoc(result2, "Heal", ParameterValue, 50);
cHeal = strval(ParameterValue); // Store the Heal
db_get_field_assoc(result2, "PaintJob", ParameterValue, 50);
cPaint = strval(ParameterValue); // Store the VehiclePaintJob
db_get_field_assoc(result2, "Component0", ParameterValue, 50);
components[0] = strval(ParameterValue); // Store the VehicleSpoiler
db_get_field_assoc(result2, "Component1", ParameterValue, 50);
components[1] = strval(ParameterValue); // Store the VehicleRoof
db_get_field_assoc(result2, "Component2", ParameterValue, 50);
components[2] = strval(ParameterValue); // Store the VehicleSideSkirt
db_get_field_assoc(result2, "Component3", ParameterValue, 50);
components[3] = strval(ParameterValue); // Store the VehicleLamps
db_get_field_assoc(result2, "Component4", ParameterValue, 50);
components[4] = strval(ParameterValue); // Store the VehicleNitro
db_get_field_assoc(result2, "Component5", ParameterValue, 50);
components[5] = strval(ParameterValue); // Store the VehicleExhaust
db_get_field_assoc(result2, "Component6", ParameterValue, 50);
components[6] = strval(ParameterValue); // Store the VehicleWheels
db_get_field_assoc(result2, "Component7", ParameterValue, 50);
components[7] = strval(ParameterValue); // Store the VehicleStereo
db_get_field_assoc(result2, "Component8", ParameterValue, 50);
components[8] = strval(ParameterValue); // Store the VehicleHydraulics
db_get_field_assoc(result2, "Component9", ParameterValue, 50);
components[9] = strval(ParameterValue); // Store the VehicleFrontBumper
db_get_field_assoc(result2, "Component10", ParameterValue, 50);
components[10] = strval(ParameterValue); // Store the VehicleRearBumper
db_get_field_assoc(result2, "Component11", ParameterValue, 50);
components[11] = strval(ParameterValue); // Store the VehicleVentRight
db_get_field_assoc(result2, "Component12", ParameterValue, 50);
components[12] = strval(ParameterValue); // Store the VehicleVentLeft
db_get_field_assoc(result2, "Component13", ParameterValue, 50);
components[13] = strval(ParameterValue); // Store the VehicleSpoiler
db_get_field_assoc(result2, "Color1", ParameterValue, 50);
Col1 = strval(ParameterValue); // Store the Color1
db_get_field_assoc(result2, "Color2", ParameterValue, 50);
Col2 = strval(ParameterValue); // Store the Color2
db_get_field_assoc(result2, "SpawnX", ParameterValue, 50);
cx = floatstr(ParameterValue); // Store the VehicleX
db_get_field_assoc(result2, "SpawnY", ParameterValue, 50);
cy = floatstr(ParameterValue); // Store the VehicleY
db_get_field_assoc(result2, "SpawnZ", ParameterValue, 50);
cz = floatstr(ParameterValue); // Store the VehicleZ
db_get_field_assoc(result2, "SpawnRot", ParameterValue, 50);
crot = floatstr(ParameterValue); // Store the VehicleAngle
db_get_field_assoc(result2, "RemainingInsurance", ParameterValue, 50);
CIns = strval(ParameterValue); // Store the Remaining Insurance
db_get_field_assoc(result2, "PanelPanels", ParameterValue, 50);
cPanels = strval(ParameterValue); // Store the Heal
db_get_field_assoc(result2, "PanelDoors", ParameterValue, 50);
cDoors = strval(ParameterValue); // Store the Heal
db_get_field_assoc(result2, "PanelLights", ParameterValue, 50);
cLights = strval(ParameterValue); // Store the Heal
db_get_field_assoc(result2, "PanelTires", ParameterValue, 50);
cTires = strval(ParameterValue); // Store the Heal
db_get_field_assoc(result2, "Clamped", ParameterValue, 50);
if (strcmp(ParameterValue, "1", false) == 0) // If the value "Yes" was read
{
VehicleClamped = true; // Vehicle is clamped
}
else
{
VehicleClamped = false; // Vehicle is not clamped
}
db_get_field_assoc(result2, "HasPass", ParameterValue, 50);
if (strcmp(ParameterValue, "1", false) == 0) // If the value "Yes" was read
{
VehicleHasPass = true; // Vehicle has password
}
else
{
VehicleHasPass = false; // Vehicle has not password
}
// Set both colors to 1 if they are 0 AND if there is a paintjob applied
if ((Col1 == 0) && (cPaint != 0))
{
Col1 = 1;
}
if ((Col2 == 0) && (cPaint != 0))
{
Col2 = 1;
}
// Now add the vehicle to the house and set it's data
vehicleid = House_AddVehicle(HouseID, cModel, cPaint, cPanels, cDoors, cLights, cTires, components, cx, cy, cz, crot, Col1, Col2);
AVehicleData[vehicleid][TPanels] = cPanels;
AVehicleData[vehicleid][TDoors] = cDoors;
AVehicleData[vehicleid][TLights] = cLights;
AVehicleData[vehicleid][TTires] = cTires;
AVehicleData[vehicleid][RemainingInsurance] = CIns;
AVehicleData[vehicleid][Clamped] = VehicleClamped;
AVehicleData[vehicleid][HasPass] = VehicleHasPass;
//Put the password to the vehicle
format(AVehicleData[vehicleid][Pass], 24, cPass); // Store the password
// Also set the fuel (set it to maximum when the fuel parameter wasn't inside the file)
if (cFuel == -1)
{
AVehicleData[vehicleid][Fuel] = MaxFuel;
}
else // If the parameter was there, store it
{
AVehicleData[vehicleid][Fuel] = cFuel;
}
// Also set the heal (set it to maximum when the fuel parameter wasn't inside the file)
if (cHeal == -1)
{
AVehicleData[vehicleid][Heal] = MaxVehHealth;
}
else // If the parameter was there, store it
{
AVehicleData[vehicleid][Heal] = cHeal;
}
SetVehicleToRespawn(vehicleid);
}
db_free_result(result2);
}
print("Load house database closed");
//Close the database
db_close(Database);
return 1;
}
This prints this into server console :
Код:
[07:11:56] Load house was called
[07:11:56] House found!
[07:11:56] Only loading house
[07:11:56] House set to not owned
[07:11:56] The house owner of HouseID: 1 is :
[07:11:56] Load house database closed
[07:11:56] Load house was called
[07:11:56] House found!
[07:11:56] Only loading house
[07:11:56] House set to not owned
[07:11:56] The house owner of HouseID: 2 is :
[07:11:56] Load house database closed
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[07:11:56] SQLitei Warning: (db_autofree_result) The autofree pool is full!
The problem goes when it runs the save (inside loop that goes to 50). If i comment it out, no warnings.
Thanks in advance!
Re: House and vehicle SQLite load -
Mencent - 26.10.2015
Hello!
You had send us the loading-part but we need the saving-part.
Can you send us this missing part?
Re: House and vehicle SQLite load -
Hessu - 26.10.2015
Well that prints into server console during load..
Here is the save part though.
pawn Код:
// This function will save the given house
HouseFile_Save(HouseID)
{
for(new i = 0; i <= MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
SendClientMessage(i, -1, "Save house was called");
}
}
//Open sqlite database
new DB:Database;
new Query[1000], HouseStrCat[800], DBResult:Result, DBResult:Result2;
Database = db_open("DataHouses.db");
format(Query, sizeof(Query), "CREATE TABLE IF NOT EXISTS `Houses` (`HouseID`, `HouseAddress`, `HouseName`, `HouseX`, `HouseY`, `HouseZ`, `HouseInterior`, `HouseMaxSlots`, `HouseNewMaxSlots`, `HousePrice`, `Owned`, `HouseOpened`, `PlayerIsTycoon`, `Owner`, `Insurance`)");
db_free_result(db_query(Database, Query));
strcat(HouseStrCat, "CREATE TABLE IF NOT EXISTS `Vehicle` (`HouseID`, `Pass`, `Model`, `Fuel`, `Heal`, `PaintJob`, `Component0`, `Component1`, `Component2`, `Component3`, `Component4`, `Component5`, `Component6`, `Component7`, `Component8`, `Component9`", sizeof(HouseStrCat));
strcat(HouseStrCat, " `Component10`, `Component11`, `Component12`, `Component13`, `Color1`, `Color2`, `SpawnX`, `SpawnY`, `SpawnZ`, `SpawnRot`, `RemainingInsurance`, `PanelPanels`, `PanelDoors`, `PanelLights`, `PanelTires`, `Clamped`, `HasPass`)", sizeof(HouseStrCat));
db_free_result(db_query(Database, HouseStrCat));
strdel(HouseStrCat, 0, 800);
format(Query, sizeof(Query), "SELECT * FROM `Houses` WHERE `HouseID` = '%d'", HouseID);
Result = db_query(Database, Query);
for(new i = 0; i <= MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
SendClientMessage(i, -1, "Searching the HouseID from the database..");
}
}
//No house with this ID was found in the database
if(!db_num_rows(Result))
{
for(new i = 0; i <= MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
SendClientMessage(i, -1, "No house with that house ID was found in database. Adding..");
}
}
strcat(HouseStrCat, "INSERT INTO `Houses` (`HouseID`, `HouseAddress`, `HouseName`, `HouseX`, `HouseY`, `HouseZ`, `HouseInterior`, `HouseMaxSlots`, `HouseNewMaxSlots`, `HousePrice`, `Owned`, `HouseOpened`, `PlayerIsTycoon`, `Owner`, `Insurance`) ", sizeof(HouseStrCat)); // 15
strcat(HouseStrCat, "VALUES('%d','%s','%s','%f','%f','%f','%d','%d','%d','%d','%d','%d','%d','%s','%d')", sizeof(HouseStrCat)); // 44
format(Query, sizeof(Query), HouseStrCat, HouseID, AHouseData[HouseID][HouseAddress], AHouseData[HouseID][HouseName], AHouseData[HouseID][HouseX], AHouseData[HouseID][HouseY], AHouseData[HouseID][HouseZ], AHouseData[HouseID][HouseInterior], AHouseData[HouseID][HouseMaxSlots], AHouseData[HouseID][HouseNewMaxSlots], AHouseData[HouseID][HousePrice], AHouseData[HouseID][Owned],
AHouseData[HouseID][HouseOpened], AHouseData[HouseID][PlayerIsTycoon], AHouseData[HouseID][Owner], AHouseData[HouseID][Insurance]);
db_free_result(db_query(Database, Query));
strdel(HouseStrCat, 0, 800);
for(new i = 0; i <= MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
SendClientMessage(i, -1, "Added!");
}
}
}
else if(db_num_rows(Result)) // The house ID is in the database. Update the values
{
db_free_result(Result);
for(new i = 0; i <= MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
SendClientMessage(i, -1, "The house was found in database! Updating..");
}
}
new string[256];
format(string, sizeof(string), "Failstep 1 : House owner : %s and house owned %d", AHouseData[HouseID][Owner], AHouseData[HouseID][Owned]);
print(string);
strcat(HouseStrCat, "UPDATE `Houses` SET `HouseAddress` = '%s', `HouseName` = '%s', `HouseX` = '%f', `HouseY` = '%f', `HouseZ` = '%f', `HouseInterior` = '%d', `HouseMaxSlots` = '%d', `HouseNewMaxSlots` = '%d', `HousePrice` = '%d', `Owned` = '%d', `HouseOpened` = '%d', ", sizeof(HouseStrCat)); // 11
strcat(HouseStrCat, "`PlayerIsTycoon` = '%d', `Owner` = '%s', `Insurance` = '%d' WHERE `HouseID` = '%d'", sizeof(HouseStrCat)); // 15
format(Query, sizeof(Query), HouseStrCat, AHouseData[HouseID][HouseAddress], AHouseData[HouseID][HouseName], AHouseData[HouseID][HouseX], AHouseData[HouseID][HouseY], AHouseData[HouseID][HouseZ], AHouseData[HouseID][HouseInterior], AHouseData[HouseID][HouseMaxSlots], AHouseData[HouseID][HouseNewMaxSlots], AHouseData[HouseID][HousePrice], AHouseData[HouseID][Owned],
AHouseData[HouseID][HouseOpened], AHouseData[HouseID][PlayerIsTycoon], AHouseData[HouseID][Owner], AHouseData[HouseID][Insurance], HouseID); // 15
db_free_result(db_query(Database, Query));
strdel(HouseStrCat, 0, 800);
format(Query, sizeof(Query), "SELECT * FROM `Houses` WHERE `HouseID` = '%d'", HouseID);
Result2 = db_query(Database, Query);
new ParameterValue[50], ParameterValue2[50];
db_get_field_assoc(Result2, "Owned", ParameterValue, 50);
db_get_field_assoc(Result2, "Owner", ParameterValue2, 50);
db_free_result(Result2);
format(string, sizeof(string), "Failstep 2 : House owner : %s and house owned %d", ParameterValue2, ParameterValue);
print(string);
// Save the vehicle-data for every vehicle added to the house
for (new CarSlot; CarSlot < 50; CarSlot++)
{
// If there is an vehicle in this slot
if (AHouseData[HouseID][VehicleIDs][CarSlot] != 0)
{
print("car found in carslot");
//Setup local variables
new vid, cPanels, cDoors, cLights, cTires;
// Get the vehicle id
vid = AHouseData[HouseID][VehicleIDs][CarSlot];
//AVehicleData[vid][BelongsToHouse] = HouseID;
GetVehicleDamageStatus(vid, cPanels, cDoors, cLights, cTires);
format(Query, sizeof(Query), "SELECT * FROM `Vehicle` WHERE `HouseID` = '%d'", HouseID);
Result = db_query(Database,Query);
//No vehicle with this ID was found in the database
if(!db_num_rows(Result))
{
for(new i = 0; i <= MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
SendClientMessage(i, -1, "Step 8");
}
}
strcat(HouseStrCat, "INSERT INTO `Vehicle` (`HouseID`, `Pass`, `Model`, `Fuel`, `Heal`, `PaintJob`, `Component0`, `Component1`, `Component2`, `Component3`, `Component4`, `Component5`, `Component6`, `Component7`, `Component8`, `Component9`", sizeof(HouseStrCat)); //16
strcat(HouseStrCat, " `Component10`, `Component11`, `Component12`, `Component13`, `Color1`, `Color2`, `SpawnX`, `SpawnY`, `SpawnZ`, `SpawnRot`, `RemainingInsurance`, `PanelPanels`, `PanelDoors`, `PanelLights`, `PanelTires`, `Clamped`, `HasPass`)", sizeof(HouseStrCat)); // 33
strcat(HouseStrCat, "VALUES('%d','%s','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%f','%f','%f','%f','%d','%d','%d','%d','%d','%d','%d')", sizeof(HouseStrCat)); // 33
format(Query, sizeof(Query), HouseStrCat, HouseID, AVehicleData[vid][Pass], AVehicleData[vid][Model], AVehicleData[vid][Fuel], AVehicleData[vid][Heal], AVehicleData[vid][PaintJob], AVehicleData[vid][Components][0], AVehicleData[vid][Components][1], AVehicleData[vid][Components][2], AVehicleData[vid][Components][3], AVehicleData[vid][Components][4],
AVehicleData[vid][Components][5], AVehicleData[vid][Components][6], AVehicleData[vid][Components][7], AVehicleData[vid][Components][8], AVehicleData[vid][Components][9], AVehicleData[vid][Components][10], AVehicleData[vid][Components][11], AVehicleData[vid][Components][12], AVehicleData[vid][Components][13], AVehicleData[vid][Color1],
AVehicleData[vid][Color2], AVehicleData[vid][SpawnX], AVehicleData[vid][SpawnY], AVehicleData[vid][SpawnZ], AVehicleData[vid][SpawnRot], AVehicleData[vid][RemainingInsurance], cPanels, cDoors, cLights, cTires, AVehicleData[vid][Clamped], AVehicleData[vid][HasPass]);
db_free_result(db_query(Database, Query));
strdel(HouseStrCat, 0, 800);
}
else if(db_num_rows(Result)) // The vehicle ID is in the database. Update the values
{
for(new i = 0; i <= MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
SendClientMessage(i, -1, "Step 9");
}
}
strcat(HouseStrCat, "UPDATE `Vehicle` SET `Pass` = '%s', `Model` = '%d', `Fuel` = '%d', `Heal` = '%d', `PaintJob` = '%d', `Component0` = '%d', `Component1` = '%d', `Component2` = '%d', `Component3` = '%d', `Component4` = '%d', `Component5` = '%d', `Component6` = '%d', ", sizeof(HouseStrCat));
strcat(HouseStrCat, "`Component7` = '%d', `Component8` = '%d', `Component9` = '%d', `Component10` = '%d', `Component11` = '%d', `Component12` = '%d', `Component13` = '%d', `Color1` = '%d', `Color2` = '%d', `SpawnX` = '%f', `SpawnY` = '%f', ", sizeof(HouseStrCat));
strcat(HouseStrCat, "`SpawnZ` = '%f', `SpawnRot` = '%f', `RemainingInsurance` = '%d', `PanelPanels` = '%d', `PanelDoors` = '%d', `PanelLights` = '%d', `PanelTires` = '%d', `Clamped` = '%d', `HasPass` = '%d' WHERE `HouseID` = '%d'", sizeof(HouseStrCat));
format(Query, sizeof(Query), HouseStrCat, AVehicleData[vid][Pass], AVehicleData[vid][Model], AVehicleData[vid][Fuel], AVehicleData[vid][Heal], AVehicleData[vid][PaintJob], AVehicleData[vid][Components][0], AVehicleData[vid][Components][1], AVehicleData[vid][Components][2], AVehicleData[vid][Components][3], AVehicleData[vid][Components][4],
AVehicleData[vid][Components][5], AVehicleData[vid][Components][6], AVehicleData[vid][Components][7], AVehicleData[vid][Components][8], AVehicleData[vid][Components][9], AVehicleData[vid][Components][10], AVehicleData[vid][Components][11], AVehicleData[vid][Components][12], AVehicleData[vid][Components][13], AVehicleData[vid][Color1],
AVehicleData[vid][Color2], AVehicleData[vid][SpawnX], AVehicleData[vid][SpawnY], AVehicleData[vid][SpawnZ], AVehicleData[vid][SpawnRot], AVehicleData[vid][RemainingInsurance], cPanels, cDoors, cLights, cTires, AVehicleData[vid][Clamped], AVehicleData[vid][HasPass], HouseID);
db_free_result(db_query(Database, Query));
strdel(HouseStrCat, 0, 800);
}
db_free_result(Result);
}
}
for(new i = 0; i <= MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
SendClientMessage(i, -1, "Updated!");
}
}
}
db_free_result(Result);
//Close the database
db_close(Database);
for(new i = 0; i <= MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
SendClientMessage(i, -1, "Databse closed!");
}
}
return 1;
}
When the save is run 2 times it freezes the server somehow, so there is problems there too.
Re: House and vehicle SQLite load -
Hessu - 27.10.2015
Updated the code. I saw there was a major bug (vhere vehicles would not have saved)
pawn Код:
// This function will save the given house
HouseFile_Save(HouseID)
{
for(new i = 0; i <= MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
SendClientMessage(i, -1, "Save house was called");
}
}
//Open sqlite database
new DB:Database;
new Query[1000], HouseStrCat[800], DBResult:Result, DBResult:Result2;
Database = db_open("DataHouses.db");
format(Query, sizeof(Query), "CREATE TABLE IF NOT EXISTS `Houses` (`HouseID`, `HouseAddress`, `HouseName`, `HouseX`, `HouseY`, `HouseZ`, `HouseInterior`, `HouseMaxSlots`, `HouseNewMaxSlots`, `HousePrice`, `Owned`, `HouseOpened`, `PlayerIsTycoon`, `Owner`, `Insurance`)");
db_free_result(db_query(Database, Query));
strcat(HouseStrCat, "CREATE TABLE IF NOT EXISTS `Vehicle` (`HouseID`, `Pass`, `Model`, `Fuel`, `Heal`, `PaintJob`, `Component0`, `Component1`, `Component2`, `Component3`, `Component4`, `Component5`, `Component6`, `Component7`, `Component8`, `Component9`", sizeof(HouseStrCat));
strcat(HouseStrCat, " `Component10`, `Component11`, `Component12`, `Component13`, `Color1`, `Color2`, `SpawnX`, `SpawnY`, `SpawnZ`, `SpawnRot`, `RemainingInsurance`, `PanelPanels`, `PanelDoors`, `PanelLights`, `PanelTires`, `Clamped`, `HasPass`, `CarSlot`)", sizeof(HouseStrCat));
db_free_result(db_query(Database, HouseStrCat));
strdel(HouseStrCat, 0, 800);
format(Query, sizeof(Query), "SELECT * FROM `Houses` WHERE `HouseID` = '%d'", HouseID);
Result = db_query(Database, Query);
for(new i = 0; i <= MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
SendClientMessage(i, -1, "Searching the HouseID from the database..");
}
}
//No house with this ID was found in the database
if(!db_num_rows(Result))
{
for(new i = 0; i <= MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
SendClientMessage(i, -1, "No house with that house ID was found in database. Adding..");
}
}
strcat(HouseStrCat, "INSERT INTO `Houses` (`HouseID`, `HouseAddress`, `HouseName`, `HouseX`, `HouseY`, `HouseZ`, `HouseInterior`, `HouseMaxSlots`, `HouseNewMaxSlots`, `HousePrice`, `Owned`, `HouseOpened`, `PlayerIsTycoon`, `Owner`, `Insurance`) ", sizeof(HouseStrCat)); // 15
strcat(HouseStrCat, "VALUES('%d','%s','%s','%f','%f','%f','%d','%d','%d','%d','%d','%d','%d','%s','%d')", sizeof(HouseStrCat)); // 44
format(Query, sizeof(Query), HouseStrCat, HouseID, AHouseData[HouseID][HouseAddress], AHouseData[HouseID][HouseName], AHouseData[HouseID][HouseX], AHouseData[HouseID][HouseY], AHouseData[HouseID][HouseZ], AHouseData[HouseID][HouseInterior], AHouseData[HouseID][HouseMaxSlots], AHouseData[HouseID][HouseNewMaxSlots], AHouseData[HouseID][HousePrice], AHouseData[HouseID][Owned],
AHouseData[HouseID][HouseOpened], AHouseData[HouseID][PlayerIsTycoon], AHouseData[HouseID][Owner], AHouseData[HouseID][Insurance]);
db_free_result(db_query(Database, Query));
strdel(HouseStrCat, 0, 800);
for(new i = 0; i <= MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
SendClientMessage(i, -1, "Added!");
}
}
}
else if(db_num_rows(Result)) // The house ID is in the database. Update the values
{
db_free_result(Result);
for(new i = 0; i <= MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
SendClientMessage(i, -1, "The house was found in database! Updating..");
}
}
new string[256];
format(string, sizeof(string), "Failstep 1 : House owner : %s and house owned %d", AHouseData[HouseID][Owner], AHouseData[HouseID][Owned]);
print(string);
strcat(HouseStrCat, "UPDATE `Houses` SET `HouseAddress` = '%s', `HouseName` = '%s', `HouseX` = '%f', `HouseY` = '%f', `HouseZ` = '%f', `HouseInterior` = '%d', `HouseMaxSlots` = '%d', `HouseNewMaxSlots` = '%d', `HousePrice` = '%d', `Owned` = '%d', `HouseOpened` = '%d', ", sizeof(HouseStrCat)); // 11
strcat(HouseStrCat, "`PlayerIsTycoon` = '%d', `Owner` = '%s', `Insurance` = '%d' WHERE `HouseID` = '%d'", sizeof(HouseStrCat)); // 15
format(Query, sizeof(Query), HouseStrCat, AHouseData[HouseID][HouseAddress], AHouseData[HouseID][HouseName], AHouseData[HouseID][HouseX], AHouseData[HouseID][HouseY], AHouseData[HouseID][HouseZ], AHouseData[HouseID][HouseInterior], AHouseData[HouseID][HouseMaxSlots], AHouseData[HouseID][HouseNewMaxSlots], AHouseData[HouseID][HousePrice], AHouseData[HouseID][Owned],
AHouseData[HouseID][HouseOpened], AHouseData[HouseID][PlayerIsTycoon], AHouseData[HouseID][Owner], AHouseData[HouseID][Insurance], HouseID); // 15
db_free_result(db_query(Database, Query));
strdel(HouseStrCat, 0, 800);
format(Query, sizeof(Query), "SELECT * FROM `Houses` WHERE `HouseID` = '%d'", HouseID);
Result2 = db_query(Database, Query);
new ParameterValue[50], ParameterValue2[50];
db_get_field_assoc(Result2, "Owned", ParameterValue, 50);
db_get_field_assoc(Result2, "Owner", ParameterValue2, 50);
db_free_result(Result2);
format(string, sizeof(string), "Failstep 2 : House owner : %s and house owned %d", ParameterValue2, ParameterValue);
print(string);
// Save the vehicle-data for every vehicle added to the house
for (new CarSlot = 0; CarSlot < 50; CarSlot++)
{
// If there is an vehicle in this slot
if (AHouseData[HouseID][VehicleIDs][CarSlot] != 0)
{
printf("carslot = %d", CarSlot);
print("car found in carslot");
//Setup local variables
new vid, cPanels, cDoors, cLights, cTires;
// Get the vehicle id
vid = AHouseData[HouseID][VehicleIDs][CarSlot];
//AVehicleData[vid][BelongsToHouse] = HouseID;
GetVehicleDamageStatus(vid, cPanels, cDoors, cLights, cTires);
format(Query, sizeof(Query), "SELECT * FROM `Vehicle` WHERE `HouseID` = '%d' AND CarSlot = '%d'", HouseID, CarSlot);
Result = db_query(Database,Query);
//No vehicle with this ID was found in the database
if(!db_num_rows(Result))
{
for(new i = 0; i <= MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
SendClientMessage(i, -1, "Step 8");
}
}
strcat(HouseStrCat, "INSERT INTO `Vehicle` (`HouseID`, `Pass`, `Model`, `Fuel`, `Heal`, `PaintJob`, `Component0`, `Component1`, `Component2`, `Component3`, `Component4`, `Component5`, `Component6`, `Component7`, `Component8`, `Component9`", sizeof(HouseStrCat)); //16
strcat(HouseStrCat, " `Component10`, `Component11`, `Component12`, `Component13`, `Color1`, `Color2`, `SpawnX`, `SpawnY`, `SpawnZ`, `SpawnRot`, `RemainingInsurance`, `PanelPanels`, `PanelDoors`, `PanelLights`, `PanelTires`, `Clamped`, `HasPass`, `CarSlot`)", sizeof(HouseStrCat)); // 33
strcat(HouseStrCat, "VALUES('%d','%s','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%f','%f','%f','%f','%d','%d','%d','%d','%d','%d','%d','%d')", sizeof(HouseStrCat)); // 33
format(Query, sizeof(Query), HouseStrCat, HouseID, AVehicleData[vid][Pass], AVehicleData[vid][Model], AVehicleData[vid][Fuel], AVehicleData[vid][Heal], AVehicleData[vid][PaintJob], AVehicleData[vid][Components][0], AVehicleData[vid][Components][1], AVehicleData[vid][Components][2], AVehicleData[vid][Components][3], AVehicleData[vid][Components][4],
AVehicleData[vid][Components][5], AVehicleData[vid][Components][6], AVehicleData[vid][Components][7], AVehicleData[vid][Components][8], AVehicleData[vid][Components][9], AVehicleData[vid][Components][10], AVehicleData[vid][Components][11], AVehicleData[vid][Components][12], AVehicleData[vid][Components][13], AVehicleData[vid][Color1],
AVehicleData[vid][Color2], AVehicleData[vid][SpawnX], AVehicleData[vid][SpawnY], AVehicleData[vid][SpawnZ], AVehicleData[vid][SpawnRot], AVehicleData[vid][RemainingInsurance], cPanels, cDoors, cLights, cTires, AVehicleData[vid][Clamped], AVehicleData[vid][HasPass], CarSlot);
db_free_result(db_query(Database, Query));
strdel(HouseStrCat, 0, 800);
}
else if(db_num_rows(Result)) // The vehicle ID is in the database. Update the values
{
for(new i = 0; i <= MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
SendClientMessage(i, -1, "Step 9");
}
}
strcat(HouseStrCat, "UPDATE `Vehicle` SET `Pass` = '%s', `Model` = '%d', `Fuel` = '%d', `Heal` = '%d', `PaintJob` = '%d', `Component0` = '%d', `Component1` = '%d', `Component2` = '%d', `Component3` = '%d', `Component4` = '%d', `Component5` = '%d', `Component6` = '%d', ", sizeof(HouseStrCat));
strcat(HouseStrCat, "`Component7` = '%d', `Component8` = '%d', `Component9` = '%d', `Component10` = '%d', `Component11` = '%d', `Component12` = '%d', `Component13` = '%d', `Color1` = '%d', `Color2` = '%d', `SpawnX` = '%f', `SpawnY` = '%f', ", sizeof(HouseStrCat));
strcat(HouseStrCat, "`SpawnZ` = '%f', `SpawnRot` = '%f', `RemainingInsurance` = '%d', `PanelPanels` = '%d', `PanelDoors` = '%d', `PanelLights` = '%d', `PanelTires` = '%d', `Clamped` = '%d', `HasPass` = '%d', `CarSlot` = '%d' WHERE `HouseID` = '%d' AND CarSlot = '%d'", sizeof(HouseStrCat));
format(Query, sizeof(Query), HouseStrCat, AVehicleData[vid][Pass], AVehicleData[vid][Model], AVehicleData[vid][Fuel], AVehicleData[vid][Heal], AVehicleData[vid][PaintJob], AVehicleData[vid][Components][0], AVehicleData[vid][Components][1], AVehicleData[vid][Components][2], AVehicleData[vid][Components][3], AVehicleData[vid][Components][4],
AVehicleData[vid][Components][5], AVehicleData[vid][Components][6], AVehicleData[vid][Components][7], AVehicleData[vid][Components][8], AVehicleData[vid][Components][9], AVehicleData[vid][Components][10], AVehicleData[vid][Components][11], AVehicleData[vid][Components][12], AVehicleData[vid][Components][13], AVehicleData[vid][Color1],
AVehicleData[vid][Color2], AVehicleData[vid][SpawnX], AVehicleData[vid][SpawnY], AVehicleData[vid][SpawnZ], AVehicleData[vid][SpawnRot], AVehicleData[vid][RemainingInsurance], cPanels, cDoors, cLights, cTires, AVehicleData[vid][Clamped], AVehicleData[vid][HasPass], CarSlot, HouseID, CarSlot);
db_free_result(db_query(Database, Query));
strdel(HouseStrCat, 0, 800);
}
db_free_result(Result);
}
}
for(new i = 0; i <= MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
SendClientMessage(i, -1, "Updated!");
}
}
}
db_free_result(Result);
//Close the database
db_close(Database);
for(new i = 0; i <= MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
SendClientMessage(i, -1, "Databse closed!");
}
}
return 1;
}
And the load part
pawn Код:
// This function will load the house's datafile (used when the server is started to load all houses)
HouseFile_Load(HouseID)
{
print("Load house was called");
// Setup local variables
new Query[64], ParameterValue[50], DB:Database, DBResult:result, DBResult:result2;
new cModel, cPass[24], cPaint, components[14], Float:cx, Float:cy, Float:cz, Float:crot, CIns, Col1, Col2, bool:VehicleClamped, bool:VehicleHasPass, cFuel = -1, cHeal = -1;
Database = db_open("DataHouses.db");
format(Query, sizeof(Query), "SELECT * FROM `Houses` WHERE `HouseID` = '%d'", HouseID);
result = db_query(Database, Query);
// A House witht his ID was found < sort of loop inside database
if(db_num_rows(result))
{
print("House found!");
print("Only loading house");
// Save the player data from database to player enum
db_get_field_assoc(result, "HouseAddress", ParameterValue, 50);
format(AHouseData[HouseID][HouseAddress], 50, ParameterValue); // Store the HouseAddress
db_get_field_assoc(result, "HouseName", ParameterValue, 50);
format(AHouseData[HouseID][HouseName], 50, ParameterValue); // Store the HouseName
db_get_field_assoc(result, "HouseX", ParameterValue, 50);
AHouseData[HouseID][HouseX] = floatstr(ParameterValue); // Store the HouseX
db_get_field_assoc(result, "HouseY", ParameterValue, 50);
AHouseData[HouseID][HouseY] = floatstr(ParameterValue); // Store the HouseY
db_get_field_assoc(result, "HouseZ", ParameterValue, 50);
AHouseData[HouseID][HouseZ] = floatstr(ParameterValue); // Store the HouseZ
db_get_field_assoc(result, "HouseInterior", ParameterValue, 50);
AHouseData[HouseID][HouseInterior] = strval(ParameterValue); // Store the HouseInterior
db_get_field_assoc(result, "HouseMaxSlots", ParameterValue, 50);
AHouseData[HouseID][HouseMaxSlots] = strval(ParameterValue); // Store the HouseMaxSlots
db_get_field_assoc(result, "HouseNewMaxSlots", ParameterValue, 50);
AHouseData[HouseID][HouseNewMaxSlots] = strval(ParameterValue); // Store the HouseNewMaxSlots
db_get_field_assoc(result, "HousePrice", ParameterValue, 50);
AHouseData[HouseID][HousePrice] = strval(ParameterValue); // Store the HousePrice
db_get_field_assoc(result, "Owned", ParameterValue, 50);
if (strcmp(ParameterValue, "1", false) == 0) // If the value "Yes" was read
{
AHouseData[HouseID][Owned] = true; // House is owned
print("House set to owned");
}
else
{
AHouseData[HouseID][Owned] = false; // House is not owned
print("House set to not owned");
}
db_get_field_assoc(result, "HouseOpened", ParameterValue, 50);
if (strcmp(ParameterValue, "1", false) == 0) // If the value "Yes" was read
{
AHouseData[HouseID][HouseOpened] = true; // House is open
}
else
{
AHouseData[HouseID][HouseOpened] = false; // House is closed
}
db_get_field_assoc(result, "PlayerIsTycoon", ParameterValue, 50);
if (strcmp(ParameterValue, "1", false) == 0) // If the value "Yes" was read
{
AHouseData[HouseID][PlayerIsTycoon] = true; // House owner is tycoon
}
else
{
AHouseData[HouseID][PlayerIsTycoon] = false; // House owner is not tycoon
}
db_get_field_assoc(result, "Owner", ParameterValue, 50);
format(AHouseData[HouseID][Owner], 24, ParameterValue);
new string[128];
format(string, sizeof(string), "The house owner of HouseID: %d is : %s", HouseID, AHouseData[HouseID][Owner]);
print(string);
db_get_field_assoc(result, "Insurance", ParameterValue, 50);
AHouseData[HouseID][Insurance] = strval(ParameterValue); // Store the Insurance
}
db_free_result(result);
for (new is = 1; is < 50 + 1; is += 1)
{
format(Query, sizeof(Query), "SELECT * FROM `vehicle` WHERE `HouseID` = '%d' COLLATE NOCASE AND `CarSlot` = '%d'", HouseID, is);
result2 = db_query(Database, Query);
if(db_num_rows(result2))
{
new vehicleid = AHouseData[HouseID][VehicleIDs][is];
AVehicleData[vehicleid][BelongsToHouse] = HouseID;
//Setup local variables
new cPanels = 0, cDoors = 0, cLights = 0, cTires = 0;
// Clear all data to start a new vehicle
cModel = 0;
cPaint = 0;
cFuel = -1;
cFuel = -1;
for (new i; i < 14; i++)
{
components[i] = 0;
}
db_get_field_assoc(result2, "Pass", ParameterValue, 50);
format(cPass, 24, ParameterValue); // Store the password
db_get_field_assoc(result2, "Model", ParameterValue, 50);
cModel = strval(ParameterValue); // Store the VehicleModel
db_get_field_assoc(result2, "Fuel", ParameterValue, 50);
cFuel = strval(ParameterValue); // Store the Fuel
db_get_field_assoc(result2, "Heal", ParameterValue, 50);
cHeal = strval(ParameterValue); // Store the Heal
db_get_field_assoc(result2, "PaintJob", ParameterValue, 50);
cPaint = strval(ParameterValue); // Store the VehiclePaintJob
db_get_field_assoc(result2, "Component0", ParameterValue, 50);
components[0] = strval(ParameterValue); // Store the VehicleSpoiler
db_get_field_assoc(result2, "Component1", ParameterValue, 50);
components[1] = strval(ParameterValue); // Store the VehicleRoof
db_get_field_assoc(result2, "Component2", ParameterValue, 50);
components[2] = strval(ParameterValue); // Store the VehicleSideSkirt
db_get_field_assoc(result2, "Component3", ParameterValue, 50);
components[3] = strval(ParameterValue); // Store the VehicleLamps
db_get_field_assoc(result2, "Component4", ParameterValue, 50);
components[4] = strval(ParameterValue); // Store the VehicleNitro
db_get_field_assoc(result2, "Component5", ParameterValue, 50);
components[5] = strval(ParameterValue); // Store the VehicleExhaust
db_get_field_assoc(result2, "Component6", ParameterValue, 50);
components[6] = strval(ParameterValue); // Store the VehicleWheels
db_get_field_assoc(result2, "Component7", ParameterValue, 50);
components[7] = strval(ParameterValue); // Store the VehicleStereo
db_get_field_assoc(result2, "Component8", ParameterValue, 50);
components[8] = strval(ParameterValue); // Store the VehicleHydraulics
db_get_field_assoc(result2, "Component9", ParameterValue, 50);
components[9] = strval(ParameterValue); // Store the VehicleFrontBumper
db_get_field_assoc(result2, "Component10", ParameterValue, 50);
components[10] = strval(ParameterValue); // Store the VehicleRearBumper
db_get_field_assoc(result2, "Component11", ParameterValue, 50);
components[11] = strval(ParameterValue); // Store the VehicleVentRight
db_get_field_assoc(result2, "Component12", ParameterValue, 50);
components[12] = strval(ParameterValue); // Store the VehicleVentLeft
db_get_field_assoc(result2, "Component13", ParameterValue, 50);
components[13] = strval(ParameterValue); // Store the VehicleSpoiler
db_get_field_assoc(result2, "Color1", ParameterValue, 50);
Col1 = strval(ParameterValue); // Store the Color1
db_get_field_assoc(result2, "Color2", ParameterValue, 50);
Col2 = strval(ParameterValue); // Store the Color2
db_get_field_assoc(result2, "SpawnX", ParameterValue, 50);
cx = floatstr(ParameterValue); // Store the VehicleX
db_get_field_assoc(result2, "SpawnY", ParameterValue, 50);
cy = floatstr(ParameterValue); // Store the VehicleY
db_get_field_assoc(result2, "SpawnZ", ParameterValue, 50);
cz = floatstr(ParameterValue); // Store the VehicleZ
db_get_field_assoc(result2, "SpawnRot", ParameterValue, 50);
crot = floatstr(ParameterValue); // Store the VehicleAngle
db_get_field_assoc(result2, "RemainingInsurance", ParameterValue, 50);
CIns = strval(ParameterValue); // Store the Remaining Insurance
db_get_field_assoc(result2, "PanelPanels", ParameterValue, 50);
cPanels = strval(ParameterValue); // Store the Heal
db_get_field_assoc(result2, "PanelDoors", ParameterValue, 50);
cDoors = strval(ParameterValue); // Store the Heal
db_get_field_assoc(result2, "PanelLights", ParameterValue, 50);
cLights = strval(ParameterValue); // Store the Heal
db_get_field_assoc(result2, "PanelTires", ParameterValue, 50);
cTires = strval(ParameterValue); // Store the Heal
db_get_field_assoc(result2, "Clamped", ParameterValue, 50);
if (strcmp(ParameterValue, "1", false) == 0) // If the value "Yes" was read
{
VehicleClamped = true; // Vehicle is clamped
}
else
{
VehicleClamped = false; // Vehicle is not clamped
}
db_get_field_assoc(result2, "HasPass", ParameterValue, 50);
if (strcmp(ParameterValue, "1", false) == 0) // If the value "Yes" was read
{
VehicleHasPass = true; // Vehicle has password
}
else
{
VehicleHasPass = false; // Vehicle has not password
}
// Set both colors to 1 if they are 0 AND if there is a paintjob applied
if ((Col1 == 0) && (cPaint != 0))
{
Col1 = 1;
}
if ((Col2 == 0) && (cPaint != 0))
{
Col2 = 1;
}
// Now add the vehicle to the house and set it's data
vehicleid = House_AddVehicle(HouseID, cModel, cPaint, cPanels, cDoors, cLights, cTires, components, cx, cy, cz, crot, Col1, Col2);
AVehicleData[vehicleid][TPanels] = cPanels;
AVehicleData[vehicleid][TDoors] = cDoors;
AVehicleData[vehicleid][TLights] = cLights;
AVehicleData[vehicleid][TTires] = cTires;
AVehicleData[vehicleid][RemainingInsurance] = CIns;
AVehicleData[vehicleid][Clamped] = VehicleClamped;
AVehicleData[vehicleid][HasPass] = VehicleHasPass;
//Put the password to the vehicle
format(AVehicleData[vehicleid][Pass], 24, cPass); // Store the password
// Also set the fuel (set it to maximum when the fuel parameter wasn't inside the file)
if (cFuel == -1)
{
AVehicleData[vehicleid][Fuel] = MaxFuel;
}
else // If the parameter was there, store it
{
AVehicleData[vehicleid][Fuel] = cFuel;
}
// Also set the heal (set it to maximum when the fuel parameter wasn't inside the file)
if (cHeal == -1)
{
AVehicleData[vehicleid][Heal] = MaxVehHealth;
}
else // If the parameter was there, store it
{
AVehicleData[vehicleid][Heal] = cHeal;
}
SetVehicleToRespawn(vehicleid);
}
db_free_result(result2);
}
print("Load house database closed");
//Close the database
db_close(Database);
return 1;
}
Re: House and vehicle SQLite load -
Hessu - 28.10.2015
Bump.