[HELP] mysql check
#1

I want to check if player is not logged on this script and save these fields:

pawn Код:
if(GetPVarInt(playerid, "IsPlayerLogged") == 0)
{
}
I was trying to many ways, but does not work... If works when player is not logged, then doesn't work when player is logged. What can you suggest?

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    if(MySQLConnection == AK_TRUE)
    {
        // If player is logged in
        if(GetPVarInt(playerid, "IsPlayerLogged") == 1)
        {
            // Create variables
            new
                MySQLQuery[300],
                pname[24];

            // Get player name
            GetPlayerName(playerid, pname, 24);

            // Format MySQL UPDATE command
            format(MySQLQuery, sizeof(MySQLQuery), "UPDATE Users SET Kills=%i, Deaths=%i, Money=%i, Bank=%i, Admin=%i WHERE Name='%s'", GetPVarInt(playerid, "Kills"), GetPVarInt(playerid, "Deaths"), GetPlayerMoney(playerid), GetPVarInt(playerid, "Bank"), GetPVarInt(playerid, "Admin"), pname);

            // Execute UPDATE command
            mysql_query(MySQLQuery);
        }
    }
    // Exit
    return 1;
}
Reply
#2

Make sure you do set the variable to 1 when the player logs in...
Reply
#3

I want to put both of them in one :/
Reply
#4

Quote:
Originally Posted by V4at
Посмотреть сообщение
I want to put both of them in one :/
You've got to insert the field even if the player is not logged in then.
Reply
#5

I was trying to many ways with "if(GetPVarInt(playerid, "IsPlayerLogged") == 0)" I tried to put everywhere, but does not work... How need to change this script?
Reply
#6

You can't update a field in the DB if it's not existant. If what you're trying to do is to save the stats of a player even if he is not logged in, you've gotta insert the DB fields if they don't exist when they login.
Reply
#7

But I say works when player is not logged, but then doesn't work when player is logged and vice versa.. So I think does not need to insert a field..
Reply
#8

Quote:
Originally Posted by V4at
Посмотреть сообщение
But I say works when player is not logged, but then doesn't work when player is logged and vice versa.. So I think does not need to insert a field..
If you're trying to make it work for both then remove the checks. If you're trying to make it work for logged players make sure you set a loggedin variable when they log in and check for that one. If you're trying to make it work for non logged in players then do the same thing as before but check if the player is not logged in instead.
Reply
#9

How can I change this:

for example:

if(GetPVarInt(playerid, "IsPlayerLogged") == 1 OR == 0)

This line is bad, but how something like this?
Reply
#10

Remove the check itself. It's redundant to check if its 1 or 0 if the only values it takes are 1 or 0.

But to answer your question you must use the OR operators (||)

pawn Код:
if(a == 0 || a == 1 || a == 2)
Translates as A = 0 OR A = 1 OR a = 2

pawn Код:
if(a == 0 && b == 2 && c == 2)
Translates as A = 0 AND B = 2 AND c = 2
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)