SA-MP Forums Archive
MySQL Saving won't work out probably. - 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: MySQL Saving won't work out probably. (/showthread.php?tid=486936)



MySQL Saving won't work out probably. - Lyksus - 11.01.2014

Anyone can see why the position is not saving?


pawn Код:
stock SavePlayer(playerid)
    {
        if(!IsPlayerConnected(playerid))return 1;
        new query[500];
        GetPlayerPos(playerid, Player[playerid][PosX], Player[playerid][PosY], Player[playerid][PosZ]);
        format(query, sizeof(query), "UPDATE accounts SET Name='%s', Password='%s', AdminLevel='%d', PosX='%f', PosY'%f', PosZ'%f' WHERE userid='%d' LIMIT 1",
        pName(playerid),
        Player[playerid][Password],
        Player[playerid][AdminLevel],
        Player[playerid][PosX],
        Player[playerid][PosY],
        Player[playerid][PosZ],
        Player[playerid][UserID]);
        mysql_query(query);
       
        printf("%s (%d) has successfully saved account details in the database.", RemoveUnderScore(playerid), playerid);
        return 1;
    }



Re: MySQL Saving won't work out probably. - MadafakaPro - 11.01.2014

Try this:
pawn Код:
stock SavePlayer(playerid)
    {
        if(!IsPlayerConnected(playerid))return 1;
        new query[500];
        GetPlayerPos(playerid, Player[playerid][PosX], Player[playerid][PosY], Player[playerid][PosZ]);
        format(query, sizeof(query), "UPDATE accounts SET Name='%s', Password='%s', AdminLevel='%d', PosX='%f', PosY='%f', PosZ='%f' WHERE userid='%d' LIMIT 1",
        pName(playerid),
        Player[playerid][Password],
        Player[playerid][AdminLevel],
        Player[playerid][PosX],
        Player[playerid][PosY],
        Player[playerid][PosZ],
        Player[playerid][UserID]);
        mysql_query(query);
       
        printf("%s (%d) has successfully saved account details in the database.", RemoveUnderScore(playerid), playerid);
        return 1;
    }



Re: MySQL Saving won't work out probably. - Sojo12 - 11.01.2014

Shouldnt the return 0?


Re: MySQL Saving won't work out probably. - newbie scripter - 11.01.2014

pawn Код:
if(!IsPlayerConnected(playerid))return 0;



Re: MySQL Saving won't work out probably. - Lyksus - 12.01.2014

Still having the same problem...

If you can see the issue, please tell me...

pawn Код:
stock SavePlayer(playerid)
    {
        if(!IsPlayerConnected(playerid))return 0;
        new query[500];
        GetPlayerPos(playerid, Player[playerid][PosX], Player[playerid][PosY], Player[playerid][PosZ]);
        format(query, sizeof(query), "UPDATE `accounts` SET `AdminLevel` = '%d', `PosX` = '%f', `PosY` = '%f', `PosZ` = '%f' WHERE `Name` = '%d' LIMIT 1", Player[playerid][AdminLevel], Player[playerid][PosX], Player[playerid][PosY], Player[playerid][PosZ], pName(playerid));
        mysql_query(query);
       
        printf("%s (%d) has successfully saved account details in the database.", RemoveUnderScore(playerid), playerid);
        return 1;
    }



Re: MySQL Saving won't work out probably. - Konstantinos - 12.01.2014

What do you you mean by "MySQL Saving won't work out probably."? It doesn't save at all? Does it print anything to the mysql log? Try printing the query for debugging. You can also get the query printed to the server log and execute it via phpMyAdmin, it will probably say if something is wrong. Last, just so you know, only strings must have '' around the placeholder while integers/float not.

Quote:
Originally Posted by Sojo12
Посмотреть сообщение
Shouldnt the return 0?
What would be the difference? Any value it will return, the code below will not be executed anyways.


Re: MySQL Saving won't work out probably. - Lyksus - 12.01.2014

Are you able to help me via skype and teamviewer?


Re: MySQL Saving won't work out probably. - Lyksus - 12.01.2014

Just found out that it worked all the time. But. Now I am having a new issue. Before the player logs off, it doesn't actually save his position. How can I make it save before the player actually logs off?
pawn Код:
public OnPlayerDisconnect(playerid, reason)
    {
        SavePlayer(playerid);
       
        new string[256], astring[256];
        switch(reason)
        {
            case 0: format(string,sizeof string,"%s has lost connection to the server.", RemoveUnderScore(playerid));
            case 1: format(string,sizeof string,"%s has left the server.", RemoveUnderScore(playerid));
            case 2: format(string,sizeof string,"%s has been kicked or banned from the server.", RemoveUnderScore(playerid));
        }
        NearByMessage(playerid, GREY, string);
        printf("[LOGGING] %s (ID: %d) has just disconnected the server. Reason: %s", pName(playerid), playerid, string);
       
        for(new i = 0; i < MAX_PLAYERS; i++)
        if(Player[i][AdminLevel] >= 1)
        {
            if(!IsPlayerInRangeOfPlayer(i, playerid, 20))
            {
                switch(reason)
                {
                    case 0: format(astring,sizeof astring,"%s has lost connection to the server.", RemoveUnderScore(playerid));
                    case 1: format(astring,sizeof astring,"%s has left the server.", RemoveUnderScore(playerid));
                    case 2: format(astring,sizeof astring,"%s has been kicked or banned from the server.", RemoveUnderScore(playerid));
                }
                SendAdminMessage(playerid, RED, astring);
            }
        }
       
        DestroyPlayerTextDraws(playerid);
        return 1;
    }