Position saving when exiting isnt working
#1

As the title says, I have made a MySQL base and it doesn't save the position for the player. What I mean by this ? When a player connects to the server and plays a bit then exits the game, when he re-connects he should be spawned at the position he quit . But.. its not working.

These are my codes:


PHP код:
#define    SPAWN_X  10.0
#define    SPAWN_Y  10.0
#define    SPAWN_Z  14.0
#define    SPAWN_A  0.0 
PHP код:
enum PlayerData
{
    
ID,
    
Name[MAX_PLAYER_NAME],
    
Password[129],
    
IP[16],
    
Admin,
    
Tester,
    
Money,
    
Float:posX,
    
Float:posY,
    
Float:posZ,
    
Float:posA
}; 
PHP код:
public OnPlayerDisconnect(playeridreason)
{
    new 
query[128], Float:pos[4];
    
GetPlayerPos(playeridpos[0], pos[1], pos[2]);
    
GetPlayerFacingAngle(playeridpos[3]);
    
mysql_format(1querysizeof(query), "UPDATE `accounts` SET `Money` = %d, `PosX` = %f, `PosY` = %f, `PosZ` = %f, `PosA` = %f WHERE `ID` = %d",
    
GetPlayerMoney(playerid), pos[0], pos[1], pos[2], pos[3], Player[playerid][ID]);
    
mysql_tquery(1query"""");
    return 
1;

PHP код:
forward OnAccountLoad(playerid);
public 
OnAccountLoad(playerid)
{
    
Player[playerid][Admin] = cache_get_field_content_int(0"Admin");
    
Player[playerid][VIP] = cache_get_field_content_int(0"Tester");
    
Player[playerid][Money] = cache_get_field_content_int(0"Money");
    
Player[playerid][posX] = cache_get_field_content_float(0"PosX");
    
Player[playerid][posY] = cache_get_field_content_float(0"PosY");
    
Player[playerid][posZ] = cache_get_field_content_float(0"PosZ");
    
Player[playerid][posA] = cache_get_field_content_float(0"PosA");
    
TogglePlayerSpectating(playeridfalse);
    
GivePlayerMoney(playeridPlayer[playerid][Money]);
    
SetSpawnInfo(playerid023Player[playerid][posX], Player[playerid][posY], Player[playerid][posZ], Player[playerid][posA], 000000);
    
SpawnPlayer(playerid);
    
SendClientMessage(playerid, -1"Te-ai logat cu succes !");
    return 
1;

This is everything that saves the position and some more things, can someone please help me and explain me why isn't working ?
Reply
#2

Nevermind.. I'm such an idiot, now it works.
Reply
#3

PHP код:
enum PlayerData
{
    
ID,
    
Name[MAX_PLAYER_NAME],
    
bool:pSpawned// Will check if player is spawned then true if not then false
    
Password[129],
    
IP[16],
    
Admin,
    
Tester,
    
Money,
    
Float:posX,
    
Float:posY,
    
Float:posZ,
    
Float:posA
};
new 
Player[MAX_PLAYERS][PlayerData]; 
PHP код:
public OnPlayerSpawn(playerid)
{
    if(
Player[playerid][pSpawned]== false// Checking if he was spawned already
    
{
        
SetPlayerPos(playerid,Player[playerid][posX],Player[playerid][posY],Player[playerid][posZ]);
        
SetPlayerFacingAngle(playeridPlayer[playerid][posA]);
        
Player[playerid][pSpawned]= true// true so he wont respawn on the same position after each death
    
}
    return 
1;

PHP код:
public OnPlayerConnect(playerid)
{
    
Player[playerid][pSpawned]= false// False to reset player's variable before he logs in to mysql
    
return 1;

PHP код:
public OnPlayerDisconnect(playeridreason)
{
    new 
query[128], Float:pos[4];
    
GetPlayerPos(playeridpos[0], pos[1], pos[2]);
    
GetPlayerFacingAngle(playeridpos[3]);
    
mysql_format(1querysizeof(query), "UPDATE `accounts` SET `Money` = %d, `PosX` = %f, `PosY` = %f, `PosZ` = %f, `PosA` = %f WHERE `ID` = %d",
    
GetPlayerMoney(playerid), pos[0], pos[1], pos[2], pos[3], Player[playerid][ID]);
    
mysql_tquery(1query"""");
    
Player[playerid][pSpawned]= false// False to reset player's variable before he disconnects
    
return 1;

PHP код:
forward OnAccountLoad(playerid);
public 
OnAccountLoad(playerid)
{
    
Player[playerid][Admin] = cache_get_field_content_int(0"Admin");
    
Player[playerid][VIP] = cache_get_field_content_int(0"Tester");
    
Player[playerid][Money] = cache_get_field_content_int(0"Money");
    
Player[playerid][posX] = cache_get_field_content_float(0"PosX");
    
Player[playerid][posY] = cache_get_field_content_float(0"PosY");
    
Player[playerid][posZ] = cache_get_field_content_float(0"PosZ");
    
Player[playerid][posA] = cache_get_field_content_float(0"PosA");
    
TogglePlayerSpectating(playeridfalse);
    
GivePlayerMoney(playeridPlayer[playerid][Money]);
    
SetSpawnInfo(playerid023Player[playerid][posX], Player[playerid][posY], Player[playerid][posZ], Player[playerid][posA], 000000);
    
SpawnPlayer(playerid);
    
SendClientMessage(playerid, -1"Te-ai logat cu succes !");
    return 
1;

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)