SA-MP Forums Archive
How to get the X, Y, Z floats and set the players position? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: How to get the X, Y, Z floats and set the players position? (/showthread.php?tid=149838)



How to get the X, Y, Z floats and set the players position? - NewTorran - 23.05.2010

Hi,

Im using G-Stylez (I dont know his name so im going to put that) MySQL plugin.
And i have a table on my database with 3 fields, X, Y & ofc Z
How would i get all three coordinates and set the players position to the X, Y, Z, it got?


Re: How to get the X, Y, Z floats and set the players position? - dice7 - 23.05.2010

You'll need to learn SQL

http://www.w3schools.com/sql/default.asp


Re: How to get the X, Y, Z floats and set the players position? - NewTorran - 23.05.2010

Quote:
Originally Posted by dice7
I know the basic bit, Like how to get one thing, But not all three at once


Re: How to get the X, Y, Z floats and set the players position? - Joe Staff - 23.05.2010

Assuming you've set the 3 fields to be 'Floats' and not 'Ints' then it should go like this

You'd save it like this
pawn Код:
new Float:x,Float:y,Float:z,query[64],pname[24];
GetPlayerPos(playerid,x,y,z);
GetPlayerName(playerid,pname,24);
format(query,64,"SELECT * FROM Table WHERE Name='%s' LIMIT 1",pname); //Check to make sure if the row already exists
mysql_query(query);
mysql_store_result();
if(mysql_num_rows()) //Row exists
{
  format(query,64,"UPDATE Table SET X='%f', Y='%f', Z='%f' WHERE Name='%s'",x,y,z,pname);
}else{ //Row doesn't exist
  format(query,64,"INSERT INTO Table (X,Y,Z,Name) VALUES('%f','%f','%f','%s')",x,y,z,pname);
}
mysql_query(query);
To load it you'll need some way to parse the information, using sscanf or the split function will work


Re: How to get the X, Y, Z floats and set the players position? - Miguel - 23.05.2010

Quote:
Originally Posted by Joe Staff
To load it you'll need some way to parse the information, using sscanf or the split function will work
mysql_retrieve_row() for the win!