[debug] Run time error
#1

I have these issues :

Server Log :
pawn Код:
[19:29:32] [debug] Run time error 4: "Array index out of bounds"
[19:29:32] [debug]  Accessing element at index 1000 past array upper bound 999
[19:29:32] [debug] AMX backtrace:
[19:29:32] [debug] #0 0003aed4 in public rMessage2 () from GFHusi.amx
[19:29:32] SavePlayerData: All player data saved(5 minutes).
[19:29:33] [debug] Run time error 4: "Array index out of bounds"
[19:29:33] [debug]  Accessing element at index 1000 past array upper bound 999
[19:29:33] [debug] AMX backtrace:
[19:29:33] [debug] #0 0003ac28 in public rMessage () from GFHusi.amx
Script:
pawn Код:
public rMessage()
{
    new rNumber, Check = 0;
    do{
        for(new i=0; i<sizeof(rCheckList); i++)
            if(rCheckList[i] != 0)
                Check++;
        if(Check == sizeof(rCheckList))
            for(new i=0; i<sizeof(rCheckList); i++)
                rCheckList[i] = 0;
        rNumber = random(sizeof(RandomMSG));
    }while(rCheckList[rNumber]);
    for(new x = 0; x<= MAX_PLAYERS; x++)
    {
        if(PlayerInfo[x][pLanguage] == 2)
        {
            SendClientMessage(x, COLOR_GOLD, RandomMSG[rNumber]);
            rCheckList[rNumber] = 1;
        }
    }
}
public rMessage2()
{
    new rNumber, Check = 0;
    do{
        for(new i=0; i<sizeof(rCheckList2); i++)
            if(rCheckList2[i] != 0)
                Check++;
        if(Check == sizeof(rCheckList2))
            for(new i=0; i<sizeof(rCheckList2); i++)
                rCheckList2[i] = 0;
        rNumber = random(sizeof(RandomMSGENG));
    }while(rCheckList2[rNumber]);
    for(new x = 0; x<= MAX_PLAYERS; x++)
    {
        if(PlayerInfo[x][pLanguage] == 1)
        {
            SendClientMessage(x, COLOR_GOLD, RandomMSGENG[rNumber]);
            rCheckList2[rNumber] = 1;
        }
    }
}
And also
pawn Код:
[19:35:45] [debug] Run time error 4: "Array index out of bounds"
[19:35:45] [debug]  Accessing element at index 65535 past array upper bound 999
[19:35:45] [debug] AMX backtrace:
[19:35:45] [debug] #0 00071d1c in public OnPlayerDeath (0, 65535, 54) from GFHusi.amx
[19:35:45] [debug] #1 0006fab4 in public OnPlayerTakeDamage (0, 65535, 1084122727, 54, 3) from GFHusi.amx
Script :
pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart)
{
    if(flymode[playerid] > 0) { return 1; }
    if(AdminDuty[playerid] > 0) { return 1; }
    if(issuerid != INVALID_PLAYER_ID)
    {
        if(amount < 0)
        {
            new string[256],sendername[25];
            GetPlayerName(issuerid,sendername,sizeof(sendername));
            format(string, sizeof(string), "(N) %s (%d, level %d) can use global kill, damage: %.2f.",sendername,issuerid,PlayerInfo[issuerid][pLevel],amount);
            ABroadCast(COLOR_RED,string,1);
            return 1;
        }
        if(weaponid == 54 && GetPlayerState(issuerid) != PLAYER_STATE_DRIVER)
        {
            if(playerdeath[issuerid] == 0)
            {
                new Float:HP, Float:AP, Float:remainHP;
                GetPlayerHealthEx(issuerid,HP);
                GetPlayerArmourEx(issuerid,AP);
                if ( AP >= amount )
                {
                    SetPlayerArmourEx( issuerid, AP - amount );
                    SetPlayerHealthEx( issuerid, HP );
                }
                else if ( AP <= 0 )
                {
                    remainHP = HP - amount;
                    SetPlayerHealthEx( issuerid, remainHP );
                    if ( remainHP <= 0 && playerdeath[issuerid] == 0 )
                    {
                        OnPlayerDeath( playerid, issuerid, weaponid );
                        playerdeath[playerid] = 1;
                    }
                }
                else
                {
                    remainHP = HP + ( AP - amount );
                    SetPlayerArmourEx( issuerid, 0.0 );
                    SetPlayerHealthEx( issuerid, remainHP );
                    if ( remainHP <= 0 && playerdeath[issuerid] == 0 )
                    {
                        OnPlayerDeath( playerid, issuerid, weaponid );
                        playerdeath[issuerid] = 1;
                    }
                }
            }
        }
    }
    if(weaponid == 49 || weaponid == 50 || weaponid == 51 || weaponid == 52 || weaponid == 53 || weaponid == 54 || GetPlayerState(issuerid) == PLAYER_STATE_DRIVER)
    {
        if(playerdeath[playerid] == 0)
        {
            new Float:HP, Float:AP, Float:remainHP;
            GetPlayerHealthEx(playerid,HP);
            GetPlayerArmourEx(playerid,AP);
            if ( AP >= amount )
            {
                SetPlayerArmourEx( playerid, AP - amount );
                SetPlayerHealthEx( playerid, HP );
            }
            else if ( AP <= 0 )
            {
                remainHP = HP - amount;
                SetPlayerHealthEx( playerid, remainHP );
                if ( remainHP <= 0 && playerdeath[playerid] == 0 )
                {
                    OnPlayerDeath( playerid, issuerid, weaponid );
                    playerdeath[playerid] = 1;
                }
            }
            else
            {
                remainHP = HP + ( AP - amount );
                SetPlayerArmourEx( playerid, 0.0 );
                SetPlayerHealthEx( playerid, remainHP );
                if ( remainHP <= 0 && playerdeath[playerid] == 0 )
                {
                    OnPlayerDeath( playerid, issuerid, weaponid );
                    playerdeath[playerid] = 1;
                }
            }
        }
    }
    return 1;
}
Reply
#2

pawn Код:
for(new x = 0; x<= MAX_PLAYERS; x++)
to

pawn Код:
for(new x = 0; x < MAX_PLAYERS; x++)

2.

pawn Код:
if(playerdeath[playerid] == 0)
        {
            new Float:HP, Float:AP, Float:remainHP;
            GetPlayerHealthEx(playerid,HP);
            GetPlayerArmourEx(playerid,AP);
            if ( AP >= amount )
            {
                SetPlayerArmourEx( playerid, AP - amount );
                SetPlayerHealthEx( playerid, HP );
            }
            else if ( AP <= 0 )
            {
                remainHP = HP - amount;
                SetPlayerHealthEx( playerid, remainHP );
                if ( remainHP <= 0 && playerdeath[playerid] == 0 )
                {
                    OnPlayerDeath( playerid, issuerid, weaponid );
                    playerdeath[playerid] = 1;
                }
            }
            else
            {
                remainHP = HP + ( AP - amount );
                SetPlayerArmourEx( playerid, 0.0 );
                SetPlayerHealthEx( playerid, remainHP );
                if ( remainHP <= 0 && playerdeath[playerid] == 0 )
                {
                    OnPlayerDeath( playerid, issuerid, weaponid );
                    playerdeath[playerid] = 1;
                }
            }
        }
here issuerid is INVALID_PLAYER_ID you need add
pawn Код:
if(issuerid != INVALID_PLAYER_ID)
before calling
pawn Код:
OnPlayerDeath( playerid, issuerid, weaponid );
Reply
#3

Replace:
pawn Код:
for(new x = 0; x<= MAX_PLAYERS; x++)
with:
pawn Код:
for(new x = 0; x< MAX_PLAYERS; x++)
Array indexes start from 0 to SIZE-1. So MAX_PLAYERS is 1000 and the valid indexes 0-999.

The last is in OnPlayerDeath callback.
Reply
#4

Rep Both ,Thanks
Reply
#5

I have one last question. Do i have to check all the public OnPlayerDeath for this error?

pawn Код:
[15:13:15] [debug] Run time error 4: "Array index out of bounds"
[15:13:15] [debug]  Accessing element at index 65535 past array upper bound 999
[15:13:15] [debug] AMX backtrace:
[15:13:15] [debug] #0 000855f8 in public OnPlayerDeath (0, 65535, 54) from GFHusi.amx
?
Reply
#6

Any array that uses killerid as index must be inside a check (killerid != INVALID_PLAYER_ID) to avoid it.
Reply
#7

Thanks, it worked
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)