Mysql FLOAT cant go more than 6 characters... -
Blademaster680 - 05.09.2014
Hi
I am trying to save the position of a house I create, but the house is not were
the player is standing were he creates it. The house is a metre or so away from
hi.
Here is a picture:
Here is a picture of the database:
See? In the pos columns it is limited to 6 characters, and dont know how to change that...
If there are more than 6 characters in the float, then it rounds off the 7th digit
and changes the last digit, thats why my houses are not in the right place...
Please help, How do I increase the max characters?
Re: Mysql FLOAT cant go more than 6 characters... -
Wizzy951 - 05.09.2014
I assume posting the code of the query that saves the houses will let us help you.
Re: Mysql FLOAT cant go more than 6 characters... -
IstuntmanI - 05.09.2014
It's not caused by MySQL, but by your script. Make sure that you don't have any GetXYInFrontOfPlayer after creating the pickup, or something like that. There's nothing wrong with MySQL. Show us the code where you create/load the house.
Re: Mysql FLOAT cant go more than 6 characters... -
Blademaster680 - 06.09.2014
Код:
CMD:housecreate(playerid, params[])
{
new Query[500], amount, level, rows, fields, houseid = 0, str[150];
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You are not authorised to use that command.");
if(sscanf(params, "id", level, amount)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /housecreate [level] [price]");
new Float: x, Float: y, Float: z;
new Float: ix, Float: iy, Float: iz;
GetPlayerPos(playerid, x, y, z);
ix = 2259.5205; iy = -1135.9044; iz = 1050.6328;
if(level == 1)
{
strcat(Query,"INSERT INTO `houses`(`ID`, `Owner`, `Level`, `Price`,`PosX`,`PosY`,`PosZ`, `IPosX`, `IPosY`, `IPosZ`, `Interior`, `VirtualWorld`)");
strcat(Query," VALUES (NULL, '%s', '%d', '%d', '%f', '%f', '%f', '%f', '%f', '%f', 10, 0)");
mysql_format(dbHandle, Query, sizeof(Query), Query, "Server", level, amount, x, y, z, ix+1, iy, iz);
mysql_query(dbHandle, Query, false);
for(new i = 0; i<= MAX_HOUSES; i++)
{
mysql_format(dbHandle,Query, sizeof(Query), "SELECT * FROM `Houses` WHERE `ID` = '%d'", i);
mysql_query(dbHandle,Query);
cache_get_data(rows, fields);
if(rows)
{
houseid = i;
}
}
Load_House(houseid);
format(str, sizeof(str), "Created house ID: %i", houseid);
SendClientMessage(playerid, COLOR_GREY, str);
format(str, sizeof(str), "PosX: %f | PosY: %f | PosZ: %f", x, y, z);
SendClientMessage(playerid, COLOR_GREY, str);
}
return 1;
}
At first I thought it was the code also, but the code is right... It has something that is limiting the max characters I think
Re: Mysql FLOAT cant go more than 6 characters... -
IstuntmanI - 06.09.2014
It looks good (a little weird formatted, but still good). The house is fine after /housecreate ? If not, after restarting the server (when loading from database) the house is fine ?
Re: Mysql FLOAT cant go more than 6 characters... -
BroZeus - 06.09.2014
Looks like there was a mistake while creating Float varaibles
run these querries --
pawn Код:
//-----query 1
ALTER TABLE `houses` DROP COLUMN `PosX`,
DROP COLUMN `PosY`,
DROP COLUMN `PosZ`,
DROP COLUMN `IPosX`,
DROP COLUMN `IPosY`,
DROP COLUMN `IPosZ;
//--------query 2
ALTER TABLE `houses`
ADD(`PosX` FLOAT(10,10),
`PosY` FLOAT(10,10),
`PosZ`FLOAT(10,10),
`IPosX` FLOAT(10,10),
`IPosY` FLOAT(10,10),
`IPosZ` FLOAT(10,10);
FLOAT(10,10) is the key here...
Re: Mysql FLOAT cant go more than 6 characters... -
Blademaster680 - 06.09.2014
Quote:
Looks like there was a mistake while creating Float varaibles
run these querries --
pawn Code:
//-----query 1
ALTER TABLE `houses` DROP COLUMN `PosX`,
DROP COLUMN `PosY`,
DROP COLUMN `PosZ`,
DROP COLUMN `IPosX`,
DROP COLUMN `IPosY`,
DROP COLUMN `IPosZ;
//--------query 2
ALTER TABLE `houses`
ADD(`PosX` FLOAT(10,10),
`PosY` FLOAT(10,10),
`PosZ`FLOAT(10,10),
`IPosX` FLOAT(10,10),
`IPosY` FLOAT(10,10),
`IPosZ` FLOAT(10,10);
FLOAT(10,10) is the key here...
|
Ok I did that and it seems to have fixed the digit limit, but the positions are somehow being set to 1.0000000.
and I cant even change them in the database...
Any clue to how this could be fixed?
Re: Mysql FLOAT cant go more than 6 characters... -
BroZeus - 07.09.2014
Just make houses again
Re: Mysql FLOAT cant go more than 6 characters... -
Vince - 07.09.2014
MySQL stores floating point values with a high precision by default (up to 12 decimal places, I think), far more than what is used by the game (usually no more than 4). The results in phpMyAdmin are usually truncated to 6 characters for readability, but if you run a query like
PHP код:
SELECT posx+0, posy+0, posz+0 ...
then the entire number will be displayed.
Re: Mysql FLOAT cant go more than 6 characters... -
Blademaster680 - 07.09.2014
I did create the house again... It still had the exact same problem, but their were more characters in the FLOATS.
But the house still isn't saving in the right location...