[MySQL]Player Spawn info not saving
#1

well as title says player spawn info is not being saved...
i mean when i /q it dont save or update the last location on database it still stays at 0 as default position why?
i tried debugging most of parts and everything responded good...
tell me which part of script i should show to let you get more info...
Thanks...
Reply
#2

Any one there?
Reply
#3

I can't help you here more as I can't see the code, however here is the main debugging test I want you to try.

Make a command called "/SaveMyAccount", run the command DON'T quit. Does it still contain 0, 0, 0, for the player position?

If yes, your saving is bugged post your code.
If no, your getting the position too late in your save procedure... fix it yourself or show code.

Also position should be one of the high priority things to save, therefore get this information and store it first or atleast format it into a string first. I suggest this as if it's one of the last things saved it could be the player has gone already and getting a position from a player that's gone... well it's 0, 0, 0.. A.K.A NULL.
Reply
#4

i used it to update player spawn info into database....and using this as a function in OnPlayerDisconnect to update player spawn information...
PHP код:
PlayerAccountUpdate(playeridreason)
{
    if (
PINFO[playerid][Plogged] == false) return 0;
    if (
reason == 1)
    {
        
GetPlayerPos(playeridPINFO[playerid][SpawnPX], PINFO[playerid][SpawnPY], PINFO[playerid][SpawnPZ]);
        
GetPlayerFacingAngle(playeridPINFO[playerid][SpawnPA]);
    }    
    new 
query[150];
    
mysql_format(ConHandlerquerysizeof query"UPDATE `playerdata` SET `SpawnPosX` = %f, `SpawnPosY` = %f, `SpawnPosZ` = %f, `SpawnPosA` = %f, `Interior` = %d WHERE `ID` = %d LIMIT 1"PINFO[playerid][SpawnPX], PINFO[playerid][SpawnPY], PINFO[playerid][SpawnPZ], PINFO[playerid][SpawnPA], GetPlayerInterior(playerid), PINFO[playerid][ID]);
    
mysql_tquery(ConHandlerquery);
    return 
1;

BTW can it be possible to delay player /q so that it should update first?
or something else is wrong..
PS:I wanted to ask is there anyway possible too that to create a function or so which will automatically save player data every minute and will that be good for it or not?
Reply
#5

GetPlayer functions is not called when a player disconnects. And yes, you could create a variable where you update his co-ordinates every seconds.

EDIT ;

Example:

PHP код:
forward PosSaving(playerid);
new 
PosSavingTimer[MAX_PLAYERS];
public 
OnPlayerSpawn(playerid)
{
    
PosSavingTimer[playerid] = SetTimerEx("PosSaving"1000false"i"playerid); // Ticks every seconds
    
return 1;
}
public 
OnPlayerDisconnect(playeridreason)
{
    if (
PINFO[playerid][Plogged] == false) return 0;  
    new 
query[150]; 
    
mysql_format(ConHandlerquerysizeof query"UPDATE `playerdata` SET `SpawnPosX` = %f, `SpawnPosY` = %f, `SpawnPosZ` = %f, `SpawnPosA` = %f, `Interior` = %d WHERE `ID` = %d LIMIT 1"PINFO[playerid][SpawnPX], PINFO[playerid][SpawnPY], PINFO[playerid][SpawnPZ], PINFO[playerid][SpawnPA], GetPlayerInterior(playerid), PINFO[playerid][ID]); 
    
mysql_tquery(ConHandlerquery); 
    
KillTimer(PosSavingTimer[playerid]);
    return 
1;
}
public 
OnPlayerDeath(playeridkilleridreason)
{
    
KillTimer(PosSavingTimer[playerid]);
    return 
1;
}
public 
PosSaving(playerid)
{
    new 
Float:xFloat:yFloat:zFloat:a;
    
GetPlayerFacingAngle(playerida);
    
GetPlayerPos(playeridx,y,z);
    
PINFO[playerid][SpawnPX] = x;
    
PINFO[playerid][SpawnPY] = y;
    
PINFO[playerid][SpawnPZ] = z;
    
PINFO[playerid][SpawnPA] = a;
    return 
1;

Reply
#6

well is it really not important to check something..onplayerdisconnect
like if 1 player disconnect and then another player join with same playerid his data will be transferred to him...
correct me if i'm wrong..
PHP код:
public OnPlayerDisconnect(playeridreason)
{
    
MySQLRaceCheck[playerid]++;
    
PlayerAccountUpdate(playeridreason);
    if(
cache_is_valid(PINFO[playerid][Cache_ID]))
    {
        
cache_delete(PINFO[playerid][Cache_ID]);
        
PINFO[playerid][Cache_ID] = MYSQL_INVALID_CACHE;
    }
    if (
PINFO[playerid][LoginTimer])
    {
        
KillTimer(PINFO[playerid][LoginTimer]);
        
PINFO[playerid][LoginTimer] = 0;
    }
    
PINFO[playerid][Plogged] = false;
    return 
1;

BTW I don't have to create Cache_ID in database right?
Reply
#7

Quote:
Originally Posted by princejeet1510
Посмотреть сообщение
well is it really not important to check something..onplayerdisconnect
like if 1 player disconnect and then another player join with same playerid his data will be transferred to him...
correct me if i'm wrong..
PHP код:
public OnPlayerDisconnect(playeridreason)
{
    
MySQLRaceCheck[playerid]++;
    
PlayerAccountUpdate(playeridreason);
    if(
cache_is_valid(PINFO[playerid][Cache_ID]))
    {
        
cache_delete(PINFO[playerid][Cache_ID]);
        
PINFO[playerid][Cache_ID] = MYSQL_INVALID_CACHE;
    }
    if (
PINFO[playerid][LoginTimer])
    {
        
KillTimer(PINFO[playerid][LoginTimer]);
        
PINFO[playerid][LoginTimer] = 0;
    }
    
PINFO[playerid][Plogged] = false;
    return 
1;

BTW I don't have to create Cache_ID in database right?
1st: Yes, it does happen. That's why i killed the timer when the player disconnected so that the disconnected player's position variable don't get transferred to the player joined with the same ID.

2nd: The ID is the primary key to store all the records unique and avoid data from dublicating. Yes, you should create the ID.
Reply
#8

well its still not working....
i thought of something else now...
like i have used
PHP код:
PlayerAccountUpdate(playeridreason); 
as a function under
PHP код:
public OnPlayerDisconnect(playeridreason
but i did nothing under
PHP код:
public OnPlayerSpawn(playerid
how can i add
PHP код:
PlayerAccountUpdate(playeridreason); 
on it too?
as if i do it gives error undefined symbol "reason".

as after player register the values of spawnpoint on DATABASE remain 0 so it means they never were changed actually so why not adding
PHP код:
PlayerAccountUpdate(playeridreason); 
so that it updates info once player spawn too?
please tell how i can do that...
and one more thing like once a player register he actually spawn at the position i have defined but it is never updated in Database.....as soon as he leave server he rejoin it spawn at blueberry acre falling down....basically changes it position.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)