SA-MP Forums Archive
Commands out of sync; you can't run this command now - 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: Commands out of sync; you can't run this command now (/showthread.php?tid=303974)



Commands out of sync; you can't run this command now - Unknown123 - 16.12.2011

pawn Код:
public OnPlayerConnect(playerid)
{
    serverInfoUpdate(true);

    if(isPlayerWhiteListed(playerid))
    {
        //code
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason
{
    serverInfoUpdate(false);

    savePlayerAccount(playerid);
    return 1;
}
OnPlayerConnect
Код:
MYSQL]: Error ID: 2014 | Error: Commands out of sync; you can't run this command now | Query: SELECT `pName` FROM `whitelist` WHERE `pName` = 'Unknown'
[14:00:26] MYSQL]: Commands out of sync for thread ID: -1
[14:00:26] MYSQL]: Error ID: 2014 | Error: Commands out of sync; you can't run this command now | Query: UPDATE `serverinfo` SET `onlinePlayers` = `PlayersOnline` +1
[14:00:26] MYSQL]: Commands out of sync for thread ID: -1
OnPlayerDisconnect
Код:
[13:33:32] MYSQL]: Error ID: 2014 | Error: Commands out of sync; you can't run this command now | Query: UPDATE `accs` SET aLevel = '0' ect ect.. WHERE `pName` = 'Unknown'
[13:33:32] MYSQL]: Commands out of sync for thread ID: -1
[13:33:32] MYSQL]: Error ID: 2014 | Error: Commands out of sync; you can't run this command now | Query: UPDATE `sinfo` SET `onlinePlayers` = `PlayersOnline` -1
[13:33:32] MYSQL]: Commands out of sync for thread ID: -1
error info:
Clickme

i dont know how to fix but i think the problem is that a new query starts before another query finish


Re: Commands out of sync; you can't run this command now - BlackWolf120 - 16.12.2011

can you show us the query code? (whole saving/loading block)


Re: Commands out of sync; you can't run this command now - Unknown123 - 16.12.2011

Quote:
Originally Posted by BlackWolf120
Посмотреть сообщение
can you show us the query code? (whole saving/loading block)
pawn Код:
stock savePlayerAccount(playerid)
{
    new SaveQuery[500];
    format(SaveQuery, sizeof(SaveQuery), "UPDATE `accs` SET `aLevel` = '%d', `Donator` = '%d', `Score` = '%d', `Money` = '%d', `Kills` = '%d', `Deaths` = '%d' WHERE `pName` = '%s'",
    pInfo[playerid][aLevel],
    pInfo[playerid][pDonator],
    GetPlayerScore(playerid),
    GetPlayerMoney(playerid),
    pInfo[playerid][pKills],
    pInfo[playerid][pDeaths],
    pName(playerid));

    mysql_query(SaveQuery);
    return playerid;
}

stock isPlayerWhiteListed(playerid)
{
    new string[81];
    Format(string, "SELECT `pName` FROM `whitelist` WHERE `pName` = '%s'", pName(playerid));
    mysql_query(string);
    mysql_store_result();
    if(mysql_num_rows() != 0 && mysql_ping(connection) != -1)
    {
        mysql_free_result();
        return 1;
    }
    mysql_free_result();
    return 0;
}

stock serverInfoUpdate(bool:connect)
{
    if(connect == true)
    {
        mysql_query("UPDATE `sinfo` SET `onlineplayers` = `onlineplayers` +1");
    }
    else
    {
        mysql_query("UPDATE `sinfo` SET `onlineplayers` = `onlineplayers` -1");
    }
}



Re: Commands out of sync; you can't run this command now - BlackWolf120 - 16.12.2011

made it up pretty quick so i dont know if i overlooked smth.
But it should work...
I changed some things as im used to script certain parts "in my style" but the result should be the same

pawn Код:
new PlayersOnline=0;

public OnPlayerConnect(playerid)
{
    PlayersOnline++;
    new queryconn[30];
    format(queryconn, sizeof(queryconn), "UPDATE sinfo SET on‌lineplayers=%d",PlayersOnline);
    mysql_query(queryconn);
    if(isPlayerWhiteListed(playerid))
    {
        //code
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason
{
    PlayersOnline--;
    new queryconn[30];
    format(queryconn, sizeof(queryconn), "UPDATE sinfo SET on‌lineplayers=%d",PlayersOnline);
    mysql_query(queryconn);
    savePlayerAccount(playerid);
    return 1;
}

stock isPlayerWhiteListed(playerid)
{
        new string[96];
        format(string, "SELECT pName FROM whitelist WHERE pName='%s' LIMIT 1", pName(playerid));
        mysql_query(string);
        mysql_store_result();
        new rows = mysql_num_rows();
        if(!rows)
        {
            //code that shall be executed when the player is not on the whitelist.
        }
        else if(rows == 1)
        {
            //code that shall be executed when the player is on the whitelist.
        }
        mysql_free_result();
}

stock savePlayerAccount(playerid)
{
    new SaveQuery[500];
    format(SaveQuery, sizeof(SaveQuery), "UPDATE accs SET aLevel=%d, Donator=%d, Score=%d, Money=%d, Kills=%d, Deaths=%d WHERE pName='%s'",pInfo[playerid][aLevel],pInfo[playerid][pDonator],GetPlayerScore(playerid),GetPlayerMoney(playerid),pInfo[playerid][pKills],pInfo[playerid][pDeaths],pName(playerid));
    mysql_query(SaveQuery);
    return 1;
}
Hope this helps.


Re: Commands out of sync; you can't run this command now - Unknown123 - 16.12.2011

you just changed the scripting sytle, it dont solve the porb. so i still get errors...


Re: Commands out of sync; you can't run this command now - BlackWolf120 - 16.12.2011

did you even try it?

I use a pretty simillar code and it works like a charm for me.
And its not just the style if u take a closer look...


Re: Commands out of sync; you can't run this command now - Unknown123 - 16.12.2011

Quote:
Originally Posted by BlackWolf120
Посмотреть сообщение
did you even try it?

I use a pretty simillar code and it works like a charm for me.
And its not just the style if u take a closer look...
i saw you changed some of the code yes.

and i replied "so i still get errors..." it means i have tested it......


Re: Commands out of sync; you can't run this command now - Laronic - 16.12.2011

pawn Код:
new WhiteListed[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
    new string[90];
    Format(string, "SELECT `pName` FROM `whitelist` WHERE `pName` = '%s' LIMIT 1", pName(playerid));
    mysql_query(string, THREAD_WHITELIST, playerid);
   
    serverInfoUpdate(true);
    if(isPlayerWhiteListed(playerid))
    {
        //code
    }
    return 1;
}

public OnQueryFinish(query[], resultid, extraid, connectionHandle)
{
    switch(resultid)
    {
        case THREAD_WHITELIST:
        {
            mysql_store_result();
            if(IsPlayerConnected(playerid) && mysql_num_rows() != 0)
            {
                WhiteListed[playerid] = 1;
            }
            else
            {
                WhiteListed[playerid] = 0;
            }
            mysql_free_result();
        }
    }
    return true;
}

stock isPlayerWhiteListed(playerid)
{
    if(WhiteListed[playerid] == 1) return true;
    return false;
}