HELP with getting coordinates into MSQL
#1

Hi guys im trying to store some coordinates into MSQL and it doesnt seem to work. I think im messing up my MSQL code. Heres the script:

pawn Код:
{
                new string[128];
                GetPlayerPos(i, x, y, z);  
                format(string, sizeof(string), "UPDATE `Users` SET `afkX` = '%s' AND `afkY` = '%s' AND `afkZ` = '%s'  WHERE `Name` = '%s'", x, y, z, vardas);
                mysql_query(string);
                afkn[i] = 1;
            }
everything compiles, but i dont get the coordinates into MSQL. Anyone know whats the problem? Thank you.
Reply
#2

%s is the string specifier

use %f, or %.2f since any value after the hundredths is redundant
Reply
#3

If you were to enable the debug, it would tell you that you have a syntax error. And even so, you could look up the correct syntax on the Internet. But that requires common sense, which most people don't have.
Reply
#4

I dont know guys it still does not work for me. I get somekind of the coordinates saved in the database, but their not having any decimals and look kind of strange. I tried changing the saving in database to decimal but it did not work. Im going to show you guys all of the script, sorry but im a noob in MySQL. So its basically a timer that gets players coordinates, and after a while it will get coordinates if their the same it will get a dialog out, if not then it will keep on going.

pawn Код:
public ZaidejuKord()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        new vardas[MAX_PLAYER_NAME];
        new Float:x, Float:y, Float:z;
        GetPlayerName(i, vardas, sizeof(vardas));
        if(prisijunges[i] == 1)
        {
            if(afkn[i] == 0)
            {
                new string[128];
                GetPlayerPos(i, x, y, z);  
                format(string, sizeof(string), "UPDATE `Users` SET `afkX` = '%.2f', `afkY` = '%.2f', `afkZ` = '%.2f'  WHERE `Name` = '%s'", x, y, z, vardas);
                mysql_query(string);
                afkn[i] = 1;
            }
            else if(afkn[i] == 1)
            {
                GetPlayerPos(i, x, y, z);
                CheckMySQL();

                new string[128];
                format(string, sizeof(string), "SELECT * FROM Users WHERE Name = '%s', afkX = '%.2f', afkY = '%.2f', afkZ = '%.2f'", vardas, x, y, z);
                mysql_query(string);
                mysql_store_result();
                if(!mysql_num_rows())
                {
                    afkn[i] = 0;
                }
                else
                {
                    ShowPlayerDialog(i,50,DIALOG_STYLE_MSGBOX,"{A3E4FF}AFK","{FFFFFF}Jus buvote {FFAF00}AFK{FFFFFF}, ar norite testi zaidima?","Taip","Ne");
                    AFK[i] = Create3DTextLabel("{C9FFAB}AFK", COLOR_GREEN,30.0,40.0,50.0,40.0,0);
                    Attach3DTextLabelToPlayer(AFK[i], i, 0.0, 0.0, 0.3);
                    afkn[i] = 2;
                }

                new row[128];
                new field[8][32];

                mysql_fetch_row_format(row, "|");
                explode(row, field, "|");
                mysql_free_result();

            }
            else if(afkn[i] == 2)
            {
            }
        }
    }
}

Im guessing there are some problems with applying murtiple coordinates i dont know what to put , or AND. If you guys see the problem please help me. Thank you!
Reply
#5

Are your table columns defined as the type FLOAT? If you're inserting a floating point number but the column types are strings this still won't work.

eg:

PHP код:
CREATE TABLE tbl (
    
vargas VARCHAR(24),   // VARCHAR for names
    
afkX FLOAT NOT NULL// Not VARCHAR
    
afkY FLOAT NOT NULL// but FLOAT
    
afkZ FLOAT NOT NULL

Also, why do you only do CheckMySQL(); in one of the if() statements? Shouldn't you do that at the beginning?

If you're not sure if the query is running, try it manually in phpMyAdmin and see if it returns errors.
Reply
#6

Thanks i fixed it to FLOAT, but now its always saying that im AFK, even if i move far away from the coordinate... WTF
Reply
#7

Post any code relevant to this afk system
Reply
#8

This is the script. Theres no other code.

pawn Код:
public ZaidejuKord()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        new vardas[MAX_PLAYER_NAME];
        new Float:x, Float:y, Float:z;
        GetPlayerName(i, vardas, sizeof(vardas));
        if(prisijunges[i] == 1)
        {
            if(afkn[i] == 0)
            {
                new string[128];
                GetPlayerPos(i, x, y, z);  
                format(string, sizeof(string), "UPDATE `Users` SET `afkX` = '%.2f', `afkY` = '%.2f', `afkZ` = '%.2f'  WHERE `Name` = '%s'", x, y, z, vardas);
                mysql_query(string);
                afkn[i] = 1;
            }
            else if(afkn[i] == 1)
            {
                GetPlayerPos(i, x, y, z);
                CheckMySQL();

                new string[128];
                format(string, sizeof(string), "SELECT * FROM Users WHERE Name = '%s', afkX = '%.2f', afkY = '%.2f', afkZ = '%.2f'", vardas, x, y, z);
                mysql_query(string);
                mysql_store_result();
                if(!mysql_num_rows())
                {
                    afkn[i] = 0;
                }
                else
                {
                    ShowPlayerDialog(i,50,DIALOG_STYLE_MSGBOX,"{A3E4FF}AFK","{FFFFFF}Jus buvote {FFAF00}AFK{FFFFFF}, ar norite testi zaidima?","Taip","Ne");
                    AFK[i] = Create3DTextLabel("{C9FFAB}AFK", COLOR_GREEN,30.0,40.0,50.0,40.0,0);
                    Attach3DTextLabelToPlayer(AFK[i], i, 0.0, 0.0, 0.3);
                    afkn[i] = 2;
                }

                new row[128];
                new field[8][32];

                mysql_fetch_row_format(row, "|");
                explode(row, field, "|");
                mysql_free_result();

            }
            else if(afkn[i] == 2)
            {
            }
        }
    }
}

ZaidejuKord is the timer.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)