SA-MP Forums Archive
Save and Load Positions[ MySQL] - 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: Save and Load Positions[ MySQL] (/showthread.php?tid=593591)



Save and Load Positions[ MySQL] - vassilis - 07.11.2015

Hello so i wonder how i can load the last position of player when he relogs? It saves very well but i used the setplayerPosition(pinfo[playerid][posX],pinfo[playerid][posY],pinfo[playerid][posZ]) but when i relog it spawns me at x0 y0 z0 coords!! even if it saves correctly the coords when i disconnect!
Here is my function where it has to spawn player OnPlayerSpawnCallback

pawn Код:
if(pinfo[playerid][Registered] == 0)
            {
                SetPlayerSkin(playerid,pinfo[playerid][Skin]);
                SetClassFromSkin(playerid);
                WantedLevelColor(playerid);
                SetPlayerTeam(playerid,pinfo[playerid][Team]);
                SetPlayerToTeamColor(playerid);
                GivePlayerTeamWeapons(playerid);
                printf("%s stats have been given.Skin: %d Team: %d", GPN(playerid),pinfo[playerid][Skin],pinfo[playerid][Team]);

                if(pinfo[playerid][Team] == TEAM_COPS)
                {
                    SetPlayerPos(playerid, 1569.5902,-1694.6520,5.8906);
                    SetCameraBehindPlayer(playerid);
                }
                if(pinfo[playerid][Team] == NO_TEAM)
                {

                    if(pinfo[playerid][Cuffed] == 1)
                    {
                        SendClientMessage(playerid, COLOR_RED," [ AUTO CUFF]: You have been autojailed because you left server while cuffed!");
                        new rnd = random(sizeof(PrisonSpawn));
                        SetPlayerPos(playerid, PrisonSpawn[rnd][0], PrisonSpawn[rnd][1], PrisonSpawn[rnd][2]);
                        SendClientMessage(playerid, COLOR_GREY, "**LOS SANTOS PRISON**");
                        SendClientMessage(playerid, COLOR_LIGHTBLUE, "[PRISON] You have been sent to prison. You will be released soon.");
                    }
                    if(pinfo[playerid][Jailed] == 1)
                    {
                        new rnd = random(sizeof(PrisonSpawn));
                        SetPlayerPos(playerid, PrisonSpawn[rnd][0], PrisonSpawn[rnd][1], PrisonSpawn[rnd][2]);
                        SendClientMessage(playerid, COLOR_GREY, "**LOS SANTOS PRISON**");
                        SendClientMessage(playerid, COLOR_LIGHTBLUE, "[PRISON] You have been sent to prison. You will be released soon.");
                    }
                    else
                    {
                        new rnd = random(sizeof(SpawnPoints));
                        //SetPlayerPos(playerid, SpawnPoints[rnd][0], SpawnPoints[rnd][1], SpawnPoints[rnd][2]);
                    SetPlayerPos(playerid,pinfo[playerid][posX],pinfo[playerid][posY],pinfo[playerid][posZ]); <<<<<<<
                        SetPlayerFacingAngle(playerid, SpawnPoints[rnd][3]);
                        SetCameraBehindPlayer(playerid);
                    }
                }
            }
and here is my accountload callback
pawn Код:
public OnAccountLoad(playerid)
{
    pinfo[playerid][Admin] = cache_get_field_content_int(0, "Admin");
    pinfo[playerid][VIP] = cache_get_field_content_int(0, "VIP");
    pinfo[playerid][Money] = cache_get_field_content_int(0, "Money");
    pinfo[playerid][posX] = cache_get_field_content_float(0, "PosX");
    pinfo[playerid][posY] = cache_get_field_content_float(0, "PosY");
    pinfo[playerid][posZ] = cache_get_field_content_float(0, "PosZ");
    pinfo[playerid][Kills] = cache_get_field_content_int(0, "Kills");
    pinfo[playerid][Deaths] = cache_get_field_content_int(0, "Deaths");
    pinfo[playerid][Score] = cache_get_field_content_int(0, "Score");
    pinfo[playerid][Banned] = cache_get_field_content_int(0,"Banned");
    pinfo[playerid][Hours] = cache_get_field_content_int(0, "Hours");
    pinfo[playerid][Minutes] = cache_get_field_content_int(0, "Minutes");
    pinfo[playerid][Terskill] = cache_get_field_content_int(0, "Terskill");
    pinfo[playerid][Robskill] = cache_get_field_content_int(0, "Robskill");
    pinfo[playerid][Hitmanskill] = cache_get_field_content_int(0, "Hitmanskill");
    pinfo[playerid][WantedLevel] = cache_get_field_content_int(0, "WantedLevel");
    pinfo[playerid][TotalRobs] = cache_get_field_content_int(0, "TotalRobs");
    pinfo[playerid][Muted] = cache_get_field_content_int(0," Muted");
    pinfo[playerid][Cuffed] = cache_get_field_content_int(0,"Cuffed");
    pinfo[playerid][Jailed] = cache_get_field_content_int(0, "Jailed");
    pinfo[playerid][JailTime] = cache_get_field_content_int(0, "JailTime");
    pinfo[playerid][Skin] = cache_get_field_content_int(0, "Skin");
    pinfo[playerid][Team] = cache_get_field_content_int(0, "Team");
    pinfo[playerid][Drug] = cache_get_field_content_int(0, "Drugs");
    pinfo[playerid][DrugAmount] = cache_get_field_content_int(0, "DrugAmount");
   
    pinfo[playerid][Logged] = 1;
    pinfo[playerid][Registered] = 0;
    SpawnPlayer(playerid);

    GivePlayerMoney(playerid, pinfo[playerid][Money]);

    SendClientMessage(playerid, -1, "Successfully logged in");
    return 1;
}



Re: Save and Load Positions[ MySQL] - MD5 - 07.11.2015

Show me your sql query for saving X,Y,Z coords.


Re: Save and Load Positions[ MySQL] - vassilis - 07.11.2015

pawn Код:
GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
    pinfo[playerid][Skin] = GetPlayerSkin(playerid);
    pinfo[playerid][Team] = GetPlayerTeam(playerid);
    pinfo[playerid][Money] = GetPlayerMoney(playerid);
    pinfo[playerid][Score] = GetPlayerScore(playerid);
    mysql_format(mysql, query, sizeof(query), "UPDATE `players` SET `Admin`=%d, `VIP`=%d, `Money`=%d, `posX`=%f, `posY`=%f, `posZ`=%f,\
    `Score` =%d, `Banned` =%d, `Cuffed` =%d, `Muted` =%d, `Jailed` =%d, `JailTime` =%d, `Drugs` =%d, `DrugAmount` =%d, `Robskill` =%d, `Hitmanskill` =%d, `Terskill` =%d, `TotalRobs` =%d,\
    `Skin` =%d, `Team` =%d, `Kills` =%d, `Deaths`=%d WHERE `ID`=%d"
,
    pinfo[playerid][Admin], pinfo[playerid][VIP],pinfo[playerid][Money], pos[0], pos[1], pos[2],
    pinfo[playerid][Score],pinfo[playerid][Banned], pinfo[playerid][Cuffed],pinfo[playerid][Muted],
    pinfo[playerid][Jailed],pinfo[playerid][JailTime],pinfo[playerid][Drug],pinfo[playerid][DrugAmount],
    pinfo[playerid][Robskill],pinfo[playerid][Hitmanskill],pinfo[playerid][Terskill],pinfo[playerid][TotalRobs],pinfo[playerid][Skin],
    pinfo[playerid][Team],pinfo[playerid][Kills],pinfo[playerid][Deaths],pinfo[playerid][ID]);



Re: Save and Load Positions[ MySQL] - Vince - 07.11.2015

Quote:
Originally Posted by vassilis
Посмотреть сообщение
It saves very well
Are you sure? Have you verified this after disconnecting? GetPlayer* functions do not work in OnPlayerDisconnect because the player has already left the game at the point.


Re: Save and Load Positions[ MySQL] - vassilis - 07.11.2015

Well vince i noticed that it saves actually the coords i might have put it and to another callback. D you have any suggestion of how i should work with that problem?

EDIT: It only saves the pos onplayerdisconnect


Re: Save and Load Positions[ MySQL] - MD5 - 07.11.2015

Quote:
Originally Posted by vassilis
Посмотреть сообщение
Well vince i noticed that it saves actually the coords i might have put it and to another callback. D you have any suggestion of how i should work with that problem?

EDIT: It only saves the pos onplayerdisconnect
You can't save the pos using "GetPlayer" on disconnect, because they're already disconnected.

However, you can make a stock in which updates/saves player stats every "34123412" milliseconds; and so fourth.


Re: Save and Load Positions[ MySQL] - vassilis - 07.11.2015

Quote:
Originally Posted by MD5
Посмотреть сообщение
You can't save the pos using "GetPlayer" on disconnect, because they're already disconnected.

However, you can make a stock in which updates/saves player stats every "34123412" milliseconds; and so fourth.
So you suggest me to use atimer which will save/update player stats every x miliseconds so i could save player pos too?