Crashing while using this cmd
#1

While using this command, the whole server crashes, is there anything wrong with this code?

pawn Код:
CMD:richlist(playerid, params[])
{
    mysql_query("SELECT `username`, `money` FROM `data` WHERE `PlayerBanned`=0 ORDER BY `money` DESC LIMIT 10");
    mysql_store_result();

    new
        ID,
        output[800];

    while(mysql_retrieve_row())
    {
        ID ++;

        new
            username[24],
            moneyvariable[80];

        mysql_fetch_field_row(username, "user");
        mysql_fetch_field_row(moneyvariable, "money");

        format(output, sizeof(output), "%s %d. %s with %d Dollars\n", output, ID, username, strval(moneyvariable));
    }
    mysql_free_result();

    ShowPlayerDialog(playerid, 25, DIALOG_STYLE_MSGBOX, "Top 10 Players", output, "OK", "Cancel");
    return 1;
}
Reply
#2

Well I've not spotted any errors directly, try and debug the code and look on your console for where the script is stopping (on server_log.txt)

pawn Код:
CMD:richlist(playerid, params[])
{
    mysql_query("SELECT `username`, `money` FROM `data` WHERE `PlayerBanned`=0 ORDER BY `money` DESC LIMIT 10");
    mysql_store_result();
    printf("debug note 1");
    new
        ID,
        output[800];
    printf("debug note 2");
    while(mysql_retrieve_row())
    {
        ID ++;
        printf("debug note 3 ID %d", id);
        new
            username[24],
            moneyvariable[80];
        printf("debug note 4 ID %d", id);
        mysql_fetch_field_row(username, "user");
        mysql_fetch_field_row(moneyvariable, "money");
        printf("debug note 5 ID %d", id);
        format(output, sizeof(output), "%s %d. %s with %d Dollars\n", output, ID, username, strval(moneyvariable));
        printf("debug note 6 ID %d", id);
    }
    mysql_free_result();
    printf("debug note 7");
    ShowPlayerDialog(playerid, 25, DIALOG_STYLE_MSGBOX, "Top 10 Players", output, "OK", "Cancel");
    printf("debug note 8");
    return 1;
}
Reply
#3

See if this helps any. You don't really need strval for moneyvariable:

pawn Код:
CMD:richlist(playerid, params[])
{
    #pragma unused params
    mysql_query("SELECT `username`, `money` FROM `data` WHERE `PlayerBanned` = 0 ORDER BY `money` DESC LIMIT 10");
    mysql_store_result();

    new ID = 0, output[800];

    while(mysql_retrieve_row())
    {
        ID++;
        new username[MAX_PLAYER_NAME], moneyvariable[80];

        mysql_fetch_field_row(username, "user");
        mysql_fetch_field_row(moneyvariable, "money");

        format(output, sizeof(output), "%s %d. %s with %s dollars\n", output, ID, username, moneyvariable);
    }
    mysql_free_result();
    return ShowPlayerDialog(playerid, 25, DIALOG_STYLE_MSGBOX, "Top 10 Players", output, "OK", "");
}
Reply
#4

Quote:
Originally Posted by DanishHaq
Посмотреть сообщение
Well I've not spotted any errors directly, try and debug the code and look on your console for where the script is stopping (on server_log.txt)

pawn Код:
CMD:richlist(playerid, params[])
{
    mysql_query("SELECT `username`, `money` FROM `data` WHERE `PlayerBanned`=0 ORDER BY `money` DESC LIMIT 10");
    mysql_store_result();
    printf("debug note 1");
    new
        ID,
        output[800];
    printf("debug note 2");
    while(mysql_retrieve_row())
    {
        ID ++;
        printf("debug note 3 ID %d", id);
        new
            username[24],
            moneyvariable[80];
        printf("debug note 4 ID %d", id);
        mysql_fetch_field_row(username, "user");
        mysql_fetch_field_row(moneyvariable, "money");
        printf("debug note 5 ID %d", id);
        format(output, sizeof(output), "%s %d. %s with %d Dollars\n", output, ID, username, strval(moneyvariable));
        printf("debug note 6 ID %d", id);
    }
    mysql_free_result();
    printf("debug note 7");
    ShowPlayerDialog(playerid, 25, DIALOG_STYLE_MSGBOX, "Top 10 Players", output, "OK", "Cancel");
    printf("debug note 8");
    return 1;
}
From this part on wards it ain't working.

pawn Код:
mysql_fetch_field_row(moneyvariable, "money");
        printf("debug note 5 ID %d", id);
        format(output, sizeof(output), "%s %d. %s with %d Dollars\n", output, ID, username, strval(moneyvariable));
        printf("debug note 6 ID %d", id);
    }
    mysql_free_result();
    printf("debug note 7");
    ShowPlayerDialog(playerid, 25, DIALOG_STYLE_MSGBOX, "Top 10 Players", output, "OK", "Cancel");
    printf("debug note 8");
Reply
#5

pawn Код:
CMD:richlist(playerid, params[])
{
    mysql_query("SELECT `username`, `money` FROM `data` WHERE `PlayerBanned`=0 ORDER BY `money` DESC LIMIT 10");
    mysql_store_result();
    printf("debug note 1");
    new ID, output[800], string[256];
    printf("debug note 2");
    while(mysql_retrieve_row())
    {
        ID ++;
        printf("debug note 3 ID %d", id);
        new username[24], moneyvariable;
        printf("debug note 4 ID %d", id);
        mysql_fetch_field_row(username, "user");
        mysql_fetch_field_row(string, "money"); moneyvariable = strval(string);
        printf("debug note 5 ID %d", id);
        format(output, sizeof(output), "%s %d. %s with %d Dollars\n", output, ID, username, moneyvariable);
        printf("debug note 6 ID %d", id);
    }
    mysql_free_result();
    printf("debug note 7");
    ShowPlayerDialog(playerid, 25, DIALOG_STYLE_MSGBOX, "Top 10 Players", output, "OK", "Cancel");
    printf("debug note 8");
    return 1;
}
This should work.
Reply
#6

Doesn't work :/

from here again

pawn Код:
mysql_fetch_field_row(string, "money"); moneyvariable = strval(string);
        printf("debug note 5 ID %d", id);
        format(output, sizeof(output), "%s %d. %s with %d Dollars\n", output, ID, username, moneyvariable);
        printf("debug note 6 ID %d", id);
    }
    mysql_free_result();
    printf("debug note 7");
    ShowPlayerDialog(playerid, 25, DIALOG_STYLE_MSGBOX, "Top 10 Players", output, "OK", "Cancel");
    printf("debug note 8");
Reply
#7

bump anyone?
Reply
#8

try to delete

pawn Код:
format(output, sizeof(output), "%s %d. %s with %d Dollars\n", output, ID, username, moneyvariable);
if the command didn't crash then you need to delete that output after the Dollars\n",
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)