30.10.2015, 10:20
Nothing of that dint work, and Vince, i have annother code for saving player stats the same way built, and it works fine, so i dont think its that. Interesting not though.
The code looks like this now, and has exacly the same problems. Here i have more of it if you can spot something interesting from it. Sorry for the failsteps!
And the AHouseData as RoboN1X asked for :
Let me clearify that creating a house and putting the values of the house into database using "INSERT INTO `Houses`" works. 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!
The code looks like this now, and has exacly the same problems. Here i have more of it if you can spot something interesting from it. Sorry for the failsteps!
pawn Код:
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...");
pawn Код:
// 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];
Thanks for your replies!