Save position in MYSQL
#1

Can anyone help me making a code to save a position in MYSQL please?
Thanks
Reply
#2

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
Reply
#3

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..
Reply
#4

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...
Reply
#5

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"
Reply
#6

still need help =s
Reply
#7

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);
Reply
#8

I mean when i save it, it saves X:0 Y:0 Z:0
Reply
#9

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
Reply
#10

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 >.<
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)