MySQL House Not saving
#1

So my houses that i create won't save in my database, This is the line of Load And Saving houses...

Код:
stock SaveHouse(houseid)
{
	new string[2048];
	format(string, sizeof(string), "UPDATE `houses` SET \
		`Owned`=%d, \
		`Level`=%d, \
		`HInteriorWorld`=%d, \
		`Description`='%s', \
		`Owner`='%s', \
		`ExteriorX`=%f, \
		`ExteriorY`=%f, \
		`ExteriorZ`=%f, \
		`ExteriorR`=%f, \
		`InteriorX`=%f, \
		`InteriorY`=%f, \
		`InteriorZ`=%f, \
		`InteriorR`=%f,",
		HouseInfo[houseid][hOwned],
		HouseInfo[houseid][hLevel],
		HouseInfo[houseid][hHInteriorWorld],
		HouseInfo[houseid][hDescription],
		HouseInfo[houseid][hOwner],
		HouseInfo[houseid][hExteriorX],
		HouseInfo[houseid][hExteriorY],
		HouseInfo[houseid][hExteriorZ],
		HouseInfo[houseid][hExteriorR],
		HouseInfo[houseid][hInteriorX],
		HouseInfo[houseid][hInteriorY],
		HouseInfo[houseid][hInteriorZ],
		HouseInfo[houseid][hInteriorR]
	);

	format(string, sizeof(string), "%s \
		`Lock`=%d, \
		`Rentable`=%d, \
		`RentFee`=%d, \
		`Value`=%d, \
		`SafeMoney`=%d, \
		`Pot`=%d, \
		`Crack`=%d, \
		`Materials`=%d, \
		`Weapons0`=%d, \
		`Weapons1`=%d, \
		`Weapons2`=%d, \
		`Weapons3`=%d, \
		`Weapons4`=%d, \
		`GLUpgrade`=%d, \
		`CustomInterior`=%d, \
		`CustomExterior`=%d, \
		`ExteriorA`=%f, \
		`InteriorA`=%f WHERE `id`=%d",
		string,
		HouseInfo[houseid][hLock],
		HouseInfo[houseid][hRentable],
		HouseInfo[houseid][hRentFee],
		HouseInfo[houseid][hValue],
   		HouseInfo[houseid][hSafeMoney],
		HouseInfo[houseid][hPot],
		HouseInfo[houseid][hCrack],
		HouseInfo[houseid][hMaterials],
		HouseInfo[houseid][hWeapons][0],
		HouseInfo[houseid][hWeapons][1],
		HouseInfo[houseid][hWeapons][2],
		HouseInfo[houseid][hWeapons][3],
		HouseInfo[houseid][hWeapons][4],
		HouseInfo[houseid][hGLUpgrade],
		HouseInfo[houseid][hCustomInterior],
		HouseInfo[houseid][hCustomExterior],
		HouseInfo[houseid][hExteriorA],
		HouseInfo[houseid][hInteriorA],
		houseid+1
	); // Array starts from zero, MySQL starts at 1 (this is why we are adding one).

	mysql_function_query(MainPipeline, string, false, "OnQueryFinish", "i", SENDDATA_THREAD);
}

stock CreateHouse(houseid)
{
	new string[2048];
	format(string, sizeof(string), "INSERT INTO `houses` VALUES \
		`Owned`=%d, \
		`Level`=%d, \
		`HInteriorWorld`=%d, \
		`Description`='%s', \
		`Owner`='%s', \
		`ExteriorX`=%f, \
		`ExteriorY`=%f, \
		`ExteriorZ`=%f, \
		`ExteriorR`=%f, \
		`InteriorX`=%f, \
		`InteriorY`=%f, \
		`InteriorZ`=%f, \
		`InteriorR`=%f,",
		HouseInfo[houseid][hOwned],
		HouseInfo[houseid][hLevel],
		HouseInfo[houseid][hHInteriorWorld],
		HouseInfo[houseid][hDescription],
		HouseInfo[houseid][hOwner],
		HouseInfo[houseid][hExteriorX],
		HouseInfo[houseid][hExteriorY],
		HouseInfo[houseid][hExteriorZ],
		HouseInfo[houseid][hExteriorR],
		HouseInfo[houseid][hInteriorX],
		HouseInfo[houseid][hInteriorY],
		HouseInfo[houseid][hInteriorZ],
		HouseInfo[houseid][hInteriorR]
	);

	format(string, sizeof(string), "%s \
		`Lock`=%d, \
		`Rentable`=%d, \
		`RentFee`=%d, \
		`Value`=%d, \
		`SafeMoney`=%d, \
		`Pot`=%d, \
		`Crack`=%d, \
		`Materials`=%d, \
		`Weapons0`=%d, \
		`Weapons1`=%d, \
		`Weapons2`=%d, \
		`Weapons3`=%d, \
		`Weapons4`=%d, \
		`GLUpgrade`=%d, \
		`CustomInterior`=%d, \
		`CustomExterior`=%d, \
		`ExteriorA`=%f, \
		`InteriorA`=%f WHERE `id`=%d",
		string,
		HouseInfo[houseid][hLock],
		HouseInfo[houseid][hRentable],
		HouseInfo[houseid][hRentFee],
		HouseInfo[houseid][hValue],
   		HouseInfo[houseid][hSafeMoney],
		HouseInfo[houseid][hPot],
		HouseInfo[houseid][hCrack],
		HouseInfo[houseid][hMaterials],
		HouseInfo[houseid][hWeapons][0],
		HouseInfo[houseid][hWeapons][1],
		HouseInfo[houseid][hWeapons][2],
		HouseInfo[houseid][hWeapons][3],
		HouseInfo[houseid][hWeapons][4],
		HouseInfo[houseid][hGLUpgrade],
		HouseInfo[houseid][hCustomInterior],
		HouseInfo[houseid][hCustomExterior],
		HouseInfo[houseid][hExteriorA],
		HouseInfo[houseid][hInteriorA],
		houseid+1
	); // Array starts from zero, MySQL starts at 1 (this is why we are adding one).

	mysql_function_query(MainPipeline, string, false, "OnQueryFinish", "i", SENDDATA_THREAD);
}

stock SaveHouses()
{
	for(new i = 0; i < MAX_HOUSES; i++)
	{
		SaveHouse(i);
	}
	return 1;
}

stock LoadHouse(houseid)
{
	new string[128];
	printf("[LoadHouse] Loading HouseID %d's data from database...", houseid);
	format(string, sizeof(string), "SELECT * FROM `houses` WHERE `id`=%d",houseid+1); // Array starts at zero, MySQL starts at one.
	mysql_function_query(MainPipeline, string, true, "OnLoadHouse", "i", houseid);
}

forward OnLoadHouse(index);
public OnLoadHouse(index)
{
	new string[64];
	new rows, fields;
	cache_get_data(rows, fields, MainPipeline);

	for(new field;field<fields;field++)
	{
	    cache_get_row(index, field, string, MainPipeline);
		switch(field)
		{
		   	case 0:  HouseInfo[index][hSQLId] = strval(string);
			case 1:  HouseInfo[index][hOwned] = strval(string);
			case 2:  HouseInfo[index][hLevel] = strval(string);
			case 3:  HouseInfo[index][hHInteriorWorld] = strval(string);
			case 4:  format(HouseInfo[index][hDescription], 16, "%s", string);
			case 5:  format(HouseInfo[index][hOwner], 24, "%s", string);
			case 6:  HouseInfo[index][hExteriorX] = floatstr(string);
			case 7:  HouseInfo[index][hExteriorY] = floatstr(string);
			case 8:  HouseInfo[index][hExteriorZ] = floatstr(string);
			case 9:  HouseInfo[index][hExteriorR] = floatstr(string);
			case 10:  HouseInfo[index][hInteriorX] = floatstr(string);
			case 11: HouseInfo[index][hInteriorY] = floatstr(string);
			case 12: HouseInfo[index][hInteriorZ] = floatstr(string);
			case 13: HouseInfo[index][hInteriorR] = floatstr(string);
			case 14: HouseInfo[index][hLock] = strval(string);
			case 15: HouseInfo[index][hRentable] = strval(string);
			case 16: HouseInfo[index][hRentFee] = strval(string);
			case 17: HouseInfo[index][hValue] = strval(string);
			case 18: HouseInfo[index][hSafeMoney] = strval(string);
			case 19: HouseInfo[index][hPot] = strval(string);
			case 20: HouseInfo[index][hCrack] = strval(string);
			case 21: HouseInfo[index][hMaterials] = strval(string);
			case 22: HouseInfo[index][hWeapons][0] = strval(string);
			case 23: HouseInfo[index][hWeapons][1] = strval(string);
			case 24: HouseInfo[index][hWeapons][2] = strval(string);
			case 25: HouseInfo[index][hWeapons][3] = strval(string);
			case 26: HouseInfo[index][hWeapons][4] = strval(string);
			case 27: HouseInfo[index][hGLUpgrade] = strval(string);
			case 28: HouseInfo[index][hPickupID] = strval(string);
			case 29: HouseInfo[index][hCustomInterior] = strval(string);
			case 30: HouseInfo[index][hCustomExterior] = strval(string);
			case 31: HouseInfo[index][hExteriorA] = floatstr(string);
			case 32: HouseInfo[index][hInteriorA] = floatstr(string);
		}
	}
	if(HouseInfo[index][hOwned]) {
		if(!HouseInfo[index][hRentable]) format(string, sizeof(string), "This house is owned by\n%s\nLevel: %d\nID: %d",HouseInfo[index][hOwner], HouseInfo[index][hLevel], index);
		else format(string, sizeof(string), "This house is owned by\n%s\nRent: $%d\nLevel: %d\nID: %d\nType /rentroom to rent a room", HouseInfo[index][hOwner], HouseInfo[index][hRentFee], HouseInfo[index][hLevel], index);
	}
	else format(string, sizeof(string), "This house is\n for sale!\n Description: %s\nCost: $%d\n Level: %d\nID: %d\nTo buy this house type /buyhouse",HouseInfo[index][hDescription],HouseInfo[index][hValue],HouseInfo[index][hLevel],index);

	HouseInfo[index][hPickupID] = CreatePickupEx(1273, 23, HouseInfo[index][hExteriorX], HouseInfo[index][hExteriorY], HouseInfo[index][hExteriorZ]);
	HouseInfo[index][hTextID] = CreateDynamic3DTextLabel(string, COLOR_GREEN, HouseInfo[index][hExteriorX], HouseInfo[index][hExteriorY], HouseInfo[index][hExteriorZ]+0.5,10.0, .testlos = 1, .streamdistance = 10.0);
	return 1;
}

stock LoadHouses()
{
	printf("[LoadHouses] Loading data from database...");
	mysql_function_query(MainPipeline, "SELECT * FROM `houses`", true, "OnLoadHouses", "");
}

forward OnLoadHouses();
public OnLoadHouses()
{
	new string[512], iIndex;
	new rows, fields;
	cache_get_data(rows, fields, MainPipeline);
	while(iIndex<rows)
	{
	    for(new field;field<fields;field++)
	    {
 		    cache_get_row(iIndex, field, string, MainPipeline);
			switch(field)
			{
			    case 0:  HouseInfo[iIndex][hSQLId] = strval(string);
				case 1:  HouseInfo[iIndex][hOwned] = strval(string);
				case 2:  HouseInfo[iIndex][hLevel] = strval(string);
				case 3:  HouseInfo[iIndex][hHInteriorWorld] = strval(string);
				case 4:  format(HouseInfo[iIndex][hDescription], 16, "%s", string);
				case 5:  format(HouseInfo[iIndex][hOwner], 24, "%s", string);
				case 6:  HouseInfo[iIndex][hExteriorX] = floatstr(string);
				case 7:  HouseInfo[iIndex][hExteriorY] = floatstr(string);
				case 8:  HouseInfo[iIndex][hExteriorZ] = floatstr(string);
				case 9:  HouseInfo[iIndex][hExteriorR] = floatstr(string);
				case 10:  HouseInfo[iIndex][hInteriorX] = floatstr(string);
				case 11: HouseInfo[iIndex][hInteriorY] = floatstr(string);
				case 12: HouseInfo[iIndex][hInteriorZ] = floatstr(string);
				case 13: HouseInfo[iIndex][hInteriorR] = floatstr(string);
				case 14: HouseInfo[iIndex][hLock] = strval(string);
				case 15: HouseInfo[iIndex][hRentable] = strval(string);
				case 16: HouseInfo[iIndex][hRentFee] = strval(string);
				case 17: HouseInfo[iIndex][hValue] = strval(string);
				case 18: HouseInfo[iIndex][hSafeMoney] = strval(string);
				case 19: HouseInfo[iIndex][hPot] = strval(string);
				case 20: HouseInfo[iIndex][hCrack] = strval(string);
				case 21: HouseInfo[iIndex][hMaterials] = strval(string);
				case 22: HouseInfo[iIndex][hWeapons][0] = strval(string);
				case 23: HouseInfo[iIndex][hWeapons][1] = strval(string);
				case 24: HouseInfo[iIndex][hWeapons][2] = strval(string);
				case 25: HouseInfo[iIndex][hWeapons][3] = strval(string);
				case 26: HouseInfo[iIndex][hWeapons][4] = strval(string);
				case 27: HouseInfo[iIndex][hGLUpgrade] = strval(string);
				case 28: HouseInfo[iIndex][hPickupID] = strval(string);
				case 29: HouseInfo[iIndex][hCustomInterior] = strval(string);
				case 30: HouseInfo[iIndex][hCustomExterior] = strval(string);
				case 31: HouseInfo[iIndex][hExteriorA] = floatstr(string);
				case 32: HouseInfo[iIndex][hInteriorA] = floatstr(string);
			}
		}
		if(HouseInfo[iIndex][hOwned]) {

		if(!HouseInfo[iIndex][hRentable]) format(string, sizeof(string), "This house is owned by\n%s\nLevel: %d\nID: %d",HouseInfo[iIndex][hOwner], HouseInfo[iIndex][hLevel], iIndex);
			else format(string, sizeof(string), "This house is owned by\n%s\nRent: $%d\nLevel: %d\nID: %d\nType /rentroom to rent a room", HouseInfo[iIndex][hOwner], HouseInfo[iIndex][hRentFee], HouseInfo[iIndex][hLevel], iIndex);
		}
		else format(string, sizeof(string), "This house is\n for sale!\n Description: %s\nCost: $%d\n Level: %d\nID: %d\nTo buy this house type /buyhouse",HouseInfo[iIndex][hDescription],HouseInfo[iIndex][hValue],HouseInfo[iIndex][hLevel],iIndex);

		HouseInfo[iIndex][hPickupID] = CreatePickupEx(1273, 23, HouseInfo[iIndex][hExteriorX], HouseInfo[iIndex][hExteriorY], HouseInfo[iIndex][hExteriorZ]);
		HouseInfo[iIndex][hTextID] = CreateDynamic3DTextLabel(string, COLOR_GREEN, HouseInfo[iIndex][hExteriorX], HouseInfo[iIndex][hExteriorY], HouseInfo[iIndex][hExteriorZ]+0.5,10.0, .testlos = 1, .streamdistance = 10.0);
  		iIndex++;
 	}
	if(iIndex > 0) printf("[LoadHouses] %d houses rehashed/loaded.", iIndex);
	else printf("[LoadHouses] Failed to load any houses.");
	return 1;
}
And this is my database SQL

Код:
-- ----------------------------
-- Table structure for `houses`
-- ----------------------------
DROP TABLE IF EXISTS `houses`;
CREATE TABLE `houses` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `Owned` int(11) NOT NULL DEFAULT '0',
  `Level` int(11) NOT NULL DEFAULT '999',
  `HInteriorWorld` int(11) NOT NULL DEFAULT '9',
  `Description` varchar(16) NOT NULL DEFAULT 'High',
  `Owner` varchar(24) NOT NULL DEFAULT 'No-Owner',
  `ExteriorX` float(10,5) NOT NULL DEFAULT '0.00000',
  `ExteriorY` float(10,5) NOT NULL DEFAULT '0.00000',
  `ExteriorZ` float(10,5) NOT NULL DEFAULT '0.00000',
  `ExteriorR` float(10,5) NOT NULL DEFAULT '0.00000',
  `InteriorX` float(10,5) NOT NULL DEFAULT '0.00000',
  `InteriorY` float(10,5) NOT NULL DEFAULT '0.00000',
  `InteriorZ` float(10,5) NOT NULL DEFAULT '0.00000',
  `InteriorR` float(10,5) NOT NULL DEFAULT '0.00000',
  `Lock` int(11) NOT NULL DEFAULT '0',
  `Rentable` int(11) NOT NULL DEFAULT '0',
  `RentFee` int(11) NOT NULL DEFAULT '0',
  `Value` int(11) NOT NULL DEFAULT '0',
  `SafeMoney` int(11) NOT NULL DEFAULT '0',
  `Pot` int(11) NOT NULL DEFAULT '0',
  `Crack` int(11) NOT NULL DEFAULT '0',
  `Materials` int(11) NOT NULL DEFAULT '0',
  `Weapons0` int(11) NOT NULL DEFAULT '0',
  `Weapons1` int(11) NOT NULL DEFAULT '0',
  `Weapons2` int(11) NOT NULL DEFAULT '0',
  `Weapons3` int(11) NOT NULL DEFAULT '0',
  `Weapons4` int(11) NOT NULL DEFAULT '0',
  `GLUpgrade` int(11) NOT NULL DEFAULT '0',
  `PickupID` int(11) NOT NULL DEFAULT '0',
  `CustomInterior` int(11) NOT NULL DEFAULT '0',
  `CustomExterior` int(11) NOT NULL DEFAULT '0',
  `ExteriorA` float(10,5) NOT NULL DEFAULT '0.00000',
  `InteriorA` float(10,5) NOT NULL DEFAULT '0.00000',
  PRIMARY KEY (`id`),
  KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

-- ----------------------------
-- Records of houses
-- ----------------------------
Reply
#2

pawn Код:
stock SaveHouse(houseid)
{
    new string[2048];
    format(string, sizeof(string), "UPDATE `houses` SET \
        `Owned`=%d, \
        `Level`=%d, \
        `HInteriorWorld`=%d, \
        `Description`='%s', \
        `Owner`='%s', \
        `ExteriorX`=%f, \
        `ExteriorY`=%f, \
        `ExteriorZ`=%f, \
        `ExteriorR`=%f, \
        `InteriorX`=%f, \
        `InteriorY`=%f, \
        `InteriorZ`=%f, \
        `InteriorR`=%f,"
,
        HouseInfo[houseid][hOwned],
        HouseInfo[houseid][hLevel],
        HouseInfo[houseid][hHInteriorWorld],
        HouseInfo[houseid][hDescription],
        HouseInfo[houseid][hOwner],
        HouseInfo[houseid][hExteriorX],
        HouseInfo[houseid][hExteriorY],
        HouseInfo[houseid][hExteriorZ],
        HouseInfo[houseid][hExteriorR],
        HouseInfo[houseid][hInteriorX],
        HouseInfo[houseid][hInteriorY],
        HouseInfo[houseid][hInteriorZ],
        HouseInfo[houseid][hInteriorR]
    );

    format(string, sizeof(string), "%s \
        `Lock`=%d, \
        `Rentable`=%d, \
        `RentFee`=%d, \
        `Value`=%d, \
        `SafeMoney`=%d, \
        `Pot`=%d, \
        `Crack`=%d, \
        `Materials`=%d, \
        `Weapons0`=%d, \
        `Weapons1`=%d, \
        `Weapons2`=%d, \
        `Weapons3`=%d, \
        `Weapons4`=%d, \
        `GLUpgrade`=%d, \
        `CustomInterior`=%d, \
        `CustomExterior`=%d, \
        `ExteriorA`=%f, \
        `InteriorA`=%f WHERE `id`=%d"
,
        string,
        HouseInfo[houseid][hLock],
        HouseInfo[houseid][hRentable],
        HouseInfo[houseid][hRentFee],
        HouseInfo[houseid][hValue],
        HouseInfo[houseid][hSafeMoney],
        HouseInfo[houseid][hPot],
        HouseInfo[houseid][hCrack],
        HouseInfo[houseid][hMaterials],
        HouseInfo[houseid][hWeapons][0],
        HouseInfo[houseid][hWeapons][1],
        HouseInfo[houseid][hWeapons][2],
        HouseInfo[houseid][hWeapons][3],
        HouseInfo[houseid][hWeapons][4],
        HouseInfo[houseid][hGLUpgrade],
        HouseInfo[houseid][hCustomInterior],
        HouseInfo[houseid][hCustomExterior],
        HouseInfo[houseid][hExteriorA],
        HouseInfo[houseid][hInteriorA],
        houseid+1
    ); // Array starts from zero, MySQL starts at 1 (this is why we are adding one).
You have to use strcat https://sampwiki.blast.hk/wiki/Strcat ('This function concatenates (joins together) two strings into the destination reference.') instead of two times format.

example

pawn Код:
new savestring[1000], string[1000]; // Random string size, adjust to your needs.

strcat(string, "UPDATE `houses` SET \
        `Owned`=%d, \
        `Level`=%d, \
        `HInteriorWorld`=%d, \
        `Description`='%s', \
        `Owner`='%s', \
        `ExteriorX`=%f, \
        `ExteriorY`=%f, \
        `ExteriorZ`=%f, \
        `ExteriorR`=%f, \
        `InteriorX`=%f, \
        `InteriorY`=%f, \
        `InteriorZ`=%f, \
        `InteriorR`=%f,"
, sizeof(string));

strcat(string, "`Lock`=%d, \
        `Rentable`=%d, \
        `RentFee`=%d, \
        `Value`=%d, \
        `SafeMoney`=%d, \
        `Pot`=%d, \
        `Crack`=%d, \
        `Materials`=%d, \
        `Weapons0`=%d, \
        `Weapons1`=%d, \
        `Weapons2`=%d, \
        `Weapons3`=%d, \
        `Weapons4`=%d, \
        `GLUpgrade`=%d, \
        `CustomInterior`=%d, \
        `CustomExterior`=%d, \
        `ExteriorA`=%f, \
        `InteriorA`=%f WHERE `id`=%d"
, sizeof(string));

format(savestring, sizeof(savestring), string, HouseInfo[houseid][hOwned],
        HouseInfo[houseid][hLevel],
        HouseInfo[houseid][hHInteriorWorld],
        HouseInfo[houseid][hDescription],
        HouseInfo[houseid][hOwner],
        HouseInfo[houseid][hExteriorX],
        HouseInfo[houseid][hExteriorY],
        HouseInfo[houseid][hExteriorZ],
        HouseInfo[houseid][hExteriorR],
        HouseInfo[houseid][hInteriorX],
        HouseInfo[houseid][hInteriorY],
        HouseInfo[houseid][hInteriorZ],
        HouseInfo[houseid][hInteriorR],
                HouseInfo[houseid][hLock],
        HouseInfo[houseid][hRentable],
        HouseInfo[houseid][hRentFee],
        HouseInfo[houseid][hValue],
        HouseInfo[houseid][hSafeMoney],
        HouseInfo[houseid][hPot],
        HouseInfo[houseid][hCrack],
        HouseInfo[houseid][hMaterials],
        HouseInfo[houseid][hWeapons][0],
        HouseInfo[houseid][hWeapons][1],
        HouseInfo[houseid][hWeapons][2],
        HouseInfo[houseid][hWeapons][3],
        HouseInfo[houseid][hWeapons][4],
        HouseInfo[houseid][hGLUpgrade],
        HouseInfo[houseid][hCustomInterior],
        HouseInfo[houseid][hCustomExterior],
        HouseInfo[houseid][hExteriorA],
        HouseInfo[houseid][hInteriorA],
        houseid+1
    );
Take a better look on them and I'm sure you can make them work.
Reply
#3

Still no Luck
Reply
#4

As I told you, look closer to your code, even a single comma matters. If you don't see tables created in your database, check your table creation for typos again.
Reply
#5

I suggest changing file system to y_ini as MySQL really sux , personal experience with me.
Reply
#6

I suggest you still using MySQL, MySQL is better than Y_INI/Dini/.......... Fast and you can use it in everywhere.
Reply
#7

Still it won't create the tabels? idk whats wrong and i am not that good of a scripter?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)