Save position in MYSQL -
Stefans94 - 01.07.2011
Can anyone help me making a code to save a position in MYSQL please?
Thanks
Re: Save position in MYSQL -
Sascha - 01.07.2011
pawn Код:
new Float:x, Float:y, Float:z, query[200];
GetPlayerPos(playerid, x, y, z);
format(query, sizeof(query), "INSERT INTO `positions` (`x`, `y`, `z`) VALUES (%f, %f, %f)", x, y, z);
mysql_query(query);
NOTE: edit the "positions" to your db table name... and add the "float" value to the table rows..
edit: to update a certain row
pawn Код:
new Float:x, Float:y, Float:z, query[250], name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
GetPlayerPos(playerid, x, y, z);
format(query, sizeof(query), "UPDATE `positions` SET `x`=%f AND `y`=%f AND `z`=%f WHERE `name`='%s'", x, y, z, name);
mysql_query(query);
^ This would update the positions of a certain name.. you can ofc also use IDs or w/e
-
Stefans94 - 01.07.2011
Thanks
Still 1 problem, if i use float, in my mysql db, it just says "0"
so
X, Float, 0
if i use varchar, nothing happens..
Re: Save position in MYSQL -
Sascha - 01.07.2011
yea 'cause 0.00000 is the same as 0
if you use 0.12356 then it willbe 0.123456..
and a varchar is not a float.. so just use float...
Re: Save position in MYSQL -
Stefans94 - 01.07.2011
Quote:
Originally Posted by Sascha
yea 'cause 0.00000 is the same as 0
if you use 0.12356 then it willbe 0.123456..
and a varchar is not a float.. so just use float...
|
it's not 0. ... it's just "0" nothing else, for the x, y and z just "0"
Re: Save position in MYSQL -
Stefans94 - 01.07.2011
still need help =s
Re: Save position in MYSQL -
Sascha - 01.07.2011
you mean when you get the position with mysql_fetch_field("x", string);?
if so, then use something like this:
pawn Код:
new tmp[50], Float:x;
mysql_fetch_field("x", tmp); x = floatstr(tmp);
Re: Save position in MYSQL -
Stefans94 - 01.07.2011
I mean when i save it, it saves X:0 Y:0 Z:0
Re: Save position in MYSQL -
Sascha - 01.07.2011
then you've probably either used a wrong "symbol" in the string or didn't get the position correctly..
be sure to use "GetPlayerPos(playierid, x, y, z);" before formatting the string
and in the string use %f as variable
Re: Save position in MYSQL -
Stefans94 - 01.07.2011
I have this in OnPlayerDisconnect
Код:
new Float:x, Float:y, Float:z, Query[250], name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
GetPlayerPos(playerid, x, y, z);
format(Query, sizeof(Query), "UPDATE `playerinfo` SET `x`= '%f' AND `y`= '%f' AND `z`= '%f' WHERE `name`='%s'", x, y, z, name);
mysql_query(Query);
mysql_free_result();
It just saves like 0 0 and 0
fields:
x type float
y type float
z type float
i'm sorry for all this XD but it just wont work, samp server hates me >.<