22.11.2015, 17:20
Ok so my houses won't save into my database which is weird, MySQL.
The dialog code for creating a house.
The code for saving the house and loading them.
The code for the MySQL Database / Text file.
Can Anyone help, It won't save my houses into my database or create the furniture into them.
The dialog code for creating a house.
Код:
case 6:
{
//House Creation
new UID, text[128];
new found = 0;
for(new i = 1; i < MAX_HOUSES; i++)
{
if(HouseInfo[i][hID] == 0 && found == 0)
{
found++;
UID = i;
format(text, sizeof(text), "House id is %d", UID);
SendClientMessage(playerid, -1, text);
}
}
HouseInfo[UID][hID] = UID;
HouseInfo[UID][hPrice] = AdminCreateHousePrice[playerid];
HouseInfo[UID][hIntOut] = AdminCreateHouseInterior[playerid][0];
HouseInfo[UID][hIntIn] = AdminCreateHouseInterior[playerid][1];
HouseInfo[UID][hVwOut] = AdminCreateHouseOutSideVW[playerid];
HouseInfo[UID][hVwIn] = UID;
HouseInfo[UID][Garage] = AdminCreateHouseGarage[playerid];
HouseInfo[UID][gInterior] = AdminCreateHouseGarageInterior[playerid];
HouseInfo[UID][HouseEnterPos][0] = AdminCreateHousePos[playerid][0];
HouseInfo[UID][HouseEnterPos][1] = AdminCreateHousePos[playerid][1];
HouseInfo[UID][HouseEnterPos][2] = AdminCreateHousePos[playerid][2];
HouseInfo[UID][HouseIntPos][0] = AdminCreateHouseIntPos[playerid][0];
HouseInfo[UID][HouseIntPos][1] = AdminCreateHouseIntPos[playerid][1];
HouseInfo[UID][HouseIntPos][2] = AdminCreateHouseIntPos[playerid][2];
HouseInfo[UID][GaragePos][0] = AdminCreateHouseGaragePos[playerid][0];
HouseInfo[UID][GaragePos][1] = AdminCreateHouseGaragePos[playerid][1];
HouseInfo[UID][GaragePos][2] = AdminCreateHouseGaragePos[playerid][2];
HouseInfo[UID][GarageIntPos][0] = AdminCreateHouseGarageIntPos[playerid][0];
HouseInfo[UID][GarageIntPos][1] = AdminCreateHouseGarageIntPos[playerid][1];
HouseInfo[UID][GarageIntPos][2] = AdminCreateHouseGarageIntPos[playerid][2];
new query[800], owner[25];
format(owner, sizeof(owner), "None");
mysql_format(mysql, query, sizeof(query),"INSERT INTO `houses`(`ID`, `Xo`, `Yo`, `Zo`, `Xi`, `Yi`, `Zi`, `IntOut`, `IntIn`, `VwOut`, `VwIn`, `Owner`, `Value`) VALUES (%d, %f, %f, %f, %f, %f, %f, %d, %d, %d, %d, '%e', %d)",
UID, HouseInfo[UID][HouseEnterPos][0], HouseInfo[UID][HouseEnterPos][1], HouseInfo[UID][HouseEnterPos][2], HouseInfo[UID][HouseIntPos][0], HouseInfo[UID][HouseIntPos][1], HouseInfo[UID][HouseIntPos][2],
HouseInfo[UID][hIntOut], HouseInfo[UID][hIntIn], HouseInfo[UID][hVwOut], UID, owner, HouseInfo[UID][hPrice]);
mysql_pquery(mysql, query);
printf("House %d created", UID);
//HouseInfo[UID][hIcon]=CreateDynamicPickup(1273, 1, HouseInfo[UID][hXo], HouseInfo[UID][hYo], HouseInfo[UID][hZo],HouseInfo[UID][hVwOut],HouseInfo[UID][hVwOut] );
//HouseInfo[UID][hIcon] = CreateDynamicCP(HouseInfo[UID][hXo], HouseInfo[UID][hYo], HouseInfo[UID][hZo], 1.5, HouseInfo[UID][hVwOut], -1, -1, 10.0);
HouseInfo[UID][hIcon] = CreateDynamicPickup(1273, 1, HouseInfo[UID][HouseEnterPos][0],HouseInfo[UID][HouseEnterPos][1],HouseInfo[UID][HouseEnterPos][2]);
new string[256];
format(string, sizeof(string), "House Owned By %s\nPrice: %d\nPress H to enter", HouseInfo[UID][hOwnerName], HouseInfo[UID][hPrice]);
House3D[UID] = CreateDynamic3DTextLabel(string,0xFFFFFFFF,HouseInfo[UID][HouseEnterPos][0],HouseInfo[UID][HouseEnterPos][1],HouseInfo[UID][HouseEnterPos][2]+0.75, 25.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, 0, 0, -1, 100.0);
CreateDynamicMapIcon(HouseInfo[UID][HouseEnterPos][0],HouseInfo[UID][HouseEnterPos][1],HouseInfo[UID][HouseEnterPos][2], 31, COLOR_YELLOW, HouseInfo[UID][hVwOut], 0, -1, 10.0);
Iter_Add(HouseIterator, UID);
SaveHouseID(UID, 0);
SetPlayerPos(playerid, AdminCreateHousePos[playerid][0], AdminCreateHousePos[playerid][1], AdminCreateHousePos[playerid][2]);
}
}
}
Код:
stock SaveHouseID(i, saveowner = 1)
{
new query[700];
if(HouseInfo[i][hPrice] > 0)
{
if(saveowner == 1)
{
mysql_format(mysql, query, sizeof(query), "UPDATE `houses` SET `Owner`='%e' WHERE ID=%d", HouseInfo[i][hOwnerName], HouseInfo[i][hID]);
mysql_tquery(mysql, query, "SendQueryHouse", "d", i);
}
mysql_format(mysql, query, sizeof(query), "UPDATE `houses` SET `Xo`=%f,`Yo`=%f,`Zo`=%f,`Xi`=%f,`Yi`=%f,`Zi`=%f,`bdXo`=%f,`bdYo`=%f,`bdZo`=%f,`bdXi`=%f,`bdYi`=%f,`bdZi`=%f,`IntOut`=%d,`IntIn`=%d,`VwOut`=%d,`VwIn`=%d,`Owned`=%d,`Value`=%d, WHERE `ID`=%d",
HouseInfo[i][HouseEnterPos][0],HouseInfo[i][HouseEnterPos][1],HouseInfo[i][HouseEnterPos][2],HouseInfo[i][HouseIntPos][0],HouseInfo[i][HouseIntPos][1],HouseInfo[i][HouseIntPos][2],
HouseInfo[i][HouseBDPos][0],HouseInfo[i][HouseBDPos][1],HouseInfo[i][HouseBDPos][2],HouseInfo[i][HouseBDIntPos][0],HouseInfo[i][HouseBDIntPos][1],HouseInfo[i][HouseBDIntPos][2],
HouseInfo[i][hIntOut],HouseInfo[i][hIntIn],HouseInfo[i][hVwOut],HouseInfo[i][hVwIn],HouseInfo[i][hOwned],HouseInfo[i][hPrice], HouseInfo[i][hID]);
mysql_tquery(mysql, query, "SendQueryHouse", "d", i);
mysql_format(mysql, query, sizeof(query), "UPDATE `houses` SET `HasGarage`=%i, `hgXo`=%f, `hgYo`=%f, `hgZo`=%f, `hgAo`=%f, `gInterior`=%d, `hgXi`=%f, `hgYi`=%f, `hgZi`=%f, `hgAi`=%f , `Locked`=%d WHERE `ID`=%d",
HouseInfo[i][Garage],
HouseInfo[i][GaragePos][0],
HouseInfo[i][GaragePos][1],
HouseInfo[i][GaragePos][2],
HouseInfo[i][GaragePos][3],
HouseInfo[i][gInterior],
HouseInfo[i][GarageIntPos][0],
HouseInfo[i][GarageIntPos][1],
HouseInfo[i][GarageIntPos][2],
HouseInfo[i][GarageIntPos][3],
HouseInfo[i][hLocked], HouseInfo[i][hID]);
mysql_tquery(mysql, query, "SendQueryHouse", "d", i);
}
return 1;
}
stock LoadHouses()
{
new query[256];
for(new i = 1; i < MAX_HOUSES; i++)
{
format(query, sizeof(query), "SELECT * FROM houses WHERE ID=%i", i);
mysql_function_query(mysql, query, true, "LoadHouseSQL", "d", i);
}
return 1;
}
stock LoadHouseID(id)
{
new query[256];
format(query, sizeof(query), "SELECT * FROM houses WHERE ID=%d", id);
mysql_function_query(handlesql, query, true, "LoadHouseSQL", "d", id);
return 1;
}
forward LoadHouseSQL(id);
public LoadHouseSQL(id)
{
new fields, rows;
cache_get_data(rows, fields);
if(rows)
{
new fetch[256];
cache_get_field_content(0, "ID", fetch);
HouseInfo[id][hID]= strval(fetch);
cache_get_field_content(0, "Xo", fetch);
HouseInfo[id][HouseEnterPos][0]= floatstr(fetch);
cache_get_field_content(0, "Yo", fetch);
HouseInfo[id][HouseEnterPos][1]= floatstr(fetch);
cache_get_field_content(0, "Zo", fetch);
HouseInfo[id][HouseEnterPos][2]= floatstr(fetch);
cache_get_field_content(0, "Xi", fetch);
HouseInfo[id][HouseIntPos][0]= floatstr(fetch);
cache_get_field_content(0, "Yi", fetch);
HouseInfo[id][HouseIntPos][1]= floatstr(fetch);
cache_get_field_content(0, "Zi", fetch);
HouseInfo[id][HouseIntPos][2]= floatstr(fetch);
cache_get_field_content(0, "bdXo", fetch);
HouseInfo[id][HouseBDPos][0]= floatstr(fetch);
cache_get_field_content(0, "bdYo", fetch);
HouseInfo[id][HouseBDPos][1]= floatstr(fetch);
cache_get_field_content(0, "bdZo", fetch);
HouseInfo[id][HouseBDPos][2]= floatstr(fetch);
cache_get_field_content(0, "bdXi", fetch);
HouseInfo[id][HouseBDIntPos][0]= floatstr(fetch);
cache_get_field_content(0, "bdYi", fetch);
HouseInfo[id][HouseBDIntPos][1]= floatstr(fetch);
cache_get_field_content(0, "bdZi", fetch);
HouseInfo[id][HouseBDIntPos][2]= floatstr(fetch);
cache_get_field_content(0, "IntOut", fetch);
HouseInfo[id][hIntOut]= strval(fetch);
cache_get_field_content(0, "IntIn", fetch);
HouseInfo[id][hIntIn]= strval(fetch);
cache_get_field_content(0, "VwOut", fetch);
HouseInfo[id][hVwOut]= strval(fetch);
cache_get_field_content(0, "VwIn", fetch);
HouseInfo[id][hVwIn]= strval(fetch);
cache_get_field_content(0, "Owned", fetch);
HouseInfo[id][hOwned]= strval(fetch);
cache_get_field_content(0, "Owner", fetch);
format(HouseInfo[id][hOwnerName], 128, fetch);
cache_get_field_content(0, "Value", fetch);
HouseInfo[id][hPrice]= strval(fetch);
cache_get_field_content(0, "Locked", fetch);
HouseInfo[id][hLocked]= strval(fetch);
HouseInfo[id][Garage] = cache_get_field_content_int(0, "Garage");
cache_get_field_content(0, "hgXo", fetch);
HouseInfo[id][GaragePos][0]= floatstr(fetch);
cache_get_field_content(0, "hgYo", fetch);
HouseInfo[id][GaragePos][1]= floatstr(fetch);
cache_get_field_content(0, "hgZo", fetch);
HouseInfo[id][GaragePos][2]= floatstr(fetch);
cache_get_field_content(0, "hgAo", fetch);
HouseInfo[id][GaragePos][3]= floatstr(fetch);
cache_get_field_content(0, "gInterior", fetch);
HouseInfo[id][gInterior]= strval(fetch);
cache_get_field_content(0, "hgXi", fetch);
HouseInfo[id][GarageIntPos][0]= floatstr(fetch);
cache_get_field_content(0, "hgYi", fetch);
HouseInfo[id][GarageIntPos][1]= floatstr(fetch);
cache_get_field_content(0, "hgZi", fetch);
HouseInfo[id][GarageIntPos][2]= floatstr(fetch);
cache_get_field_content(0, "hgAi", fetch);
HouseInfo[id][GarageIntPos][3]= floatstr(fetch);
//HouseInfo[id][hIcon]=CreateDynamicPickup(1273, 1, HouseInfo[id][hXo], HouseInfo[id][hYo], HouseInfo[id][hZo],HouseInfo[id][hVwOut]);
//HouseInfo[id][hIcon] = CreateDynamicCP(HouseInfo[id][hXo], HouseInfo[id][hYo], HouseInfo[id][hZo], 1.5, HouseInfo[id][hVwOut], -1, -1, 10.0);
HouseInfo[id][hIcon] = CreateDynamicPickup(1273, 1, HouseInfo[id][HouseEnterPos][0],HouseInfo[id][HouseEnterPos][1],HouseInfo[id][HouseEnterPos][2]);
new string[256];
format(string, sizeof(string), "House Owned By %s\nPrice: %d\nPress H to enter", HouseInfo[id][hOwnerName], HouseInfo[id][hPrice]);
House3D[id] = CreateDynamic3DTextLabel(string,0xFFFFFFFF,HouseInfo[id][HouseEnterPos][0],HouseInfo[id][HouseEnterPos][1],HouseInfo[id][HouseEnterPos][2]+0.75, 25.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, 0, 0, -1, 100.0);
if(HouseInfo[id][Garage] != 0)
{
HouseInfo[id][hIcon] = CreateDynamicPickup(1273, 1, HouseInfo[id][GaragePos][0],HouseInfo[id][GaragePos][1],HouseInfo[id][GaragePos][2]);
format(string, sizeof(string), "%s houses garage\nPress H to enter", HouseInfo[id][hOwnerName]);
House3D[id] = CreateDynamic3DTextLabel(string,0xFFFFFFFF,HouseInfo[id][GaragePos][0],HouseInfo[id][GaragePos][1],HouseInfo[id][GaragePos][2]+0.75, 25.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, 0, 0, -1, 100.0);
}
/*if(HouseInfo[id][hbdXo] != 0 || HouseInfo[id][hbdYo] != 0 || HouseInfo[id][hbdZo] != 0)
{
HouseInfo[id][hbdoIcon] = CreateDynamicCP(HouseInfo[id][hbdXo], HouseInfo[id][hbdYo], HouseInfo[id][hbdZo], 1.5, HouseInfo[id][hVwOut], -1, -1, 10.0);
}
if(HouseInfo[id][hbdXi] != 0 || HouseInfo[id][hbdYi] != 0 || HouseInfo[id][hbdZi] != 0)
{
HouseInfo[id][hbdiIcon] = CreateDynamicCP(HouseInfo[id][hbdXi], HouseInfo[id][hbdYi], HouseInfo[id][hbdZi], 1.5, HouseInfo[id][hVwIn], -1, -1, 10.0);
}*/
new query[248];
format(query, sizeof(query), "SELECT * FROM housefurn WHERE HID=%d", id);
mysql_function_query(mysql, query, true, "LoadFurn", "i", id);
Iter_Add(HouseIterator, id);
}
return 1;
}
forward LoadFurn(houseid);
public LoadFurn(houseid)
{
for(new i = 0; i < MAX_FURNITURE; i++)
{
if(i < cache_get_row_count())
{
HouseInfo[houseid][ObjectDbID][i] = cache_get_field_content_int(i, "ID");
HouseInfo[houseid][ObjectID][i] = cache_get_field_content_int(i, "Model");
HouseInfo[houseid][ObjectPosX][i] = cache_get_field_content_float(i, "PosX");
HouseInfo[houseid][ObjectPosY][i] = cache_get_field_content_float(i, "PosY");
HouseInfo[houseid][ObjectPosZ][i] = cache_get_field_content_float(i, "PosZ");
HouseInfo[houseid][ObjectPosRX][i] = cache_get_field_content_float(i, "AngX");
HouseInfo[houseid][ObjectPosRY][i] = cache_get_field_content_float(i, "AngY");
HouseInfo[houseid][ObjectPosRZ][i] = cache_get_field_content_float(i, "AngZ");
HouseInfo[houseid][ObjectLocked][i] = cache_get_field_content_int(i, "Locked");
HouseInfo[houseid][ObjectCode][i] = cache_get_field_content_int(i, "Code");
HouseInfo[houseid][ObjectVW][i] = cache_get_field_content_int(i, "VW");
HouseInfo[houseid][ObjectInt][i] = cache_get_field_content_int(i, "Int");
new MaterialFetch[128];
new Materials[HOUSE_OBJECT_MATERIALS][8];
cache_get_field_content(i, "Materials", MaterialFetch);
split(MaterialFetch, Materials, ',');
for(new i2 = 0; i2 < HOUSE_OBJECT_MATERIALS; i2++)
{
if(strval(Materials[i2]) != 0)
{
HouseMaterialInfo[houseid][i][i2] = strval(Materials[i2]);
}
}
HouseInfo[houseid][hObject][i] = CreateDynamicObject(HouseInfo[houseid][ObjectID][i],
HouseInfo[houseid][ObjectPosX][i], HouseInfo[houseid][ObjectPosY][i], HouseInfo[houseid][ObjectPosZ][i],
HouseInfo[houseid][ObjectPosRX][i], HouseInfo[houseid][ObjectPosRY][i], HouseInfo[houseid][ObjectPosRZ][i],
HouseInfo[houseid][ObjectVW], HouseInfo[houseid][ObjectInt], -1, 100);
for(new i2 = 0; i2 < HOUSE_OBJECT_MATERIALS; i2++)
{
if(HouseMaterialInfo[houseid][i][i2] != 0)
{
ChangeDynamicObjectMaterial(HouseInfo[houseid][hObject][i], i2, HouseMaterialInfo[houseid][i][i2]);
}
}
}
}
return 1;
}
forward SaveFurn(houseid);
public SaveFurn(houseid)
{
new query[1024];
for(new i = 0; i < MAX_FURNITURE; i++)
{
if(HouseInfo[houseid][ObjectID][i] != 0)
{
new Materials[128];
for(new i2 = 0; i2 < HOUSE_OBJECT_MATERIALS; i2++)
{
if(i2 == 0)
{
format(Materials, sizeof(Materials), "%i", HouseMaterialInfo[houseid][i][i2]);
}
else
{
format(Materials, sizeof(Materials), "%s,%i", Materials, HouseMaterialInfo[houseid][i][i2]);
}
}
mysql_format(mysql, query, sizeof(query), "UPDATE housefurn SET Model=%i, VW=%i, HID=%i, Int=%i, Code=%i, PosX=%f, PosY=%f, PosZ=%f, AngX=%f, AngY=%f, AngZ=%f, Materials='%e', Locked=%i WHERE ID=%i",
HouseInfo[houseid][ObjectID][i],
HouseInfo[houseid][ObjectVW][i],
houseid,
HouseInfo[houseid][ObjectInt][i],
HouseInfo[houseid][ObjectCode][i],
HouseInfo[houseid][ObjectPosX][i],
HouseInfo[houseid][ObjectPosY][i],
HouseInfo[houseid][ObjectPosZ][i],
HouseInfo[houseid][ObjectPosRX][i],
HouseInfo[houseid][ObjectPosRY][i],
HouseInfo[houseid][ObjectPosRZ][i],
Materials,
HouseInfo[houseid][ObjectLocked][i],
HouseInfo[houseid][ObjectDbID][i]);
mysql_tquery(mysql, query);
}
}
return 1;
}
Код:
-- phpMyAdmin SQL Dump -- version 4.5.1 -- http://www.phpmyadmin.netnl6aedfbe4e9e21...69664060-- Host: 127.0.0.1 -- Generation Time: Nov 22, 2015 at 07:12 PM -- Server version: 10.1.8-MariaDB -- PHP Version: 5.6.14 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8mb4 */; -- -- Database: `housesystem` -- -- -------------------------------------------------------- -- -- Table structure for table `garages` -- CREATE TABLE `garages` ( `ID` int(11) NOT NULL, `Owned` int(11) NOT NULL, `OwnerID` int(11) NOT NULL, `OwnerName` varchar(25) NOT NULL, `Type` int(11) NOT NULL, `Xcor` float NOT NULL, `Ycor` float NOT NULL, `Zcor` float NOT NULL, `VirtualWorld` int(11) NOT NULL, `IntID` int(11) NOT NULL, `Price` int(11) NOT NULL, `Locked` int(11) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -------------------------------------------------------- -- -- Table structure for table `housefurn` -- CREATE TABLE `housefurn` ( `ID` int(11) NOT NULL, `HID` int(11) NOT NULL, `Model` int(11) NOT NULL, `PosX` float NOT NULL, `PosY` float NOT NULL, `PosZ` float NOT NULL, `AngX` float NOT NULL, `AngY` float NOT NULL, `AngZ` float NOT NULL, `Materials` varchar(128) NOT NULL, `Locked` int(11) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -------------------------------------------------------- -- -- Table structure for table `houses` -- CREATE TABLE `houses` ( `ID` int(11) NOT NULL, `Xo` float NOT NULL, `Yo` float NOT NULL, `Zo` float NOT NULL, `Xi` float NOT NULL, `Yi` float NOT NULL, `Zi` float NOT NULL, `bdXo` float NOT NULL, `bdYo` float NOT NULL, `bdZo` float NOT NULL, `bdXi` float NOT NULL, `bdYi` float NOT NULL, `bdZi` float NOT NULL, `IntOut` int(11) NOT NULL, `IntIn` int(11) NOT NULL, `VwOut` int(11) NOT NULL, `Owned` int(11) NOT NULL, `Owner` varchar(25) NOT NULL, `Value` int(11) NOT NULL, `InventoryItemID` varchar(1024) NOT NULL, `InventoryItemQuantity` varchar(1024) NOT NULL, `InventoryItemEx` varchar(1024) NOT NULL, `InventoryItemSerial` varchar(1024) NOT NULL, `Locked` int(11) NOT NULL, `Radio` int(11) NOT NULL, `TV` int(11) NOT NULL, `Class` int(11) NOT NULL, `gInterior` int(11) NOT NULL, `hgXo` float NOT NULL, `hgYo` float NOT NULL, `hgZo` float NOT NULL, `hgAo` float NOT NULL, `hgXi` float NOT NULL, `hgYi` float NOT NULL, `hgZi` float NOT NULL, `hgAi` float NOT NULL, `Garage` int(11) NOT NULL, `RentFee` int(11) NOT NULL, `Basic` int(11) NOT NULL, `Insurance` int(11) NOT NULL, `LockLvl` int(11) NOT NULL, `Alarm` int(11) NOT NULL, `FurnR` varchar(25) NOT NULL, `Bank` int(11) NOT NULL, `Code` int(11) NOT NULL, `Skins` varchar(128) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;


