SA-MP Forums Archive
Array out of Bonds - 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: Array out of Bonds (/showthread.php?tid=639366)



Array out of Bonds - Shaheen - 16.08.2017

Hi,
I have got an error

Debug :
Код:
[debug] Run time error 4: "Array index out of bounds"
[debug]  Accessing element at negative index -1
[debug] AMX backtrace:
[debug] #0 00290fa4 in public cmd_stats (0, 2752580) from CCNR.amx
[debug] #1 002905ac in public cmd_stats (0, 2741220) from CCNR.amx
[debug] #2 native CallLocalFunction () from samp-server.exe
[debug] #3 0003eeb0 in public OnPlayerCommandText (0, 2741192) from CCNR.amx
Stats Command
PHP код:
COMMAND:stats(playeridparams[]) //
{
    new 
msg[1200];
    new 
msg3[200];
    new 
otherIDgID;
    if(
sscanf(params"u"otherID))
    {
        
format(msgsizeof(msg), "%d"playerid);
        
cmd_stats(playeridmsg);
    }
    else
    {
            if(!
isConnected(otherID))
            {
                if(
Player[playerid][english])
                    
//Server(playerid, "That player isn't logged in!.");
                    
SendClientMessage(playerid,COLOR_RED,"The requested player is not connected.");
                else
                    
Server(playerid"Player tidak login.");
                return 
1;
            }
            
format(msgsizeof(msg), "%s"CHAT_WHITE"\nKills : "CHAT_YELLOW"%d"msgPlayer[otherID][playerKills]);
            
format(msgsizeof(msg), "%s"CHAT_WHITE"\nDeaths : "CHAT_YELLOW"%d"msgPlayer[otherID][playerDeaths]);
            
format(msgsizeof(msg), "%s"CHAT_WHITE"\nXP : "CHAT_YELLOW"%d"msgPlayer[otherID][playerXP]);
            
format(msgsizeof(msg), "%s"CHAT_WHITE"\nScore : "CHAT_YELLOW"%d"msgPlayer[otherID][playerScore]);
            
format(msgsizeof(msg), "%s"CHAT_WHITE"\nMoney : "CHAT_YELLOW"%s"msgFormatNumber(Player[otherID][playerMoney]));
            
format(msgsizeof(msg), "%s"CHAT_WHITE"\nRob : "CHAT_YELLOW"%d"msgPlayer[otherID][playerRob]);
            
format(msgsizeof(msg), "%s"CHAT_WHITE"\nWanted Level : "CHAT_YELLOW"%d"msgPlayer[otherID][playerWanted]);
            
format(msgsizeof(msg), "%s"CHAT_WHITE"\nPilot Missions : "CHAT_YELLOW"%d"msgPlayer[otherID][missions]);
            
format(msgsizeof(msg), "%s"CHAT_WHITE"\nDelivery Missions : "CHAT_YELLOW"%d"msgPlayer[otherID][delivery]);
            
format(msgsizeof(msg), "%s"CHAT_WHITE"\nTaxi Missions : "CHAT_YELLOW"%d"msgPlayer[otherID][taxi]);
            
format(msgsizeof(msg), "%s"CHAT_WHITE"\nBus Missions : "CHAT_YELLOW"%d"msgPlayer[otherID][bus]);
            
format(msgsizeof(msg), "%s"CHAT_WHITE"\nPlayer Vehicles : "CHAT_YELLOW"%d"msgcountplayerVeh(otherID));
            
format(msgsizeof(msg), "%s"CHAT_WHITE"\nVIP : "msg);
            if(
Player[otherID][vipLevel] > 0)
            {
                
format(msgsizeof(msg), "%s"CHAT_YELLOW"Yes"msg);
            }
            else
            {
                
format(msgsizeof(msg), "%s"CHAT_RED"No"msg);
            }
            
format(msgsizeof(msg), "%s"CHAT_WHITE"\nJailed : "msg);
            if(
Player[otherID][isJailed])
            {
                
format(msgsizeof(msg), "%s"CHAT_YELLOW"Yes"msg);
            }
            else
            {
                
format(msgsizeof(msg), "%s"CHAT_RED"No"msg);
            }
            
format(msgsizeof(msg), "%s"CHAT_WHITE"\nAFK : "msg);
            if(
Player[otherID][paused])
            {
                
format(msgsizeof(msg), "%s"CHAT_YELLOW"Yes"msg);
            }
            else
            {
                
format(msgsizeof(msg), "%s"CHAT_RED"No"msg);
            }
            
format(msgsizeof(msg), "%s"CHAT_WHITE"\nGang : "msg);
            if(
inGang(otherID))
            {
                
gID findGang(otherID);
                
format(msgsizeof(msg), "%s{%s}%s"msgGang[gID][gangColor], Gang[gID][gangName]);
            }
            else
            {
                
format(msgsizeof(msg), "%s"CHAT_RED"NO GANG"msg);
            }
            
format(msg3sizeof(msg3), "Viewing %s(%d)'s Statistics"GetName(otherID), playerid);
            
//ShowPlayerDialog(playerid, DIALOG_UNUSED, DIALOG_STYLE_MSGBOX, msg3 , msg, "Close", "");
    
}
    
ShowPlayerDialog(playeridDIALOG_UNUSEDDIALOG_STYLE_MSGBOXmsg3 msg"Done""");
    return 
1;

Thnx in Advance


Re: Array out of Bonds - OneDay - 16.08.2017

Use -d3 for line number.


Re: Array out of Bonds - Shaheen - 16.08.2017

actually i dont know about this feature.
i have ******d it but could not find it.
it will be sweet if u could have given me a link..

thnx


Re: Array out of Bonds - Misiur - 16.08.2017

https://github.com/Zeex/samp-plugin-...ith-debug-info


Re: Array out of Bonds - Shaheen - 16.08.2017

Not working with it
any other solutions ?


Re: Array out of Bonds - oMa37 - 16.08.2017

It won't work with it, but It will show you where is the exact line that cause this array out of bounds.
Could you show us the new debugs after you compiled with -d3?


Re: Array out of Bonds - denNorske - 16.08.2017

Hello Shaheen

Looking at the code, it's obvious that there's a value that is -1 when you access it.

Try to find your pawn config file (settings.ini), and add -d3 into it in the arguments. This will add debug level 3 and most likely give you a line number to work from.

Here is a picture




If this wasn't / isn't working correctly, you'll need to debug the variables manually and print the values to the chat/log.

With a good text editor this is done quickly