MySQL Saving won't work out probably.
#1

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;
    }
Reply
#2

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

Shouldnt the return 0?
Reply
#4

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

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;
    }
Reply
#6

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

Are you able to help me via skype and teamviewer?
Reply
#8

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;
    }
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)