Array index out of bounds.
#1

I usually have alot of problems with this kind, i thought lets ask help to solve one of them and ill the rest my self.


PHP код:
if(Player[playerid][PlayerGang] != -&& !IsPlayerNPC(playerid))
            {
                new 
zone Gang[Player[playerid][PlayerGang]][CurrentZone];    
                if(
GangZone[zone][ZoneStatus] == true && GangZone[zone][ZoneOwner] == Player[playerid][PlayerGang])
                {
                    new 
msg1[128];
                    
format(msg1sizeof(msg1), "{FF0000}** %s gang failed to capture %s zone, REASON: Oppenent Gang reached to rescue!"Gang[Player[playerid][PlayerGang]][GangName], GangZone[zone][ZoneName]);
                    
SendClientMessageToAll(-1msg1);
                    
Gang[Player[playerid][PlayerGang]][CurrentZone] = -1;
                    
GangZone[zone][ZoneLocked] = GetTickCount();
                    
GangZone[zone][ZoneStatus] = false;
                    
GangZoneStopFlashForAll(GangZone[zone][ZoneHolder]);            
                }
            } 
This is the code to check, if player is capturing zone, while doing that the zone owner comes into zone, the capturing status fails and zone gets locked...

This that is under onplayerenter area, and i am getting this in debug when player enters a area:

PHP код:
[debugRun time error 4"Array index out of bounds"
[debug]  Accessing element at negative index -1
[debugAMX backtrace:
[
debug#0 00055d98 in public S@@_OnPlayerEnterArea (playerid=1, areaid=27) at C:\Users\iLearner\Desktop\ffss\pawno\include\FFS/FFS_gangs.inc:1250
[debug#1 0000cb00 in Area_AddCuboid (... <2 variable arguments>) at C:\Users\iLearner\Desktop\ffss\pawno\include\YSI\y_hooks/impl.inc:2502
[debug#2 native CallRemoteFunction () [00471b40] from samp-server.exe
[debug#3 00024c9c in Area_DoEnter (playerid=1, areaid=27, &idx=@0x020f41d0) at C:\Users\iLearner\Desktop\ffss\pawno\include\YSI\y_areas.inc:2770
[debug#4 00020c6c in bool:Area_AddCuboid (... <1 variable argument>) at C:\Users\iLearner\Desktop\ffss\pawno\include\YSI\y_areas.inc:2110
[debug#5 0000b954 in Area_AddCuboid (... <1 variable argument>) at C:\Users\iLearner\Desktop\ffss\pawno\include\YSI\y_hooks/impl.inc:1997 
Additional information:
Line given in warnings:
PHP код:
                if(GangZone[zone][ZoneStatus] == true && GangZone[zone][ZoneOwner] == Player[playerid][PlayerGang]) 
Reply
#2

Did you check if 'zone' was a valid index?
Reply
#3

Well the code does what its supposed to do (detects zone etc) and works perfectly, but... this thing in debug.
Reply
#4

So where do you get the value for 'zone'.. ? And if you're making a thread on the forum, it obviously doesn't work perfectly.

EDIT: Oh derp, for some reason I was only looking at the second half of your post... lol. (Though it's 4am here, so I have an excuse)

PHP код:
if(zone != -&& GangZone[zone][ZoneStatus] == true && GangZone[zone][ZoneOwner] == Player[playerid][PlayerGang]) 
Reply
#5

Solved that one ^ but i have another one, consider it last one

PHP код:
if (dialogid == DIALOG_DUEL)
    {
        if (!
response) return 0;
        switch(
listitem)
        {
            case 
0//new duel
            
{
                   if (
duelslotid[playerid] != -1) return SendClientMessage(playeridERRORCOLOR"You have already sent someone a duel invite.");
                for (new 
0MAX_DUELSi++)
                {
                    if (
duel[i][duelstate] == 0) { duelslotid[playerid] = i; break; }
                }
                if (
duelslotid[playerid] == -1) return SendClientMessage(playeridERRORCOLOR"There are no duel slots available.");
                
duel[duelslotid[playerid]][duelstate] = 1;
                
duel[duelslotid[playerid]][players][0] = playerid;
                
duel[duelslotid[playerid]][players][1] = INVALID_PLAYER_ID;
                
duel[duelslotid[playerid]][arena] = 0;
                
duel[duelslotid[playerid]][rounds] = 0;
                for (new 
013i++) duel[duelslotid[playerid]][weapons][i] = 0;
                
duel[duelslotid[playerid]][dkills][0] = 0;
                
duel[duelslotid[playerid]][dkills][1] = 0;
                   
ShowPlayerDialog(playeridDIALOG_DUELINVDIALOG_STYLE_LIST"Invite a player to a duel"Duel_InviteString(duelslotid[playerid]), "OK""BACK");
            }
            case 
1//watch
            
{
                
//if (!AdminCheck(playerid, 5)) return SendClientMessage(playerid, ERRORCOLOR, "This feature has not been added yet.");
                
new count;
                for (new 
0MAX_DUELSi++)
                {
                    if (
duel[i][duelstate] >= 3)
                    {
                        
format(querysizeof(query), "%s\n%d - %s VS %s"queryiName[duel[i][players][0]],  Name[duel[i][players][1]]);
                        
count++;
                    }
                }
                if (
count == 0format(querysizeof(query), "There are no duels running.");
                
ShowPlayerDialog(playeridDIALOG_DUEL_WATCHDIALOG_STYLE_LIST"Watch a duel"query"OK""BACK");
            }
            case 
2//check invites
            
{
                
ShowPlayerDialog(playeridDIALOG_DUEL_INVITESDIALOG_STYLE_LIST"Duel Invites"Duel_MyInvitesString(playerid), "CONFIRM""BACK");
            }
            case 
3//cancel invite
            
{
                if (
duelslotid[playerid] == -1) return SendClientMessage(playeridERRORCOLOR"You haven't sent anyone a duel invite.");
                if (
duel[duelslotid[playerid]][duelstate] > 2) return SendClientMessage(playeridERRORCOLOR"You haven't sent anyone a duel invite.");
                
format(querysizeof(query), "%s has canceled their duel invite to you."playerData[playerid][PName]);
                
SendClientMessage(duel[duelslotid[playerid]][players][1], 0xFFFF00FFquery);
                
format(querysizeof(query), "You have canceled your duel invite to %s."Name[duel[duelslotid[playerid]][players][1]]);
                
SendClientMessage(playerid0xFFFF00FFquery);
                
duel[duelslotid[playerid]][duelstate] = 0;
                
duel[duelslotid[playerid]][players][0] = INVALID_PLAYER_ID;
                
duel[duelslotid[playerid]][players][1] = INVALID_PLAYER_ID;
                
duel[duelslotid[playerid]][arena] = 0;
                
duel[duelslotid[playerid]][rounds] = 0;
                for (new 
013i++) duel[duelslotid[playerid]][weapons][i] = 0;
                
duel[duelslotid[playerid]][dkills][0] = 0;
                
duel[duelslotid[playerid]][dkills][1] = 0;
                
duelslotid[playerid] = -1;
            }
        }
    } 
PHP код:
[00:19:31] [debugRun time error 4"Array index out of bounds"
[00:19:31] [debug]  Accessing element at index 65535 past array upper bound 999
[00:19:31] [debugAMX backtrace:
[
00:19:31] [debug#0 000dde5c in public S@@_OnDialogResponse (playerid=18, dialogid=63, response=1, listitem=3, inputtext[]=@01fdb55c "hi4") at ffs.pwn:2664
[00:19:31] [debug#1 000702f0 in public cmd_duel (playerid=18, params[]=@020e7fac "cancel") at C:\Users\iLearner\Desktop\ffss\pawno\include\FFS/FFS_Commands.inc:1541
[00:19:31] [debug#2 native CallLocalFunction () from samp03svr
[00:19:31] [debug#3 0002bdec in public OnPlayerCommandText (playerid=18, cmdtext[]=@020e7f78 "/duel cancel") at C:\Users\iLearner\Desktop\ffss\pawno\include\izcmd.inc:106 
Some stupid guy passing hi4? ...
Reply
#6

This is such a common error that if you are coming to forum to ask for help this tells me you are too lazy to figure it out or you didn't write the script and don't know what you are doing.
Reply
#7

In listitem 3, you check if duelslotid[playerid] is -1 to return an error but its (default) value is INVALID_PLAYER_ID (65535).
Reply
#8

Quote:
Originally Posted by Pottus
Посмотреть сообщение
This is such a common error that if you are coming to forum to ask for help this tells me you are too lazy to figure it out or you didn't write the script and don't know what you are doing.
Nah not mine, i script for a friend.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)