27.09.2015, 11:42
(
Последний раз редактировалось Hessu; 28.09.2015 в 05:52.
)
Hi
Sorry to bother you again, but i got stuck at a code that i dont know whats wrong with it.
I came to the conclusion that this piece of code causes problems (saving the data of a house).
Symptoms: When this function is being called, the commands and some functions stop working. Its like a server freeze and rejoining does not help.
When server is restarted, everything works well again, but the house has dissaperared (not saved properly i supose).
My suspissions ar at the db_free_result OR returns.
I am converting the PPC Trucking to use sqlite instead of fileoperations, and i managed to sucessfully convert the player starts and settings already, but i dont know too much about sql yet so..
If you want to take a look at other codes, please reply and ask for it.
Thanks!
Sorry to bother you again, but i got stuck at a code that i dont know whats wrong with it.
I came to the conclusion that this piece of code causes problems (saving the data of a house).
Symptoms: When this function is being called, the commands and some functions stop working. Its like a server freeze and rejoining does not help.
When server is restarted, everything works well again, but the house has dissaperared (not saved properly i supose).
My suspissions ar at the db_free_result OR returns.
I am converting the PPC Trucking to use sqlite instead of fileoperations, and i managed to sucessfully convert the player starts and settings already, but i dont know too much about sql yet so..
pawn Код:
// This function will save the given house
HouseFile_Save(HouseID)
{
//Open sqlite database
new catted[1500];
new DB:Database;
Database = db_open("DataPlayers.db");
strcat(catted, "CREATE TABLE IF NOT EXISTS `Houses` (`HouseID`, `HouseAddress`, `HouseName`, `HouseX`, `HouseY`, `HouseZ`, `HouseInterior`, `HouseMaxSlots`, `HouseNewMaxSlots`, `HousePrice`, `Owned`, `HouseOpened`, `PlayerIsTycoon`, `Owner`, `Insurance`)", sizeof(catted)); //15
db_free_result(db_query(Database, catted));
new Query[700], DBResult:Result;
format(Query, sizeof(Query), "SELECT * FROM `Houses` WHERE `HouseID` = '%d'", HouseID);
Result = db_query(Database,Query);
//No house with this ID was found in the database
if(!db_num_rows(Result))
{
new catted2[1500];
strcat(catted2, "INSERT INTO `Houses` (`HouseID`, `HouseAddress`, `HouseName`, `HouseX`, `HouseY`, `HouseZ`, `HouseInterior`, `HouseMaxSlots`, `HouseNewMaxSlots`, `HousePrice`, `Owned`, `HouseOpened`, `PlayerIsTycoon`, `Owner`, `Insurance`) ", sizeof(catted2)); // 15
strcat(catted2, "VALUES('%d','%s','%s','%f','%f','%f','%d','%d','%d','%d','%d','%d','%d','%s','%d')", sizeof(catted2)); // 44
format(Query, sizeof(Query), catted2, 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));
}
else if(db_num_rows(Result)) // The house ID is in the database. Update the values
{
new catted3[1500];
strcat(catted3, "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(catted3));
strcat(catted3, "`PlayerIsTycoon` = '%d', `Owner` = '%s', `Insurance` = '%d' WHERE `HouseID` = '%d'", sizeof(catted3));
format(Query, sizeof(Query), catted3, 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);
db_free_result(db_query(Database, Query));
}
db_free_result(Result);
// 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)
{
//Setup local variables
new vid, cPanels, cDoors, cLights, cTires;
new catted4[1500];
// Get the vehicle id
vid = AHouseData[HouseID][VehicleIDs][CarSlot];
//AVehicleData[vid][BelongsToHouse] = HouseID;
GetVehicleDamageStatus(vid, cPanels, cDoors, cLights, cTires);
strcat(catted4, "CREATE TABLE IF NOT EXISTS `Vehicle` (`HouseID`, `Pass`, `Model`, `Fuel`, `Heal`, `PaintJob`, `Component0`, `Component1`, `Component2`, `Component3`, `Component4`, `Component5`, `Component6`, `Component7`, `Component8`, `Component9`", sizeof(catted4));
strcat(catted4, " `Component10`, `Component11`, `Component12`, `Component13`, `Color1`, `Color2`, `SpawnX`, `SpawnY`, `SpawnZ`, `SpawnRot`, `RemainingInsurance`, `PanelPanels`, `PanelDoors`, `PanelLights`, `PanelTires`, `Clamped`, `HasPass`)", sizeof(catted4));
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))
{
new catted5[1500];
strcat(catted5, "INSERT INTO `Vehicle` (`HouseID`, `Pass`, `Model`, `Fuel`, `Heal`, `PaintJob`, `Component0`, `Component1`, `Component2`, `Component3`, `Component4`, `Component5`, `Component6`, `Component7`, `Component8`, `Component9`", sizeof(catted5)); //16
strcat(catted5, " `Component10`, `Component11`, `Component12`, `Component13`, `Color1`, `Color2`, `SpawnX`, `SpawnY`, `SpawnZ`, `SpawnRot`, `RemainingInsurance`, `PanelPanels`, `PanelDoors`, `PanelLights`, `PanelTires`, `Clamped`, `HasPass`)", sizeof(catted5)); // 33
strcat(catted5, "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(catted5)); // 33
format(Query, sizeof(Query), catted5, 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));
}
else if(db_num_rows(Result)) // The vehicle ID is in the database. Update the values
{
new catted6[1500];
strcat(catted6, "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(catted6));
strcat(catted6, "`Component7` = '%d', `Component8` = '%d', `Component9` = '%d', `Component10` = '%d', `Component11` = '%d', `Component12` = '%d', `Component13` = '%d', `Color1` = '%d', `Color2` = '%d', `SpawnX` = '%f', `SpawnY` = '%f', ", sizeof(catted6));
strcat(catted6, "`SpawnZ` = '%f', `SpawnRot` = '%f', `RemainingInsurance` = '%d', `PanelPanels` = '%d', `PanelDoors` = '%d', `PanelLights` = '%d', `PanelTires` = '%d', `Clamped` = '%d', `HasPass` = '%d' WHERE `HouseID` = '%d'", sizeof(catted6));
format(Query, sizeof(Query), catted6, 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));
}
db_free_result(Result);
}
}
//Close the database
db_close(Database);
return 1;
}
Thanks!