SA-MP Forums Archive
[SQLITE] Spawns player at the center of the map. - 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)
+--- Thread: [SQLITE] Spawns player at the center of the map. (/showthread.php?tid=617776)



[SQLITE] Spawns player at the center of the map. - ChristolisTV - 26.09.2016

I want when a player spawns it sets his/her position from database fields: X, Y, Z, but instead it goes into the center of the map. Here is what I tried.

PHP код:
public OnPlayerSpawn(playerid)
{
    new
        
Query[250],
        
DBResultResult,
        
pName[250],
        
Field[20],
        
Floatx,
        
Floaty,
        
Floatz
    
;
    
GetPlayerName(playeridpNamesizeof(pName));
    
    
format(Querysizeof(Query), "SELECT * FROM `Accounts` WHERE Name = '%s'"pName);
    
Result db_query(DatabaseQuery);
    
    
db_get_field_assoc(Result"X"Field30);
    
db_get_field_assoc(Result"Y"Field30);
    
db_get_field_assoc(Result"Z"Field30);
    
    
SetPlayerPos(playeridxyz);
    
db_free_result(Result);
     return 
1;    

Can you help me please?


Re: [SQLITE] Spawns player at the center of the map. - TheDarkBlade - 26.09.2016

Try to use printf to print into the console the spawn locations
so add printf("%f,%f,%f",X,Y,Z) or how are your cordonates named


Re: [SQLITE] Spawns player at the center of the map. - ChristolisTV - 26.09.2016

Quote:
Originally Posted by TheDarkBlade
Посмотреть сообщение
Try to use printf to print into the console the spawn locations
so add printf("%f,%f,%f",X,Y,Z) or how are your cordonates named
Do you mean format()? How to put the coordinates on SetPlayerPos()? Can you show me code I want to understand it a little bit.


Re: [SQLITE] Spawns player at the center of the map. - Konstantinos - 26.09.2016

Is the position saved when a player disconnects? If yes, if a player timeouts/crashes then GetPlayerPos will fail and the coordinates returned will be 0.0 for all x, y and z. A workaround is to check if the reason in OnPlayerDisconnect is 2 and not get the position (their last saved will be used instead).

When a player logins, store the coordinates to a global array and in OnPlayerSpawn you can set the position without executing a query to retrieve them every time. If the value in these coordinates is 0.0, spawn them somewhere else (default position).