[HELP] command shop
#1

Hello when some player near shop type /shop server crashed and it says


Run time error 4: "Array index out of bounds"
[12:31:51] [debug] Accessing element at negative index -1
[12:31:51] [debug] AMX backtrace:
[12:31:51] [debug] #0 000dd708 in public cmd_shop (0x00000009, 0x01988554)


here is that command

pawn Код:
CMD:shop(playerid,params[])
{
    if(IgracLogiran[playerid] != 1)
    {
        SCM(playerid,COLOR_GRAD2,"{FFFFFF}[{F81414}G-Protect{FFFFFF}] {C3C3C3}Morate biti logirani za koristenje ove komande!");
        return 1;
    }
    new x;
    for(new i = 19; i < 22; i++) here I check if the player is near a shop of bussines which is from id 19 to 22
    {
        if(IsPlayerInRangeOfPoint(playerid,4.0,SFBussinesInfo[i][sfenterX],SFBussinesInfo[i][sfenterY],SFBussinesInfo[i][sfenterZ]))
        {
            x++;
            if(SFBussinesInfo[NearShop[playerid]][sfProducts] <= 0) return GameTextForPlayer(playerid,"~r~there's no products here anymore",5000,1);
            NearShop[playerid] = i;
            ShowPlayerDialog(playerid,229,DIALOG_STYLE_LIST,"Dobrodosli na Kiosk","{FFFFFF}Bon od 50$\n{FFFFFF}Bon od 100$\n{FFFFFF}Bon od 150$\n{FFFFFF}Bon od 200$\n{FFFFFF}Buket Cvijeca(20$)\n{FFFFFF}Upaljac(10$)\n{FFFFFF}Cigare(17$)\n{FFFFFF}Coca-Cola(5$)","Kupi","Odustani");
            break;
        }
    }
    if(x == 0) return SCM(playerid,COLOR_GRAD2,"{F81414}[Greska!] {C3C3C3}you are not near shop!");
    return 1;
}
Reply
#2

pawn Код:
if(SFBussinesInfo[NearShop[playerid]][sfProducts] <= 0)
[NearShop[playerid] is -1 so check if it's not -1 before using it as index. And by the way, I doubt that's the reason the server crashed.
Reply
#3

how it should be look like that it if there's no produtc in the shop then it should says that there's no produtct

yes konstantinos when player is typed that command server is crashed. thanks
Reply
#4

I think you've just reversed the "NearShop" affectation and the product checking.

Put the "if" statement after the "NearShop[playerid] = i;".

EDIT : @Konstantinos : It is. When you try accessing an up bound or a negative bound cell of an array, it crashes the server (see the "Crashdetect plugin" example)
Reply
#5

I'm not aware of your code so you should check yourself if there's no product and return an error message.

Quote:
Originally Posted by S4t3K
Посмотреть сообщение
EDIT : @Konstantinos : It is. When you try accessing an up bound or a negative bound cell of an array, it crashes the server (see the "Crashdetect plugin" example)
In the example, it only gives run time error 4 and it does not crash the server unlike the fist example with fread and that run time error doesn't necessarily crash the server. I've seen logs that was caused 100+ times and no crashes.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)