else if(db_num_rows(Result)) // The house ID is in the database. Update the values
{
print("House found in database! Updaing...");
new Owned33 = 0;
if(AHouseData[HouseID][Owned] == true)
{
Owned33 = 1;
}
else if(AHouseData[HouseID][Owned] == true)
{
Owned33 = 0;
}
printf("House owned %d House Owner %s", Owned33, AHouseData[HouseID][Owner]);
// 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
print("Failstep 9");
format(Query, sizeof(Query), "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', `PlayerIsTycoon` = '%d', `Owner` = '%s', `Insurance` = '%d' WHERE `HouseID` = '%d'",
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], Owned33,
AHouseData[HouseID][HouseOpened], AHouseData[HouseID][PlayerIsTycoon], AHouseData[HouseID][Owner], AHouseData[HouseID][Insurance], HouseID); // 15
print("Failstep 10");
db_free_result(db_query(Database, Query));
print("Failstep 11");
// strdel(HouseStrCat, 0, 800);
print("Failstep 12");
}
[06:36:23] House found in database! Updaing... [06:36:23] House owned 1 House Owner Kulottaja [06:36:23] Failstep 9 [06:36:23] Failstep 10 [06:36:23] SQLitei Notice: (db_free_result_hook) Invalid result given. [06:36:23] Failstep 11 [06:36:23] Failstep 12
|
Код:
if(AHouseData[HouseID][Owned] == true)
{
Owned33 = 1;
}
else if(AHouseData[HouseID][Owned] == true)
{
Owned33 = 0;
}
|
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, PlayerIsTycoon = %d, Owner = '%s', Insurance = %d WHERE HouseID = %d
printf("Started to save house %d", HouseID);
//Open sqlite database
print("Failstep 1");
new DB:Database, DBResult:Result;
print("Failstep 2");
new HouseStrCat[800];
print("Failstep 3");
new Query[1100];
new HouseIDQuery[128];
print("Failstep 4");
Database = db_open("DataHouses.db");
print("Failstep 5");
format(HouseIDQuery, sizeof(HouseIDQuery), "SELECT * FROM `Houses` WHERE `HouseID` = '%d'", HouseID);
print("Failstep 6");
Result = db_query(Database, HouseIDQuery);
print("Searching for house in database...");
if(!db_num_rows(Result)) //No house with this ID was found in the database
{
print("No house with that id was found. Adding in in the database...");
print("Failstep 7");
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
print("Failstep 8");
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]);
print("Failstep 9");
db_free_result(db_query(Database, Query));
print("Failstep 10");
strdel(HouseStrCat, 0, 800);
print("Added!");
}
else if(db_num_rows(Result)) // The house ID is in the database. Update the values
{
print("House found in database! Updaing...");
new Owned33 = 0;
if(AHouseData[HouseID][Owned] == true)
{
Owned33 = 1;
}
else if(AHouseData[HouseID][Owned] == false)
{
Owned33 = 0;
}
printf("House owned %d House Owner %s", Owned33, AHouseData[HouseID][Owner]);
print("Failstep 9");
//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', `PlayerIsTycoon` = '%d', `Owner` = '%s', `Insurance` = '%d' WHERE `HouseID` = '%d'
format(Query, sizeof(Query), "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, PlayerIsTycoon = %d, Owner = '%s', Insurance = %d WHERE HouseID = %d",
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], Owned33,
AHouseData[HouseID][HouseOpened], AHouseData[HouseID][PlayerIsTycoon], AHouseData[HouseID][Owner], AHouseData[HouseID][Insurance], HouseID); // 15
print("Failstep 10");
db_free_result(db_query(Database, Query));
print("Failstep 11");
}
db_free_result(Result);
print("House saved. Stating to save vehicles...");
// Setup a custom type that holds all data for houses
enum THouseData
{
PickupID, // Holds the pickup-id that is linked to this house
Text3D:DoorText, // Holds the reference to the 3DText above the house's pickup
MapIconID, // Holds the ID of the mapicon for the house
HouseAddress[100], // Holds the address of the house (this will be displayed above the pickup near the house when it's owned)
HouseName[100], // Holds the name of the house (this will be displayed above the pickup near the house when it's owned)
Insurance, // Holds "1" if the house has an insurance for the vehicles belonging to this house
Float:HouseX, // Holds the X-coordinate of the pickup for the house
Float:HouseY, // Holds the Y-coordinate of the pickup for the house
Float:HouseZ, // Holds the Z-coordinate of the pickup for the house
HouseInterior, // Holds the interior of the house
HouseMaxSlots, // Holds the maximum ammount of slots this house has originally
HouseNewMaxSlots, // Holds the maximum level this house can be upgraded to
HousePrice, // Holds the price for buying the house, the same price applies when upgrading a house per level
bool:Owned, // Holds true if the house is owned by somebody
bool:PlayerIsTycoon, // Holds true if the house owner has 1000 or more truckloads
Owner[24], // Holds the name of the owner of the house
bool:HouseOpened, // Holds true if the house is open to the public (anyone can enter), false means: only the owner can enter it
VehicleIDs[50] // Holds the vehicle-id's of the vehicles linked to this house
}
// Holds the data for all houses
new AHouseData[MAX_HOUSES][THouseData];
printf("Started to save house %d", HouseID);
//Open sqlite database
print("Failstep 1");
new DB:Database, DBResult:Result;
print("Failstep 2");
new HouseStrCat[800];
print("Failstep 3");
new Query[1100];
new HouseIDQuery[128];
print("Failstep 4");
Database = db_open("DataHouses.db");
print("Failstep 5");
format(HouseIDQuery, sizeof(HouseIDQuery), "SELECT * FROM Houses WHERE HouseID = %d", HouseID);
print("Failstep 6");
Result = db_query(Database, HouseIDQuery);
print("Searching for house in database...");
if(!db_num_rows(Result)) //No house with this ID was found in the database
{
print("No house with that id was found. Adding in in the database...");
print("Failstep 7");
strcat(HouseStrCat, "INSERT INTO Houses (HouseID, HouseAddress, HouseName, HouseX, HouseY, HouseZ, HouseInterior, HouseMaxSlots, HouseNewMaxSlots, HousePrice, Owned, HouseOpened, PlayerIsTycoon, Owner, Insurance VALUES");
format(Query, sizeof(Query), "%s(%d,'%s','%s',%f,%f,%f,%d,%d,%d,%d,%d,%d,%d,'%s',%d)", 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]); // 44
print("Failstep 8");
print("Failstep 9");
db_free_result(db_query(Database, Query));
print("Failstep 10");
strdel(HouseStrCat, 0, 800);
print("Added!");
}
else if(db_num_rows(Result)) // The house ID is in the database. Update the values
{
print("House found in database! Updaing...");
new Owned33 = 0;
if(AHouseData[HouseID][Owned] == true)
{
Owned33 = 1;
}
else if(AHouseData[HouseID][Owned] == false)
{
Owned33 = 0;
}
printf("House owned %d House Owner %s", Owned33, AHouseData[HouseID][Owner]);
print("Failstep 9");
//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', `PlayerIsTycoon` = '%d', `Owner` = '%s', `Insurance` = '%d' WHERE `HouseID` = '%d'
format(Query, sizeof(Query), "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, PlayerIsTycoon = %d, Owner = '%s', Insurance = %d WHERE HouseID = %d",
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], Owned33,
AHouseData[HouseID][HouseOpened], AHouseData[HouseID][PlayerIsTycoon], AHouseData[HouseID][Owner], AHouseData[HouseID][Insurance], HouseID); // 15
print("Failstep 10");
db_free_result(db_query(Database, Query));
print("Failstep 11");
}
db_free_result(Result);
print("House saved. Stating to save vehicles...");
|
I just checked with a database browser and saw that the values for the house was correct. The problem is that when a player buys the house, it wont save the new values eg. house owned/owner/house name etc.
Thanks for your replies! |
//Create the databases and tables if not existed
//Open vehicle database
new DB:Database, Query[500], catted[800];
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(catted, "CREATE TABLE IF NOT EXISTS `Vehicle` (`HouseID`, `Pass`, `Model`, `Fuel`, `Heal`, `PaintJob`, `Component0`, `Component1`, `Component2`, `Component3`, `Component4`, `Component5`, `Component6`, `Component7`, `Component8`, `Component9`", sizeof(catted));
strcat(catted, " `Component10`, `Component11`, `Component12`, `Component13`, `Color1`, `Color2`, `SpawnX`, `SpawnY`, `SpawnZ`, `SpawnRot`, `RemainingInsurance`, `PanelPanels`, `PanelDoors`, `PanelLights`, `PanelTires`, `Clamped`, `HasPass`, `CarSlot`)", sizeof(catted));
db_free_result(db_query(Database, catted));
strdel(catted, 0, 800);
//Close the vehicle database
db_close(Database);