Run time error 4 " array index out of bounds "
#1

Been getting this problem for a little while now.

This is showing up after i made the code for OnPlayerDeath.

Код:
[22:48:50] [debug] Run time error 4: "Array index out of bounds"
[22:48:50] [debug]  Attempted to read/write array element at index 65535 in array of size 1000
[22:48:50] [debug] AMX backtrace:
[22:48:50] [debug] #0 0000a98c in public OnPlayerDeath (0, 65535, 255) from apoc-rp.amx
Код:
forward OnPlayerDeath(playerid, killerid, reason);
public OnPlayerDeath(playerid, killerid, reason)
{    
    if(IsPlayerConnected(playerid))
    {
        ZombieTeam(playerid);
        if(killerid != INVALID_PLAYER_ID)
        {
            pInfo[playerid][Kills]++;
        }
    }
    if(pInfo[killerid][Human] == 1)
    {
        if(pInfo[playerid][Human] == 1)
        {
            new str[100];
            format(str, sizeof(str),"[LOG]: %s has been killed by %s",GetName(playerid), GetName(killerid));
            ResetPlayerWeapons(playerid);
            SendAdminsMessage(1, -1, str);
            ZombieTeam(playerid);
            printf("[LOG]: %s has been killed by %s",GetName(playerid), GetName(killerid));
        }
        else if(pInfo[playerid][Zombie] == 1)
        {
            pInfo[killerid][Tokens] += 250;
        }    
    }
    return 1;    
}
Any suggestion to why this, a fix if possible and a brief summary on how to avoid the problem in future.
Reply
#2

Check if the killer ID isn't an INVALID_PLAYER_ID at this part:
Код:
if(pInfo[killerid][Human] == 1)
Also why do you add "forward OnPlayerDeath" ?
Reply
#3

Quote:
Originally Posted by Variable™
Посмотреть сообщение
Check if the killer ID isn't an INVALID_PLAYER_ID at this part:
Код:
if(pInfo[killerid][Human] == 1)
Also why do you add "forward OnPlayerDeath" ?
Done and still the same problem.

And didn't even realize the forward declaration for OnPlayerDeath i was just going threw other public's so to speak and was adding forwards for each one, i've removed it now.
Reply
#4

Try this:

Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    if(IsPlayerConnected(killerid) && killerid != INVALID_PLAYER_ID)
    {
        ZombieTeam(playerid);
        pInfo[killerid][Kills]++;
        
        if(pInfo[killerid][Human] == 1)
        {
            if(pInfo[playerid][Human] == 1)
            {
                new str[100];
                format(str, sizeof(str),"[LOG]: %s has been killed by %s",GetName(playerid), GetName(killerid));
                ResetPlayerWeapons(playerid);
                SendAdminsMessage(1, -1, str);
                ZombieTeam(playerid);
                printf("[LOG]: %s has been killed by %s",GetName(playerid), GetName(killerid));
            }
            else if(pInfo[playerid][Zombie] == 1)
            {
                pInfo[killerid][Tokens] += 250;
            }
        }
    }
    return 1;
}
P.S:

- You were adding the kills to the one died not the killer.
- You don't need to check if the one died is connected, should do for the killer only.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)