SA-MP Forums Archive
help with OnPlayerDeath - 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: help with OnPlayerDeath (/showthread.php?tid=363720)



help with OnPlayerDeath - CoDeZ - 28.07.2012

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?


Re: help with OnPlayerDeath - BlackWolf120 - 28.07.2012

Show us the definitions of the Arrays/Vars.


Kind regards, wolf.


Re: help with OnPlayerDeath - CoDeZ - 28.07.2012

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



Re: help with OnPlayerDeath - Rudy_ - 28.07.2012

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 :/


Re : help with OnPlayerDeath - lelemaster - 28.07.2012

The first one.


Re: help with OnPlayerDeath - CoDeZ - 28.07.2012

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


Re: help with OnPlayerDeath - [KHK]Khalid - 28.07.2012

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
    }
}



Re: help with OnPlayerDeath - CoDeZ - 28.07.2012

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


Re: help with OnPlayerDeath - SuperViper - 28.07.2012

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