help with OnPlayerDeath
#1

Hello guys , this is my onplayerdeath callback
pawn Код:
public OnPlayerDeath(playerid,killerid,reason)
{
    if(Account[playerid][gTeam]==Terrorists)
    {
        TerrorsCounter--;
    }
    else if(Account[playerid][gTeam]==Cops)
    {
        CopsCounter--;
    }
    Armour[playerid]=0;
    SendDeathMessage(killerid, playerid, reason);
    new kScore=GetPlayerScore(killerid);
    /*if(NormalKill[killerid]==1)
    {
    }*/

    if(NormalKill[playerid]==1)
    {
        GameTextForPlayer(playerid,"~g~You are DEAD.",5000,3);
    }
    return 1;
}
The commented part up there gives me this error :
Код:
[16:53:47] [debug] Run time error 4: "Array index out of bounds"
[16:53:47] [debug]  Accessing element at index 65535 past array upper bound 499
[16:53:47] [debug] AMX backtrace:
[16:53:47] [debug] #0 00014ef0 in public OnPlayerDeath () from teehee.amx
when i remove it the error is gone , any help please?
Reply
#2

Show us the definitions of the Arrays/Vars.


Kind regards, wolf.
Reply
#3

Well for this part i have this one
pawn Код:
new NormalKill[MAX_PLAYERS];
Reply
#4

Not sure though
pawn Код:
if(NormalKill[playerid] == 1)
pawn Код:
if(NormalKill[playerid] = 1)
pawn Код:
if(NormalKill(playerid) == 1)
I can't think properly (haen't slept from 23/4 hours :/
Reply
#5

The first one.
Reply
#6

Thanks for your help but , i already have this part in my code and its for its own uses
Reply
#7

Well, I do believe that you got these debug errors when you tested this code with only yourself (No killerid. You just died without being killed by anyone) so your check was like this:

pawn Код:
// the killerid is not connected. playerid died without being killed by anyone
if(NormalKill[INVALID_PLAYER_ID] == 1) // INVALID_PLAYER_ID = 0xFFFF which are the same as 65535
// and 65535 is obviously out of bounds since your MAX_PLAYERS is defined as 500 (or less)
{

}
Thus the debug errors came up.
Код:
[16:53:47] [debug] Run time error 4: "Array index out of bounds"
[16:53:47] [debug]  Accessing element at index 65535 past array upper bound 499
Here's a tip: When you deal with OnPlayerDeath, remember to always check whether killerid is connected or not before doing ANYTHING to it because a player can die without being killed and OnPlayerDeath gets called.

Works:
pawn Код:
if(IsPlayerConnected(killerid))
{
    if(NormalKill[killerid] == 1)
    {
        // Code
    }
}
Reply
#8

OMG dude , you're a legend
yes i tested this code using a kill command
Thank you mate !
Reply
#9

An even more efficient method of fixing this problem rather than using IsPlayerConnected is checking if killerid is equal to INVALID_PLAYER_ID.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)