Causing server crash.
#1

pawn Код:
CMD:viewfines(playerid, params[])
{
    if(LoggedIn[playerid] == 0) return SendClientMessage(playerid, COLOUR_GREY, "You must be logged in to use this command.");
    new am, string[128], totalamount;
    if(!IsPlayerInRangeOfPoint(playerid, 3.0, 3087.7048,-1779.4196,1525.7856))return SendClientMessage(playerid, COLOUR_GREY, "You must be at the town hall to pay fines.");
    for(new x = 1; x < MAX_FINES; x++)
    {
        if(PlayerFined[FineID[x]] == PlayerSQLID[playerid])
        {
            am++;
            totalamount += FineAmount[FineID[x]];
        }
    }
    if(am == 0)return SendClientMessage(playerid, COLOUR_GREY, "You do not have any outstanding fines.");
    format(string, sizeof(string), "Pay All Fines: "COL_RED"$%s\n"COL_WHITE"Pay Individual Fine", AddCommas(totalamount));//errorline
    ShowPlayerDialog(playerid, DIALOG_FINES, DIALOG_STYLE_LIST, "Fines", string, "Select","Exit");//error line
    return 1;
}
Код:
[16:41:35] [debug] Server crashed while executing BCRP_MYSQL.amx
[16:41:35] [debug] AMX backtrace:
[16:41:35] [debug] #0 native format () from samp03svr
[16:41:35] [debug] #1 000e35b8 in public cmd_viewfines () at C:\Users\Grant\Dropbox\Bone County Roleplay\gamemodes\BCRP_MYSQL.pwn:11704
[16:41:35] [debug] #2 native CallLocalFunction () from samp03svr
[16:41:35] [debug] #3 00000bb8 in public OnPlayerCommandText (playerid=1, cmdtext[]=@010d67e8 "/viewfines") at C:\Users\Grant\Dropbox\Bone County Roleplay\pawno\include\zcmd.inc:102
Reply
#2

I don't think you can do "COL_RED" inside of a quote, use color embedding instead {FF0000}

Код:
format(string, sizeof(string), "Pay All Fines: {FF0000}$%s\n{FFFFFF}Pay Individual Fine", AddCommas(totalamount));//errorline
Reply
#3

Ignore what TakeiT said, that code is perfectly fine as long as your macros are defined properly.

There are a few issues that could be the problem here. Either 'FineID[x]' is storing a value that is out of bounds of the array 'PlayerFined' or 'FineAmount', for example '-1' or a value that exceeds the size of the array. Or, your AddCommas function is causing the error.

You should make sure FineID[x] is a valid value before using it as an index for arrays.
Reply
#4

You could simplify this list with a simple SQL query (if you're working with SQL databases), and make sanity checks in your variables to make sure their values aren't out of bounds.

Anyway, why create "m" variable to check if there are more than 0 tickets if you can already know that by checking if totalamount is 0?

Oh, if you're not working with SQL I would use Iterators (y_foreach/y_iterate) to store the player fines, this way you can avoid any kind of checks AND you improve the perfomance greatly.

Also, before I forget, a 128 cell string is too small for a player that has 20 unpaid tickets.
Reply
#5

Quote:
Originally Posted by Threshold
Посмотреть сообщение
There are a few issues that could be the problem here. Either 'FineID[x]' is storing a value that is out of bounds of the array 'PlayerFined' or 'FineAmount', for example '-1' or a value that exceeds the size of the array. Or, your AddCommas function is causing the error.
Neither of them would cause a native to fail. The only way I can reproduce it is this:
Код:
new str[10];
	
format(str, 256, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa %s %i aaaaaaaaaa", "sdadada", 10);
specifying a length longer than the size of the destination.

@Dokins: If you execute that command again, you get the same logs (crash)? I'm not sure if can occur with #emit, it would probably give run time error 6.
Reply
#6

I see! Alright, I'll increase the length but he only had the one fine. I didn't have this issue at all. But I have done a few checks and things. I really appreciate all of your help.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)