[SQLITE] Spawns player at the center of the map.
#1

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?
Reply
#2

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

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)